Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1i1vVb-0004Qz-Gx for pgsql-general@arkaria.postgresql.org; Sun, 25 Aug 2019 16:36:52 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1i1vVY-0001dj-Np for pgsql-general@arkaria.postgresql.org; Sun, 25 Aug 2019 16:36:48 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1i1vVY-0001Z4-8e for pgsql-general@lists.postgresql.org; Sun, 25 Aug 2019 16:36:48 +0000 Received: from stz-bg.com ([46.40.123.212] helo=mail.stzbg.com) by magus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1i1vVR-0001K0-3V for pgsql-general@lists.postgresql.org; Sun, 25 Aug 2019 16:36:47 +0000 Received: from www.stz-bg.com (stz-bg.com [IPv6:2a02:6800:0:99::2]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: condor@stz-bg.com) by mail.stzbg.com (Postfix) with ESMTPSA id 25FAA2E06B1; Sun, 25 Aug 2019 19:36:39 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=stz-bg.com; s=mail; t=1566750999; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=QMkZIMONbEmEzKNdwFWhrSTvP2nvO19+MOFmlCG5hhU=; b=K6Pnhw0nZHwhkBAHy1VuFzODcrVuEBGi9MY1eFEZYJ4jYPMxGNKaQH443Z2CLsfzM8Hs3S 4u9hlg8cWi9okH8L+1VXpFPqincQP5NAQ28myXFrgqSXokG63r/pBMUPpojfGLtN+0OIAp kfJFEvf5cJd83qgNfUfUbagnTLdyGKI= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable Date: Sun, 25 Aug 2019 19:36:38 +0300 From: Condor To: Adrian Klaver Cc: Howard Wells , pgsql-general@lists.postgresql.org Subject: Re: Postgres SQLSTATE[08006] [7] timeout expired In-Reply-To: <8262b160-f274-a80b-68ec-a26058a961a2@aklaver.com> References: <8262b160-f274-a80b-68ec-a26058a961a2@aklaver.com> Message-ID: <46bc9b278ba7c77aa4a59084102bc1e0@stz-bg.com> X-Sender: condor@stz-bg.com User-Agent: Roundcube Webmail/1.3.9 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 25-08-2019 02:54, Adrian Klaver wrote: > On 8/24/19 3:42 PM, Howard Wells wrote: >> I have three servers behind a load balancer and a fourth server solely= =20 >> for Postgres 10 database that is not behind the load balancer.=C2=A0 All= =20 >> four are behind the same firewall, with port 5432 open. >>=20 >> I have a simple browser-based html form to submit email addresses,=20 >> usernames and passwords; the form submits through a jQuery program=20 >> that calls a php program. >>=20 >> I can navigate the browser to the IP address of the server that hosts=20 >> the Postgres database and submit records to the database with no=20 >> problems.=C2=A0 When I navigate to the site's URL (which goes through th= e=20 >> load balancer), I always get "SQLSTATE[08006] [7] timeout expired"=20 >> after a short delay -- in other words, no connection. >>=20 >> The php program is very simple: >>=20 >> > echo 'Hello ' . htmlspecialchars($_POST["firstname"]) . '!' ; >> echo PHP_EOL; >>=20 >> $dsn =3D vsprintf('pgsql:host=3D%s;port=3D%s;dbname=3D%s;user=3D%s;passw= ord=3D%s',=20 >> [ >> =C2=A0=C2=A0=C2=A0 'host' =3D> 'xxx.xx.xx.xx', >> =C2=A0=C2=A0=C2=A0 'port' =3D> '5432', >> =C2=A0=C2=A0=C2=A0 'dbname' =3D> '[DBNAME]', >> =C2=A0=C2=A0=C2=A0 'user' =3D> '[USERNAME]', >> =C2=A0=C2=A0=C2=A0 'password' =3D> '[PASSWORD]', >> ]); >>=20 >> echo 'HTTP Referer ' . $_SERVER['HTTP_REFERER']; >> echo PHP_EOL; >>=20 >> echo 'IP Address ' . $_SERVER["REMOTE_ADDR"]; >> echo PHP_EOL; >>=20 >> try{ >> // create a PostgreSQL database connection >>=20 >> =C2=A0 echo "I'm here now"; >> =C2=A0 echo PHP_EOL; >>=20 >> //ini_set("default_socket_timeout", 300); >> $pdo =3D new PDO($dsn); >> $pdo->setAttribute(PDO::ATTR_TIMEOUT, 300); >>=20 >> // display a message if connected to the PostgreSQL successfully >> if($pdo){ >> echo "Connected to the database successfully!"; >> echo PHP_EOL; >> } >> }catch (PDOException $e){ >> // report error message >> echo $e->getMessage(); >> exit(); >> } >>=20 >> $pdo =3D null; >>=20 >> ?> >>=20 >> The echo messages are simply debugging progress messages for the=20 >> browser's dev console. >>=20 >> The pg_hba.conf has these lines enabled: >>=20 >> pg_hba.conf: >> host=C2=A0=C2=A0=C2=A0 all=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 [username]=C2=A0=C2=A0 0.0.0.0/0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 trust >> host=C2=A0=C2=A0=C2=A0 all=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 all=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 0.0.0.0/0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 md5 >> host=C2=A0=C2=A0=C2=A0 all=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 all=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ::/0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= md5 >> host=C2=A0=C2=A0=C2=A0 all=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 all=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 all=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0 md5 >>=20 >> The $_SERVER["REMOTE_ADDR"]; line shown in my PHP program above always= =20 >> comes back with the address of the load balancer. >>=20 >> I'm new to Postgres, so any help with this connection problem will be=20 >> very appreciated.=C2=A0 Thanks a lot. >=20 > In addition to what Rob suggested, what do you see or not in the > Postgres logs when you try the connections(both direct to db and to > load balancer). You can use strace or tcpdump to see what's happened. First check to see=20 did the balncer is up and port is opened. Next if the balancer is bind=20 on port 5432 and pgsql server is started on same ip without port to be=20 changed this can't be happened unless the pgsql server is started on=20 socket without inet connection. If the balancer is up and they are not=20 in the same server then it's seems the problem is between balancer and=20 sql server. The balancer is not connected to pg server with some reason=20 /firewall, permissions, users and so on, you need to check them -=20 balancer logs, firewall rules /. Regards, HS