Received: from makus.postgresql.org (makus.postgresql.org [98.129.198.125]) by mail.postgresql.org (Postfix) with ESMTP id E028D1DA4C1E for ; Tue, 17 Jan 2012 11:09:56 -0400 (AST) Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1RnAfc-0005PB-Ak for pgsql-admin@postgresql.org; Tue, 17 Jan 2012 15:09:56 +0000 Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id q0HF9g9W015698; Tue, 17 Jan 2012 10:09:42 -0500 (EST) To: =?UTF-8?Q?Mindaugas_=C5=BDak=C5=A1auskas?= cc: pgsql-admin@postgresql.org Subject: Re: Establishing remote connections is slow In-reply-to: References: Comments: In-reply-to =?UTF-8?Q?Mindaugas_=C5=BDak=C5=A1auskas?= message dated "Tue, 17 Jan 2012 12:44:26 +0000" Date: Tue, 17 Jan 2012 10:09:42 -0500 Message-ID: <15697.1326812982@sss.pgh.pa.us> From: Tom Lane X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201201/61 X-Sequence-Number: 38973 =?UTF-8?Q?Mindaugas_=C5=BDak=C5=A1auskas?= writes: > I have a very weird problem related to establishing remote connections > to PostgreSQL server and hopefully someone can give me some hints how > can I debug this. > The essence is that establishing remote connection takes anywhere from > 10 to 30 seconds. Once connected, the queries are fast - it's just > establishing new connection that takes ages. Perhaps the problem is related to authentication - what auth mode are you using, and can you experiment with some other ones? What I'd do to start debugging this is to get out a packet sniffer (wireshark or some such) and just observe the timings of packets sent and received by Postgres. This would at least give you a hint which step is the bottleneck. > This problem is not > applicable to establishing local connections: running psql command > from the local machine takes no time to connect, same applies if a > client connects to the PostgreSQL via ssh tunnel. What about "psql -h localhost", ie physically local connection but via TCP not unix socket? regards, tom lane