From gray.chenhui@gmail.com Sun Aug 14 17:32:58 2005 X-Original-To: pgsql-php-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id A9AA252BC1 for ; Sun, 14 Aug 2005 14:32:58 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 00369-07 for ; Sun, 14 Aug 2005 17:32:57 +0000 (GMT) Received: from wproxy.gmail.com (wproxy.gmail.com [64.233.184.196]) by svr1.postgresql.org (Postfix) with ESMTP id E9D4852F7D for ; Sun, 14 Aug 2005 14:32:55 -0300 (ADT) Received: by wproxy.gmail.com with SMTP id i22so861435wra for ; Sun, 14 Aug 2005 10:32:56 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:mime-version:content-type:content-transfer-encoding:content-disposition; b=qolZsFovcXtGFQeCWi7Af/E75txL4u/4K5V3XAdphAUYWO26I151SOU6YmHrxzPk7yjHPxe4H+ewD5H2Qf99DnaHmZCKfVYa2ANxw9SXmmY55BzpwlB/KNwV78KduSVz07QLISFOgszRZiqJpOG03wfghMyM2MLKSsGqBFWjdhY= Received: by 10.54.69.1 with SMTP id r1mr3156317wra; Sun, 14 Aug 2005 10:32:56 -0700 (PDT) Received: by 10.54.98.9 with HTTP; Sun, 14 Aug 2005 10:32:56 -0700 (PDT) Message-ID: <923c3c1405081410326a1c2880@mail.gmail.com> Date: Sun, 14 Aug 2005 12:32:56 -0500 From: Hui Chen To: pgsql-php@postgresql.org Subject: Problem about connecting PostgreSQL through TCP/IP Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.024 tagged_above=0 required=5 tests=[RCVD_BY_IP=0.024] X-Spam-Level: X-Archive-Number: 200508/1 X-Sequence-Number: 3213 Hello, everyone, Can anyone help me? I am quite frustrating now. I have been trying to connect PostgreSQL server through TCP/IP connection using PHP. I was not successful. Could please read the following and give me some hints. Thanks a million. OS: Fedora Core 4 ("uname -s -r" yields "Linux 2.6.12-1.1398_FC4smp") PostgreSQL: version 8.0.3 PHP: version 5.0.4 In postgresql.conf, these three lines were inserted,=20 listen_addresses =3D '*' =20 port =3D 5432 max_connections =3D 100 The following lines were inserted to pg_hba.conf: local all all password host all all 127.0.0.1/32 password host all all 192.168.0.0/1 password restart posgresql by=20 /sbin/service postgresql restart The server was restarted OK. The PHP script used to connect database is as follows, "; print $fetch[0]; print ""; pg_close($conn); // Close this connection ?>=20 Assume this PHP script is named as "connectdb.php", then on commandline, when I run the following, php connectedb.php I see correct results, e.g.,=20 foo=20 On commandline again, I used the following to connect database, psql -d foodb -h localhost -p 5432 -U foo Password: ************ Welcome to psql 8.0.3, the PostgreSQL interactive terminal. Type: \copyright for distribution terms \h for help with SQL commands \? for help with psql commands \g or terminate with semicolon to execute query \q to quit foodb=3D>=20 It is OK. Then I disabled "iptables" temporarily for testing purpose by /sbin/service iptables stop Flushing firewall rules: [ OK ] Setting chains to policy ACCEPT: filter [ OK ] Unloading iptables modules: [ OK ] On localhost, I tried this command, telnet localhost 5432 after hit "enters", telnet exited. I checked postgresql_%S.log and see "LOG: invalid length of startup packet" which means postgresql server indeed saw the telnet connection.=20 I tried this on any of my other machines in the LAN, I observed the same th= ing.=20 In summary, it seemed the postgresql allowed TCP/IP connection, and worked well. However, when I ran the PHP script through web browser, I did not get connection. Instead, in Apache web server's error_log, I see [client 192.168.1.10] PHP Warning: pg_connect() [function.pg-connect]: Unable to connect to PostgreSQL server: could not connect to server: Permission denied\n\tIs the server running on host "localhost" and accepting\n\tTCP/IP connections on port 5432? in /foo/connectdb.php on line 2 Interestingly, when I checked the log file for postgresql again, it did not have anything for this connection failure. It seemed the connection did not send to the database server at all. However, 1) I disabled firewall 2) I can telnet the ports 3) I can run the script from commandline What could go wrong? Thanks a lot for your reading this lengthy email. Waiting for your help! Gray From matt@jobsforge.com Mon Aug 15 14:30:16 2005 X-Original-To: pgsql-php-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 759A852DC4 for ; Mon, 15 Aug 2005 11:30:16 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 15561-09 for ; Mon, 15 Aug 2005 14:30:14 +0000 (GMT) Received: from mout.perfora.net (mout.perfora.net [217.160.230.40]) by svr1.postgresql.org (Postfix) with ESMTP id BE38B52C2B for ; Mon, 15 Aug 2005 11:30:12 -0300 (ADT) Received: from ool-45782123.dyn.optonline.net [69.120.33.35] (helo=[192.168.2.18]) by mrelay.perfora.net with ESMTP (Nemesis), id 0MKoyl-1E4fyf18Y4-0007ex; Mon, 15 Aug 2005 10:30:13 -0400 In-Reply-To: <923c3c1405081410326a1c2880@mail.gmail.com> References: <923c3c1405081410326a1c2880@mail.gmail.com> Mime-Version: 1.0 (Apple Message framework v622) Content-Type: text/plain; charset=US-ASCII; format=flowed Message-Id: Content-Transfer-Encoding: 7bit Cc: pgsql-php@postgresql.org From: Matthew Terenzio Subject: Re: Problem about connecting PostgreSQL through TCP/IP Date: Mon, 15 Aug 2005 10:30:12 -0400 To: Hui Chen X-Mailer: Apple Mail (2.622) X-Provags-ID: perfora.net abuse@perfora.net login:55dcc513cc7db400396c2523adeeb8ca X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.153 required=5 tests=[AWL=0.153] X-Spam-Level: X-Archive-Number: 200508/24 X-Sequence-Number: 3236 > > restart posgresql by > /sbin/service postgresql restart > The server was restarted OK. > I usually use pg_ctl to start. With it and other methods of starting postgres you have to include the -i flag to get it to listen over TCP/IP perhaps your method of restarting needs this flag as well? > The PHP script used to connect database is as follows, > $conn = pg_connect("host=localhost port=5432 dbname=foodb user=foo > password=foo") or die ("Can not connect to postgres"); > $result=pg_exec("SELECT * FROM footbl"); > $fetch = pg_fetch_row($result); > print ""; > print $fetch[0]; > print ""; > > pg_close($conn); // Close this connection > ?> > > Assume this PHP script is named as "connectdb.php", then on > commandline, when I run the following, > php connectedb.php > I see correct results, e.g., > foo > > On commandline again, I used the following to connect database, > psql -d foodb -h localhost -p 5432 -U foo > Password: ************ > Welcome to psql 8.0.3, the PostgreSQL interactive terminal. > > Type: \copyright for distribution terms > \h for help with SQL commands > \? for help with psql commands > \g or terminate with semicolon to execute query > \q to quit > > foodb=> > > It is OK. Then I disabled "iptables" temporarily for testing purpose by > /sbin/service iptables stop > Flushing firewall rules: [ OK ] > Setting chains to policy ACCEPT: filter [ OK ] > Unloading iptables modules: [ OK ] > > On localhost, I tried this command, > telnet localhost 5432 > after hit "enters", telnet exited. I checked postgresql_%S.log and see > "LOG: invalid length of startup packet" > which means postgresql server indeed saw the telnet connection. > > I tried this on any of my other machines in the LAN, I observed the > same thing. > > In summary, it seemed the postgresql allowed TCP/IP connection, and > worked well. However, when I ran the PHP script through web browser, I > did not get connection. Instead, in Apache web server's error_log, I > see > [client 192.168.1.10] PHP Warning: pg_connect() [ href='function.pg-connect'>function.pg-connect]: Unable to connect > to PostgreSQL server: could not connect to server: Permission > denied\n\tIs the server running on host "localhost" and > accepting\n\tTCP/IP connections on port 5432? in /foo/connectdb.php on > line 2 > > Interestingly, when I checked the log file for postgresql again, it > did not have anything for this connection failure. It seemed the > connection did not send to the database server at all. However, > 1) I disabled firewall > 2) I can telnet the ports > 3) I can run the script from commandline > > What could go wrong? > > Thanks a lot for your reading this lengthy email. Waiting for your > help! > > Gray > > ---------------------------(end of > broadcast)--------------------------- > TIP 4: Have you searched our list archives? > > http://archives.postgresql.org > From operationsengineer1@yahoo.com Tue Aug 16 02:19:02 2005 X-Original-To: pgsql-php-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id E04C452942 for ; Mon, 15 Aug 2005 23:19:02 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 09158-09 for ; Tue, 16 Aug 2005 02:18:59 +0000 (GMT) Received: from web33304.mail.mud.yahoo.com (web33304.mail.mud.yahoo.com [68.142.206.119]) by svr1.postgresql.org (Postfix) with SMTP id 87521528FF for ; Mon, 15 Aug 2005 23:18:58 -0300 (ADT) Received: (qmail 73905 invoked by uid 60001); 16 Aug 2005 02:19:02 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=Message-ID:Received:Date:From:Subject:To:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=5JB4rCKAEEGd5WVP9YBgBGCIS9WcTg4FW5/sjBWfLGwZn57nJ02QMZ9LOp8G2NfmYT8d78AHMHjaZ98XmHm0i2rdy2mzYMEeAeWE7WakA40VP68oqfjBkrWRdo7I3yMXU7ART3JJyv3Vw6WmpWXtiEFt0Bpjvc66TtN7NWQb8yA= ; Message-ID: <20050816021902.73901.qmail@web33304.mail.mud.yahoo.com> Received: from [70.56.83.222] by web33304.mail.mud.yahoo.com via HTTP; Mon, 15 Aug 2005 19:19:02 PDT Date: Mon, 15 Aug 2005 19:19:02 -0700 (PDT) From: Subject: Re: Problem about connecting PostgreSQL through TCP/IP To: Hui Chen , pgsql-php@postgresql.org In-Reply-To: <923c3c1405081410326a1c2880@mail.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.552 required=5 tests=[DNS_FROM_RFC_ABUSE=0.374, NO_REAL_NAME=0.178] X-Spam-Level: X-Archive-Number: 200508/2 X-Sequence-Number: 3214 did you enable the "i" flag when you started the postmaster? if you didn't do that, tcp/ip will not connect! http://www.postgresql.org/docs/7.4/interactive/app-postmaster.html good luck. --- Hui Chen wrote: > Hello, everyone, > > Can anyone help me? I am quite frustrating now. I > have been trying to > connect PostgreSQL server through TCP/IP connection > using PHP. I was > not successful. Could please read the following and > give me some > hints. Thanks a million. > > OS: Fedora Core 4 ("uname -s -r" yields "Linux > 2.6.12-1.1398_FC4smp") > PostgreSQL: version 8.0.3 > PHP: version 5.0.4 > > In postgresql.conf, these three lines were inserted, > > listen_addresses = '*' > port = 5432 > max_connections = 100 > > The following lines were inserted to pg_hba.conf: > local all all > password > host all all 127.0.0.1/32 > password > host all all 192.168.0.0/1 > password > > restart posgresql by > /sbin/service postgresql restart > The server was restarted OK. > > The PHP script used to connect database is as > follows, > $conn = pg_connect("host=localhost port=5432 > dbname=foodb user=foo > password=foo") or die ("Can not connect to > postgres"); > $result=pg_exec("SELECT * FROM footbl"); > $fetch = pg_fetch_row($result); > print ""; > print $fetch[0]; > print ""; > > pg_close($conn); // Close this connection > ?> > > Assume this PHP script is named as "connectdb.php", > then on > commandline, when I run the following, > php connectedb.php > I see correct results, e.g., > foo > > On commandline again, I used the following to > connect database, > psql -d foodb -h localhost -p 5432 -U foo > Password: ************ > Welcome to psql 8.0.3, the PostgreSQL interactive > terminal. > > Type: \copyright for distribution terms > \h for help with SQL commands > \? for help with psql commands > \g or terminate with semicolon to execute > query > \q to quit > > foodb=> > > It is OK. Then I disabled "iptables" temporarily for > testing purpose by > /sbin/service iptables stop > Flushing firewall rules: > [ OK ] > Setting chains to policy ACCEPT: filter > [ OK ] > Unloading iptables modules: > [ OK ] > > On localhost, I tried this command, > telnet localhost 5432 > after hit "enters", telnet exited. I checked > postgresql_%S.log and see > "LOG: invalid length of startup packet" > which means postgresql server indeed saw the telnet > connection. > > I tried this on any of my other machines in the LAN, > I observed the same thing. > > In summary, it seemed the postgresql allowed TCP/IP > connection, and > worked well. However, when I ran the PHP script > through web browser, I > did not get connection. Instead, in Apache web > server's error_log, I > see > [client 192.168.1.10] PHP Warning: pg_connect() [ href='function.pg-connect'>function.pg-connect]: > Unable to connect > to PostgreSQL server: could not connect to server: > Permission > denied\n\tIs the server running on host > "localhost" and > accepting\n\tTCP/IP connections on port 5432? in > /foo/connectdb.php on > line 2 > > Interestingly, when I checked the log file for > postgresql again, it > did not have anything for this connection failure. > It seemed the > connection did not send to the database server at > all. However, > 1) I disabled firewall > 2) I can telnet the ports > 3) I can run the script from commandline > > What could go wrong? > > Thanks a lot for your reading this lengthy email. > Waiting for your help! > > Gray > > ---------------------------(end of > broadcast)--------------------------- > TIP 4: Have you searched our list archives? > > http://archives.postgresql.org > __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com From gray.chenhui@gmail.com Wed Aug 17 04:55:59 2005 X-Original-To: pgsql-php-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 65CFC5294C for ; Wed, 17 Aug 2005 01:55:59 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 29448-04 for ; Wed, 17 Aug 2005 04:55:54 +0000 (GMT) Received: from wproxy.gmail.com (wproxy.gmail.com [64.233.184.205]) by svr1.postgresql.org (Postfix) with ESMTP id 6AEAF52B76 for ; Wed, 17 Aug 2005 01:55:53 -0300 (ADT) Received: by wproxy.gmail.com with SMTP id i22so88832wra for ; Tue, 16 Aug 2005 21:55:51 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=P4OAzeNmReMsdxEJm9PQ0rtvUsmz8xIIxVPWxWbEEFr2Caq+xezJ+nyE3ApBpKASI1YzUuwJ6MV+cWs7V02fu6IbxP+VXv5bqoOkEDEopAhMibKQwkBSJIVFgbn5QPuMbBmea8Jk3RoCWEEjApvejLDw9fmE82BNC9Hb69rY/eI= Received: by 10.54.50.16 with SMTP id x16mr214259wrx; Tue, 16 Aug 2005 21:55:51 -0700 (PDT) Received: by 10.54.98.9 with HTTP; Tue, 16 Aug 2005 21:55:51 -0700 (PDT) Message-ID: <923c3c1405081621556f8a3c4d@mail.gmail.com> Date: Tue, 16 Aug 2005 23:55:51 -0500 From: Hui Chen To: Matthew Terenzio Subject: Re: Problem about connecting PostgreSQL through TCP/IP Cc: pgsql-php@postgresql.org In-Reply-To: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline References: <923c3c1405081410326a1c2880@mail.gmail.com> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.024 required=5 tests=[RCVD_BY_IP=0.024] X-Spam-Level: X-Archive-Number: 200508/11 X-Sequence-Number: 3223 Thanks, Matthew! I did notice that "-i" flag was used to enable the postgresql server to listen over TCP/IP. However, it seemed to me this option had become obsolete in postgresal 8.0. I did not find "-i" option from man page. Plus, the document here http://www.postgresql.org/docs/8.0/interactive/runtime-config.html states that I only need to insert "listen_addresses" option in the postgresql.conf file. Did I misunderstand anything? What do you think? thanks again! Gray On 8/15/05, Matthew Terenzio wrote: > > > > > > restart posgresql by > > /sbin/service postgresql restart > > The server was restarted OK. > I usually use pg_ctl to start. >=20 > With it and other methods of starting postgres you have to include the > -i flag to get it to listen over TCP/IP >=20 > perhaps your method of restarting needs this flag as well? >=20 > > > > The PHP script used to connect database is as follows, > > > $conn =3D pg_connect("host=3Dlocalhost port=3D5432 dbname=3Dfoodb use= r=3Dfoo > > password=3Dfoo") or die ("Can not connect to postgres"); > > $result=3Dpg_exec("SELECT * FROM footbl"); > > $fetch =3D pg_fetch_row($result); > > print ""; > > print $fetch[0]; > > print ""; > > > > pg_close($conn); // Close this connection > > ?> > > > > Assume this PHP script is named as "connectdb.php", then on > > commandline, when I run the following, > > php connectedb.php > > I see correct results, e.g., > > foo > > > > On commandline again, I used the following to connect database, > > psql -d foodb -h localhost -p 5432 -U foo > > Password: ************ > > Welcome to psql 8.0.3, the PostgreSQL interactive terminal. > > > > Type: \copyright for distribution terms > > \h for help with SQL commands > > \? for help with psql commands > > \g or terminate with semicolon to execute query > > \q to quit > > > > foodb=3D> > > > > It is OK. Then I disabled "iptables" temporarily for testing purpose by > > /sbin/service iptables stop > > Flushing firewall rules: [ OK ] > > Setting chains to policy ACCEPT: filter [ OK ] > > Unloading iptables modules: [ OK ] > > > > On localhost, I tried this command, > > telnet localhost 5432 > > after hit "enters", telnet exited. I checked postgresql_%S.log and see > > "LOG: invalid length of startup packet" > > which means postgresql server indeed saw the telnet connection. > > > > I tried this on any of my other machines in the LAN, I observed the > > same thing. > > > > In summary, it seemed the postgresql allowed TCP/IP connection, and > > worked well. However, when I ran the PHP script through web browser, I > > did not get connection. Instead, in Apache web server's error_log, I > > see > > [client 192.168.1.10] PHP Warning: pg_connect() [ > href=3D'function.pg-connect'>function.pg-connect]: Unable to connec= t > > to PostgreSQL server: could not connect to server: Permission > > denied\n\tIs the server running on host "localhost" and > > accepting\n\tTCP/IP connections on port 5432? in /foo/connectdb.php on > > line 2 > > > > Interestingly, when I checked the log file for postgresql again, it > > did not have anything for this connection failure. It seemed the > > connection did not send to the database server at all. However, > > 1) I disabled firewall > > 2) I can telnet the ports > > 3) I can run the script from commandline > > > > What could go wrong? > > > > Thanks a lot for your reading this lengthy email. Waiting for your > > help! > > > > Gray > > > > ---------------------------(end of > > broadcast)--------------------------- > > TIP 4: Have you searched our list archives? > > > > http://archives.postgresql.org > > >=20 >=20 > From gray.chenhui@gmail.com Wed Aug 17 05:03:42 2005 X-Original-To: pgsql-php-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id BF7AE52971 for ; Wed, 17 Aug 2005 02:03:42 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 31531-05 for ; Wed, 17 Aug 2005 05:03:40 +0000 (GMT) Received: from wproxy.gmail.com (wproxy.gmail.com [64.233.184.201]) by svr1.postgresql.org (Postfix) with ESMTP id 2CC2C52B54 for ; Wed, 17 Aug 2005 02:03:38 -0300 (ADT) Received: by wproxy.gmail.com with SMTP id i22so89642wra for ; Tue, 16 Aug 2005 22:03:38 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=LOPmLEQuGDV8Zm04y3dRYrjX7gCkvZvRLa57TQd794/BJE/1lxHdv9dY/DL+uB6zk42AnQuxvC0xH4YwSnL539gUHssIRV0e/9F+vh/EOHVwCnzZk7NH2rjhNDbfJC0AN3cDH7V8sT0lpZLJGbmvrv0e8igCNBqHKyBbpXl1NV8= Received: by 10.54.31.63 with SMTP id e63mr199698wre; Tue, 16 Aug 2005 22:03:38 -0700 (PDT) Received: by 10.54.98.9 with HTTP; Tue, 16 Aug 2005 22:03:38 -0700 (PDT) Message-ID: <923c3c14050816220347aaa1f9@mail.gmail.com> Date: Wed, 17 Aug 2005 00:03:38 -0500 From: Hui Chen To: "operationsengineer1@yahoo.com" Subject: Re: Problem about connecting PostgreSQL through TCP/IP Cc: pgsql-php@postgresql.org In-Reply-To: <20050816021902.73901.qmail@web33304.mail.mud.yahoo.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline References: <923c3c1405081410326a1c2880@mail.gmail.com> <20050816021902.73901.qmail@web33304.mail.mud.yahoo.com> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.259 required=5 tests=[AWL=-0.235, RCVD_BY_IP=0.024, TO_ADDRESS_EQ_REAL=0.47] X-Spam-Level: X-Archive-Number: 200508/12 X-Sequence-Number: 3224 Hello, Thanks a lot! I did noticed "-i" option. I am using 8.0 whose manual (http://www.postgresql.org/docs/8.0/interactive/app-postmaster.html) states that "-i" option is deprecated. The manual (http://www.postgresql.org/docs/8.0/interactive/runtime-config.html#RUNTIME= -CONFIG-CONNECTION) also says that I can enable "listen_addresses" option in the postgresql.conf to enable the server to listen over TCP/IP. What really puzzles me is that I could actually telnet server at 5432 ports and saw an corresponding entry in the log file; however, when I used PHP to connect the server, the log file did not have an entry for the failed connection attempt at all. Do you think what can go wrong? Thanks! Gray On 8/15/05, operationsengineer1@yahoo.com w= rote: > did you enable the "i" flag when you started the > postmaster? if you didn't do that, tcp/ip will not > connect! >=20 > http://www.postgresql.org/docs/7.4/interactive/app-postmaster.html >=20 > good luck. >=20 > --- Hui Chen wrote: >=20 > > Hello, everyone, > > > > Can anyone help me? I am quite frustrating now. I > > have been trying to > > connect PostgreSQL server through TCP/IP connection > > using PHP. I was > > not successful. Could please read the following and > > give me some > > hints. Thanks a million. > > > > OS: Fedora Core 4 ("uname -s -r" yields "Linux > > 2.6.12-1.1398_FC4smp") > > PostgreSQL: version 8.0.3 > > PHP: version 5.0.4 > > > > In postgresql.conf, these three lines were inserted, > > > > listen_addresses =3D '*' > > port =3D 5432 > > max_connections =3D 100 > > > > The following lines were inserted to pg_hba.conf: > > local all all > > password > > host all all 127.0.0.1/32 > > password > > host all all 192.168.0.0/1 > > password > > > > restart posgresql by > > /sbin/service postgresql restart > > The server was restarted OK. > > > > The PHP script used to connect database is as > > follows, > > > $conn =3D pg_connect("host=3Dlocalhost port=3D5432 > > dbname=3Dfoodb user=3Dfoo > > password=3Dfoo") or die ("Can not connect to > > postgres"); > > $result=3Dpg_exec("SELECT * FROM footbl"); > > $fetch =3D pg_fetch_row($result); > > print ""; > > print $fetch[0]; > > print ""; > > > > pg_close($conn); // Close this connection > > ?> > > > > Assume this PHP script is named as "connectdb.php", > > then on > > commandline, when I run the following, > > php connectedb.php > > I see correct results, e.g., > > foo > > > > On commandline again, I used the following to > > connect database, > > psql -d foodb -h localhost -p 5432 -U foo > > Password: ************ > > Welcome to psql 8.0.3, the PostgreSQL interactive > > terminal. > > > > Type: \copyright for distribution terms > > \h for help with SQL commands > > \? for help with psql commands > > \g or terminate with semicolon to execute > > query > > \q to quit > > > > foodb=3D> > > > > It is OK. Then I disabled "iptables" temporarily for > > testing purpose by > > /sbin/service iptables stop > > Flushing firewall rules: > > [ OK ] > > Setting chains to policy ACCEPT: filter > > [ OK ] > > Unloading iptables modules: > > [ OK ] > > > > On localhost, I tried this command, > > telnet localhost 5432 > > after hit "enters", telnet exited. I checked > > postgresql_%S.log and see > > "LOG: invalid length of startup packet" > > which means postgresql server indeed saw the telnet > > connection. > > > > I tried this on any of my other machines in the LAN, > > I observed the same thing. > > > > In summary, it seemed the postgresql allowed TCP/IP > > connection, and > > worked well. However, when I ran the PHP script > > through web browser, I > > did not get connection. Instead, in Apache web > > server's error_log, I > > see > > [client 192.168.1.10] PHP Warning: pg_connect() [ > href=3D'function.pg-connect'>function.pg-connect]: > > Unable to connect > > to PostgreSQL server: could not connect to server: > > Permission > > denied\n\tIs the server running on host > > "localhost" and > > accepting\n\tTCP/IP connections on port 5432? in > > /foo/connectdb.php on > > line 2 > > > > Interestingly, when I checked the log file for > > postgresql again, it > > did not have anything for this connection failure. > > It seemed the > > connection did not send to the database server at > > all. However, > > 1) I disabled firewall > > 2) I can telnet the ports > > 3) I can run the script from commandline > > > > What could go wrong? > > > > Thanks a lot for your reading this lengthy email. > > Waiting for your help! > > > > Gray > > > > ---------------------------(end of > > broadcast)--------------------------- > > TIP 4: Have you searched our list archives? > > > > http://archives.postgresql.org > > >=20 >=20 > __________________________________________________ > Do You Yahoo!? > Tired of spam? Yahoo! Mail has the best spam protection around > http://mail.yahoo.com > From matt@jobsforge.com Wed Aug 17 11:06:49 2005 X-Original-To: pgsql-php-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id DE08E52971 for ; Wed, 17 Aug 2005 08:06:49 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 46547-07 for ; Wed, 17 Aug 2005 11:06:45 +0000 (GMT) Received: from mout.perfora.net (mout.perfora.net [217.160.230.40]) by svr1.postgresql.org (Postfix) with ESMTP id 663425292A for ; Wed, 17 Aug 2005 08:06:44 -0300 (ADT) Received: from ool-45782123.dyn.optonline.net [69.120.33.35] (helo=[192.168.2.18]) by mrelay.perfora.net with ESMTP (Nemesis), id 0MKoyl-1E5Lkn0bui-0006OZ; Wed, 17 Aug 2005 07:06:41 -0400 In-Reply-To: <923c3c14050816220347aaa1f9@mail.gmail.com> References: <923c3c1405081410326a1c2880@mail.gmail.com> <20050816021902.73901.qmail@web33304.mail.mud.yahoo.com> <923c3c14050816220347aaa1f9@mail.gmail.com> Mime-Version: 1.0 (Apple Message framework v622) Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed Message-Id: <99dfa3a8b0e6a45655296cca37bf148d@jobsforge.com> Content-Transfer-Encoding: 7bit Cc: pgsql-php@postgresql.org, "operationsengineer1@yahoo.com" From: Matthew Terenzio Subject: Re: Problem about connecting PostgreSQL through TCP/IP Date: Wed, 17 Aug 2005 07:06:40 -0400 To: Hui Chen X-Mailer: Apple Mail (2.622) X-Provags-ID: perfora.net abuse@perfora.net login:55dcc513cc7db400396c2523adeeb8ca X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.123 required=5 tests=[AWL=0.123] X-Spam-Level: X-Archive-Number: 200508/15 X-Sequence-Number: 3227 This may be of interest to the PHP Dev group. I'll forward it to someone there. On Aug 17, 2005, at 1:03 AM, Hui Chen wrote: > Hello, > > Thanks a lot! > > I did noticed "-i" option. I am using 8.0 whose manual > (http://www.postgresql.org/docs/8.0/interactive/app-postmaster.html) > states that "-i" option is deprecated. The manual > (http://www.postgresql.org/docs/8.0/interactive/runtime- > config.html#RUNTIME-CONFIG-CONNECTION) > also says that I can enable "listen_addresses" option in the > postgresql.conf to enable the server to listen over TCP/IP. What > really puzzles me is that I could actually telnet server at 5432 ports > and saw an corresponding entry in the log file; however, when I used > PHP to connect the server, the log file did not have an entry for the > failed connection attempt at all. Do you think what can go wrong? > Thanks! > > Gray > > > On 8/15/05, operationsengineer1@yahoo.com > wrote: >> did you enable the "i" flag when you started the >> postmaster? if you didn't do that, tcp/ip will not >> connect! >> >> http://www.postgresql.org/docs/7.4/interactive/app-postmaster.html >> >> good luck. >> >> --- Hui Chen wrote: >> >>> Hello, everyone, >>> >>> Can anyone help me? I am quite frustrating now. I >>> have been trying to >>> connect PostgreSQL server through TCP/IP connection >>> using PHP. I was >>> not successful. Could please read the following and >>> give me some >>> hints. Thanks a million. >>> >>> OS: Fedora Core 4 ("uname -s -r" yields "Linux >>> 2.6.12-1.1398_FC4smp") >>> PostgreSQL: version 8.0.3 >>> PHP: version 5.0.4 >>> >>> In postgresql.conf, these three lines were inserted, >>> >>> listen_addresses = '*' >>> port = 5432 >>> max_connections = 100 >>> >>> The following lines were inserted to pg_hba.conf: >>> local all all >>> password >>> host all all 127.0.0.1/32 >>> password >>> host all all 192.168.0.0/1 >>> password >>> >>> restart posgresql by >>> /sbin/service postgresql restart >>> The server was restarted OK. >>> >>> The PHP script used to connect database is as >>> follows, >>> >> $conn = pg_connect("host=localhost port=5432 >>> dbname=foodb user=foo >>> password=foo") or die ("Can not connect to >>> postgres"); >>> $result=pg_exec("SELECT * FROM footbl"); >>> $fetch = pg_fetch_row($result); >>> print ""; >>> print $fetch[0]; >>> print ""; >>> >>> pg_close($conn); // Close this connection >>> ?> >>> >>> Assume this PHP script is named as "connectdb.php", >>> then on >>> commandline, when I run the following, >>> php connectedb.php >>> I see correct results, e.g., >>> foo >>> >>> On commandline again, I used the following to >>> connect database, >>> psql -d foodb -h localhost -p 5432 -U foo >>> Password: ************ >>> Welcome to psql 8.0.3, the PostgreSQL interactive >>> terminal. >>> >>> Type: \copyright for distribution terms >>> \h for help with SQL commands >>> \? for help with psql commands >>> \g or terminate with semicolon to execute >>> query >>> \q to quit >>> >>> foodb=> >>> >>> It is OK. Then I disabled "iptables" temporarily for >>> testing purpose by >>> /sbin/service iptables stop >>> Flushing firewall rules: >>> [ OK ] >>> Setting chains to policy ACCEPT: filter >>> [ OK ] >>> Unloading iptables modules: >>> [ OK ] >>> >>> On localhost, I tried this command, >>> telnet localhost 5432 >>> after hit "enters", telnet exited. I checked >>> postgresql_%S.log and see >>> "LOG: invalid length of startup packet" >>> which means postgresql server indeed saw the telnet >>> connection. >>> >>> I tried this on any of my other machines in the LAN, >>> I observed the same thing. >>> >>> In summary, it seemed the postgresql allowed TCP/IP >>> connection, and >>> worked well. However, when I ran the PHP script >>> through web browser, I >>> did not get connection. Instead, in Apache web >>> server's error_log, I >>> see >>> [client 192.168.1.10] PHP Warning: pg_connect() [>> href='function.pg-connect'>function.pg-connect]: >>> Unable to connect >>> to PostgreSQL server: could not connect to server: >>> Permission >>> denied\n\tIs the server running on host >>> "localhost" and >>> accepting\n\tTCP/IP connections on port 5432? in >>> /foo/connectdb.php on >>> line 2 >>> >>> Interestingly, when I checked the log file for >>> postgresql again, it >>> did not have anything for this connection failure. >>> It seemed the >>> connection did not send to the database server at >>> all. However, >>> 1) I disabled firewall >>> 2) I can telnet the ports >>> 3) I can run the script from commandline >>> >>> What could go wrong? >>> >>> Thanks a lot for your reading this lengthy email. >>> Waiting for your help! >>> >>> Gray >>> >>> ---------------------------(end of >>> broadcast)--------------------------- >>> TIP 4: Have you searched our list archives? >>> >>> http://archives.postgresql.org >>> >> >> >> __________________________________________________ >> Do You Yahoo!? >> Tired of spam? Yahoo! Mail has the best spam protection around >> http://mail.yahoo.com >> > > ---------------------------(end of > broadcast)--------------------------- > TIP 2: Don't 'kill -9' the postmaster > From gray.chenhui@gmail.com Wed Aug 17 15:32:35 2005 X-Original-To: pgsql-php-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 7023C52938 for ; Wed, 17 Aug 2005 12:32:35 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 24119-07 for ; Wed, 17 Aug 2005 15:32:30 +0000 (GMT) Received: from wproxy.gmail.com (wproxy.gmail.com [64.233.184.202]) by svr1.postgresql.org (Postfix) with ESMTP id 389EE5281E for ; Wed, 17 Aug 2005 12:32:29 -0300 (ADT) Received: by wproxy.gmail.com with SMTP id i22so167075wra for ; Wed, 17 Aug 2005 08:32:29 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=t/BAG9bBKL5E1U4bJNOiDcjzfkbQeNhkgbDkkS0UIx44NjbVjFnE4sFNHdJJC/7UsBHqRzBhj4JX9wyfvBds+CcGQNzkiHFBJqwVWb9eKzfHrlirjeVpANPc2BNGJ5sCKjQ17IwBVeOAXSZyLNgwpnYvS+6gSHJAGmy4IBDDn2g= Received: by 10.54.36.35 with SMTP id j35mr506948wrj; Wed, 17 Aug 2005 08:32:29 -0700 (PDT) Received: by 10.54.98.9 with HTTP; Wed, 17 Aug 2005 08:32:26 -0700 (PDT) Message-ID: <923c3c14050817083231e4870@mail.gmail.com> Date: Wed, 17 Aug 2005 10:32:26 -0500 From: Hui Chen To: shadowbox Subject: Re: Problem about connecting PostgreSQL through TCP/IP Cc: pgsql-php@postgresql.org In-Reply-To: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline References: <923c3c1405081410326a1c2880@mail.gmail.com> <20050816021902.73901.qmail@web33304.mail.mud.yahoo.com> <923c3c14050816220347aaa1f9@mail.gmail.com> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.102 required=5 tests=[AWL=0.078, RCVD_BY_IP=0.024] X-Spam-Level: X-Archive-Number: 200508/17 X-Sequence-Number: 3229 Hello,=20 Very good point. But did configure the PHP with pgsql support. In fact, I can successfully connect the postgresql server over UNIX-domain socket, e.g., this code below uses the UNIX-domain socket since I do not have include "host" and "port" in "pg_connect" function call, "; print $fetch[0]; print ""; pg_close($conn); // Close this connection ?> This code produced the expected result. However, when "host" and "port" were given, the connection failed. What I can conclude is, 1) PHP was successfully configured with postgresql support. PHP connected the database server UNIX-domain socket without any problem; However, PHP could not establish connection with the database server over TCP/IP 2) It seemed the database server accepted TCP/IP connection since I could locate an entry in the database log file when a telnet attempt at port 5432 was issued. 3) PHP did not pass the connection to the database at all because I did not see any entry for the failed connection in the database log file. Am I getting it correctly? How should I do?=20 Thanks a lot! Gray On 8/17/05, shadowbox wrote: > did you configure your PHP with pgsql support? >=20 > On 8/17/05, Hui Chen wrote: > > Hello, > > > > Thanks a lot! > > > > I did noticed "-i" option. I am using 8.0 whose manual > > (http://www.postgresql.org/docs/8.0/interactive/app-postmaster.html) > > states that "-i" option is deprecated. The manual > > (http://www.postgresql.org/docs/8.0/interactive/runtime-config.html#RUN= TIME-CONFIG-CONNECTION) > > also says that I can enable "listen_addresses" option in the > > postgresql.conf to enable the server to listen over TCP/IP. What > > really puzzles me is that I could actually telnet server at 5432 ports > > and saw an corresponding entry in the log file; however, when I used > > PHP to connect the server, the log file did not have an entry for the > > failed connection attempt at all. Do you think what can go wrong? > > Thanks! > > > > Gray > > > > > > On 8/15/05, operationsengineer1@yahoo.com wrote: > > > did you enable the "i" flag when you started the > > > postmaster? if you didn't do that, tcp/ip will not > > > connect! > > > > > > http://www.postgresql.org/docs/7.4/interactive/app-postmaster.html > > > > > > good luck. > > > > > > --- Hui Chen wrote: > > > > > > > Hello, everyone, > > > > > > > > Can anyone help me? I am quite frustrating now. I > > > > have been trying to > > > > connect PostgreSQL server through TCP/IP connection > > > > using PHP. I was > > > > not successful. Could please read the following and > > > > give me some > > > > hints. Thanks a million. > > > > > > > > OS: Fedora Core 4 ("uname -s -r" yields "Linux > > > > 2.6.12-1.1398_FC4smp") > > > > PostgreSQL: version 8.0.3 > > > > PHP: version 5.0.4 > > > > > > > > In postgresql.conf, these three lines were inserted, > > > > > > > > listen_addresses =3D '*' > > > > port =3D 5432 > > > > max_connections =3D 100 > > > > > > > > The following lines were inserted to pg_hba.conf: > > > > local all all > > > > password > > > > host all all 127.0.0.1/32 > > > > password > > > > host all all 192.168.0.0/1 > > > > password > > > > > > > > restart posgresql by > > > > /sbin/service postgresql restart > > > > The server was restarted OK. > > > > > > > > The PHP script used to connect database is as > > > > follows, > > > > > > > $conn =3D pg_connect("host=3Dlocalhost port=3D5432 > > > > dbname=3Dfoodb user=3Dfoo > > > > password=3Dfoo") or die ("Can not connect to > > > > postgres"); > > > > $result=3Dpg_exec("SELECT * FROM footbl"); > > > > $fetch =3D pg_fetch_row($result); > > > > print ""; > > > > print $fetch[0]; > > > > print ""; > > > > > > > > pg_close($conn); // Close this connection > > > > ?> > > > > > > > > Assume this PHP script is named as "connectdb.php", > > > > then on > > > > commandline, when I run the following, > > > > php connectedb.php > > > > I see correct results, e.g., > > > > foo > > > > > > > > On commandline again, I used the following to > > > > connect database, > > > > psql -d foodb -h localhost -p 5432 -U foo > > > > Password: ************ > > > > Welcome to psql 8.0.3, the PostgreSQL interactive > > > > terminal. > > > > > > > > Type: \copyright for distribution terms > > > > \h for help with SQL commands > > > > \? for help with psql commands > > > > \g or terminate with semicolon to execute > > > > query > > > > \q to quit > > > > > > > > foodb=3D> > > > > > > > > It is OK. Then I disabled "iptables" temporarily for > > > > testing purpose by > > > > /sbin/service iptables stop > > > > Flushing firewall rules: > > > > [ OK ] > > > > Setting chains to policy ACCEPT: filter > > > > [ OK ] > > > > Unloading iptables modules: > > > > [ OK ] > > > > > > > > On localhost, I tried this command, > > > > telnet localhost 5432 > > > > after hit "enters", telnet exited. I checked > > > > postgresql_%S.log and see > > > > "LOG: invalid length of startup packet" > > > > which means postgresql server indeed saw the telnet > > > > connection. > > > > > > > > I tried this on any of my other machines in the LAN, > > > > I observed the same thing. > > > > > > > > In summary, it seemed the postgresql allowed TCP/IP > > > > connection, and > > > > worked well. However, when I ran the PHP script > > > > through web browser, I > > > > did not get connection. Instead, in Apache web > > > > server's error_log, I > > > > see > > > > [client 192.168.1.10] PHP Warning: pg_connect() [ > > > href=3D'function.pg-connect'>function.pg-connect]: > > > > Unable to connect > > > > to PostgreSQL server: could not connect to server: > > > > Permission > > > > denied\n\tIs the server running on host > > > > "localhost" and > > > > accepting\n\tTCP/IP connections on port 5432? in > > > > /foo/connectdb.php on > > > > line 2 > > > > > > > > Interestingly, when I checked the log file for > > > > postgresql again, it > > > > did not have anything for this connection failure. > > > > It seemed the > > > > connection did not send to the database server at > > > > all. However, > > > > 1) I disabled firewall > > > > 2) I can telnet the ports > > > > 3) I can run the script from commandline > > > > > > > > What could go wrong? > > > > > > > > Thanks a lot for your reading this lengthy email. > > > > Waiting for your help! > > > > > > > > Gray > > > > > > > > ---------------------------(end of > > > > broadcast)--------------------------- > > > > TIP 4: Have you searched our list archives? > > > > > > > > http://archives.postgresql.org > > > > > > > > > > > > > __________________________________________________ > > > Do You Yahoo!? > > > Tired of spam? Yahoo! Mail has the best spam protection around > > > http://mail.yahoo.com > > > > > > > ---------------------------(end of broadcast)--------------------------= - > > TIP 2: Don't 'kill -9' the postmaster > > > From gray.chenhui@gmail.com Wed Aug 17 15:33:53 2005 X-Original-To: pgsql-php-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 9B42652BA9 for ; Wed, 17 Aug 2005 12:33:53 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 26601-03 for ; Wed, 17 Aug 2005 15:33:51 +0000 (GMT) Received: from wproxy.gmail.com (wproxy.gmail.com [64.233.184.196]) by svr1.postgresql.org (Postfix) with ESMTP id 5130C52A44 for ; Wed, 17 Aug 2005 12:33:50 -0300 (ADT) Received: by wproxy.gmail.com with SMTP id i22so167336wra for ; Wed, 17 Aug 2005 08:33:50 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=cU9MXXiidoO6OdZ6PH0D6Q4ekMJZCMG7MlHTNQVKvH9kpNCsxwE6yKoNY2x+tHyyuBO47Ou0LRC2qQk4w/CAqL6OlDy4GjF7314Jt3is6GL0nuuBvuoVfFVI/LpLiElQD8k/7n4CDIJpsqJAN9A1Xl0wQjiQ8Gmt8iFmow8idn4= Received: by 10.54.100.20 with SMTP id x20mr505787wrb; Wed, 17 Aug 2005 08:33:50 -0700 (PDT) Received: by 10.54.98.9 with HTTP; Wed, 17 Aug 2005 08:33:50 -0700 (PDT) Message-ID: <923c3c14050817083355d31d7@mail.gmail.com> Date: Wed, 17 Aug 2005 10:33:50 -0500 From: Hui Chen To: Matthew Terenzio Subject: Re: Problem about connecting PostgreSQL through TCP/IP Cc: pgsql-php@postgresql.org In-Reply-To: <99dfa3a8b0e6a45655296cca37bf148d@jobsforge.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline References: <923c3c1405081410326a1c2880@mail.gmail.com> <20050816021902.73901.qmail@web33304.mail.mud.yahoo.com> <923c3c14050816220347aaa1f9@mail.gmail.com> <99dfa3a8b0e6a45655296cca37bf148d@jobsforge.com> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.091 required=5 tests=[AWL=0.067, RCVD_BY_IP=0.024] X-Spam-Level: X-Archive-Number: 200508/16 X-Sequence-Number: 3228 Hello, Matthew, This is indeed great point. Thanks a lot for your help! Gray On 8/17/05, Matthew Terenzio wrote: > This may be of interest to the PHP Dev group. I'll forward it to > someone there. >=20 >=20 > On Aug 17, 2005, at 1:03 AM, Hui Chen wrote: >=20 > > Hello, > > > > Thanks a lot! > > > > I did noticed "-i" option. I am using 8.0 whose manual > > (http://www.postgresql.org/docs/8.0/interactive/app-postmaster.html) > > states that "-i" option is deprecated. The manual > > (http://www.postgresql.org/docs/8.0/interactive/runtime- > > config.html#RUNTIME-CONFIG-CONNECTION) > > also says that I can enable "listen_addresses" option in the > > postgresql.conf to enable the server to listen over TCP/IP. What > > really puzzles me is that I could actually telnet server at 5432 ports > > and saw an corresponding entry in the log file; however, when I used > > PHP to connect the server, the log file did not have an entry for the > > failed connection attempt at all. Do you think what can go wrong? > > Thanks! > > > > Gray > > > > > > On 8/15/05, operationsengineer1@yahoo.com > > wrote: > >> did you enable the "i" flag when you started the > >> postmaster? if you didn't do that, tcp/ip will not > >> connect! > >> > >> http://www.postgresql.org/docs/7.4/interactive/app-postmaster.html > >> > >> good luck. > >> > >> --- Hui Chen wrote: > >> > >>> Hello, everyone, > >>> > >>> Can anyone help me? I am quite frustrating now. I > >>> have been trying to > >>> connect PostgreSQL server through TCP/IP connection > >>> using PHP. I was > >>> not successful. Could please read the following and > >>> give me some > >>> hints. Thanks a million. > >>> > >>> OS: Fedora Core 4 ("uname -s -r" yields "Linux > >>> 2.6.12-1.1398_FC4smp") > >>> PostgreSQL: version 8.0.3 > >>> PHP: version 5.0.4 > >>> > >>> In postgresql.conf, these three lines were inserted, > >>> > >>> listen_addresses =3D '*' > >>> port =3D 5432 > >>> max_connections =3D 100 > >>> > >>> The following lines were inserted to pg_hba.conf: > >>> local all all > >>> password > >>> host all all 127.0.0.1/32 > >>> password > >>> host all all 192.168.0.0/1 > >>> password > >>> > >>> restart posgresql by > >>> /sbin/service postgresql restart > >>> The server was restarted OK. > >>> > >>> The PHP script used to connect database is as > >>> follows, > >>> >>> $conn =3D pg_connect("host=3Dlocalhost port=3D5432 > >>> dbname=3Dfoodb user=3Dfoo > >>> password=3Dfoo") or die ("Can not connect to > >>> postgres"); > >>> $result=3Dpg_exec("SELECT * FROM footbl"); > >>> $fetch =3D pg_fetch_row($result); > >>> print ""; > >>> print $fetch[0]; > >>> print ""; > >>> > >>> pg_close($conn); // Close this connection > >>> ?> > >>> > >>> Assume this PHP script is named as "connectdb.php", > >>> then on > >>> commandline, when I run the following, > >>> php connectedb.php > >>> I see correct results, e.g., > >>> foo > >>> > >>> On commandline again, I used the following to > >>> connect database, > >>> psql -d foodb -h localhost -p 5432 -U foo > >>> Password: ************ > >>> Welcome to psql 8.0.3, the PostgreSQL interactive > >>> terminal. > >>> > >>> Type: \copyright for distribution terms > >>> \h for help with SQL commands > >>> \? for help with psql commands > >>> \g or terminate with semicolon to execute > >>> query > >>> \q to quit > >>> > >>> foodb=3D> > >>> > >>> It is OK. Then I disabled "iptables" temporarily for > >>> testing purpose by > >>> /sbin/service iptables stop > >>> Flushing firewall rules: > >>> [ OK ] > >>> Setting chains to policy ACCEPT: filter > >>> [ OK ] > >>> Unloading iptables modules: > >>> [ OK ] > >>> > >>> On localhost, I tried this command, > >>> telnet localhost 5432 > >>> after hit "enters", telnet exited. I checked > >>> postgresql_%S.log and see > >>> "LOG: invalid length of startup packet" > >>> which means postgresql server indeed saw the telnet > >>> connection. > >>> > >>> I tried this on any of my other machines in the LAN, > >>> I observed the same thing. > >>> > >>> In summary, it seemed the postgresql allowed TCP/IP > >>> connection, and > >>> worked well. However, when I ran the PHP script > >>> through web browser, I > >>> did not get connection. Instead, in Apache web > >>> server's error_log, I > >>> see > >>> [client 192.168.1.10] PHP Warning: pg_connect() [ >>> href=3D'function.pg-connect'>function.pg-connect]: > >>> Unable to connect > >>> to PostgreSQL server: could not connect to server: > >>> Permission > >>> denied\n\tIs the server running on host > >>> "localhost" and > >>> accepting\n\tTCP/IP connections on port 5432? in > >>> /foo/connectdb.php on > >>> line 2 > >>> > >>> Interestingly, when I checked the log file for > >>> postgresql again, it > >>> did not have anything for this connection failure. > >>> It seemed the > >>> connection did not send to the database server at > >>> all. However, > >>> 1) I disabled firewall > >>> 2) I can telnet the ports > >>> 3) I can run the script from commandline > >>> > >>> What could go wrong? > >>> > >>> Thanks a lot for your reading this lengthy email. > >>> Waiting for your help! > >>> > >>> Gray > >>> > >>> ---------------------------(end of > >>> broadcast)--------------------------- > >>> TIP 4: Have you searched our list archives? > >>> > >>> http://archives.postgresql.org > >>> > >> > >> > >> __________________________________________________ > >> Do You Yahoo!? > >> Tired of spam? Yahoo! Mail has the best spam protection around > >> http://mail.yahoo.com > >> > > > > ---------------------------(end of > > broadcast)--------------------------- > > TIP 2: Don't 'kill -9' the postmaster > > >=20 > From javier.wilson@gmail.com Wed Aug 17 15:55:58 2005 X-Original-To: pgsql-php-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id E1947528DA for ; Wed, 17 Aug 2005 12:55:58 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 34371-05 for ; Wed, 17 Aug 2005 15:55:56 +0000 (GMT) Received: from wproxy.gmail.com (wproxy.gmail.com [64.233.184.206]) by svr1.postgresql.org (Postfix) with ESMTP id 0DA3C528AD for ; Wed, 17 Aug 2005 12:55:55 -0300 (ADT) Received: by wproxy.gmail.com with SMTP id i4so181966wra for ; Wed, 17 Aug 2005 08:55:55 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=pX/FcVbFvwX46lqh6ZNndZOQBj3pbAl/AF/sLzbPaDWQuNGsrfAvltaqlqEuAVODOQFuPjMcu+W54Eug059UutRugUkU/4tr6gGpL9qckEAmnFCk/+n/9HaLkpxxnw1i/Fs7QtgHeMJiPk+J1wQ84/rZspuS30ze+rgSc1k1JOA= Received: by 10.54.21.53 with SMTP id 53mr533695wru; Wed, 17 Aug 2005 08:55:55 -0700 (PDT) Received: by 10.54.4.12 with HTTP; Wed, 17 Aug 2005 08:55:55 -0700 (PDT) Message-ID: Date: Wed, 17 Aug 2005 10:55:55 -0500 From: javier wilson To: Hui Chen Subject: Re: Problem about connecting PostgreSQL through TCP/IP Cc: pgsql-php@postgresql.org In-Reply-To: <923c3c1405081410326a1c2880@mail.gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline References: <923c3c1405081410326a1c2880@mail.gmail.com> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.228 required=5 tests=[AWL=0.204, RCVD_BY_IP=0.024] X-Spam-Level: X-Archive-Number: 200508/23 X-Sequence-Number: 3235 On 8/14/05, Hui Chen wrote: > Hello, everyone, >=20 > Can anyone help me? I am quite frustrating now. I have been trying to > connect PostgreSQL server through TCP/IP connection using PHP. I was > not successful. Could please read the following and give me some > hints. Thanks a million. >=20 > OS: Fedora Core 4 ("uname -s -r" yields "Linux 2.6.12-1.1398_FC4smp") > PostgreSQL: version 8.0.3 > PHP: version 5.0.4 > In postgresql.conf, these three lines were inserted, > listen_addresses =3D '*' > port =3D 5432 > max_connections =3D 100 >=20 > The following lines were inserted to pg_hba.conf: > local all all password > host all all 127.0.0.1/32 password > host all all 192.168.0.0/1 password >=20 > restart posgresql by > /sbin/service postgresql restart > The server was restarted OK. >=20 > The PHP script used to connect database is as follows, > $conn =3D pg_connect("host=3Dlocalhost port=3D5432 dbname=3Dfoodb user= =3Dfoo > password=3Dfoo") or die ("Can not connect to postgres"); > $result=3Dpg_exec("SELECT * FROM footbl"); > $fetch =3D pg_fetch_row($result); > print ""; > print $fetch[0]; > print ""; >=20 > pg_close($conn); // Close this connection > ?> >=20 > Assume this PHP script is named as "connectdb.php", then on > commandline, when I run the following, > php connectedb.php > I see correct results, e.g., > foo >=20 > On commandline again, I used the following to connect database, > psql -d foodb -h localhost -p 5432 -U foo > Password: ************ > Welcome to psql 8.0.3, the PostgreSQL interactive terminal. >=20 > Type: \copyright for distribution terms > \h for help with SQL commands > \? for help with psql commands > \g or terminate with semicolon to execute query > \q to quit >=20 > foodb=3D> >=20 > It is OK. Then I disabled "iptables" temporarily for testing purpose by > /sbin/service iptables stop > Flushing firewall rules: [ OK ] > Setting chains to policy ACCEPT: filter [ OK ] > Unloading iptables modules: [ OK ] >=20 > On localhost, I tried this command, > telnet localhost 5432 > after hit "enters", telnet exited. I checked postgresql_%S.log and see > "LOG: invalid length of startup packet" > which means postgresql server indeed saw the telnet connection. >=20 > I tried this on any of my other machines in the LAN, I observed the same = thing. >=20 > In summary, it seemed the postgresql allowed TCP/IP connection, and > worked well. However, when I ran the PHP script through web browser, I > did not get connection. Instead, in Apache web server's error_log, I > see > [client 192.168.1.10] PHP Warning: pg_connect() [ href=3D'function.pg-connect'>function.pg-connect]: Unable to connect > to PostgreSQL server: could not connect to server: Permission > denied\n\tIs the server running on host "localhost" and > accepting\n\tTCP/IP connections on port 5432? in /foo/connectdb.php on > line 2 >=20 > Interestingly, when I checked the log file for postgresql again, it > did not have anything for this connection failure. It seemed the > connection did not send to the database server at all. However, > 1) I disabled firewall > 2) I can telnet the ports > 3) I can run the script from commandline >=20 > What could go wrong? >=20 > Thanks a lot for your reading this lengthy email. Waiting for your help! >=20 > Gray could this have something to do with SELinux? can you disable it alltogethe= r and try? javier From David.Rogers@MCI.com Wed Aug 17 16:32:22 2005 X-Original-To: pgsql-php-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 127F2529B7 for ; Wed, 17 Aug 2005 13:32:22 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 47746-03 for ; Wed, 17 Aug 2005 16:32:18 +0000 (GMT) Received: from pmesmtp04.mci.com (pmesmtp04.mci.com [199.249.20.36]) by svr1.postgresql.org (Postfix) with ESMTP id 13714529B3 for ; Wed, 17 Aug 2005 13:32:17 -0300 (ADT) Received: from pmismtp04.wcomnet.com ([166.38.62.39]) by firewall.mci.com (Iplanet MTA 5.2) with ESMTP id <0ILD005ARKKGW8@firewall.mci.com> for pgsql-php@postgresql.org; Wed, 17 Aug 2005 16:31:28 +0000 (GMT) Received: from pmismtp04.wcomnet.com by pmismtp04.mcilink.com (iPlanet Messaging Server 5.2 HotFix 1.14 (built Mar 18 2003)) with SMTP id <0ILD00J01KKBIP@pmismtp04.mcilink.com>; Wed, 17 Aug 2005 16:31:28 +0000 (GMT) Received: from nsoc6522a.mcilink.com ([166.50.73.109]) by pmismtp04.mcilink.com (iPlanet Messaging Server 5.2 HotFix 1.14 (built Mar 18 2003)) with ESMTP id <0ILD00JMPKKF9B@pmismtp04.mcilink.com>; Wed, 17 Aug 2005 16:31:28 +0000 (GMT) Date: Wed, 17 Aug 2005 11:31:27 -0500 From: David Rogers Subject: Re: Problem about connecting PostgreSQL through TCP/IP In-reply-to: <923c3c14050817083231e4870@mail.gmail.com> To: Hui Chen Cc: pgsql-php@postgresql.org Message-id: <1124296287.3061.13.camel@nsoc6522a.mcilink.com> MIME-version: 1.0 X-Mailer: Evolution 2.2.3 (2.2.3-2.fc4) Content-type: text/plain; CHARSET=us-ascii Content-transfer-encoding: 7bit References: <923c3c1405081410326a1c2880@mail.gmail.com> <20050816021902.73901.qmail@web33304.mail.mud.yahoo.com> <923c3c14050816220347aaa1f9@mail.gmail.com> <923c3c14050817083231e4870@mail.gmail.com> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.542 required=5 tests=[DNS_FROM_RFC_WHOIS=0.492, FORGED_RCVD_HELO=0.05] X-Spam-Level: X-Archive-Number: 200508/18 X-Sequence-Number: 3230 The -i command line switch is depreciated in version 8. A new mechanism is now preferred. In order to connect via TCP/IP you must tell PostgreSQL to listen on TCP interfaces in the file /var/lib/pgsql/data/postgresql.conf Change: listen_addresses = 'localhost' to listen_addresses = '*' You must also have appropriate entries in pg_hba.conf for hosts and authentication type. You could use something like: local all all password host all all 127.0.0.1/32 password host all all 192.168.1.0/24 password Be sure to enter your own subnet instead of 192.168.1.0. On Wed, 2005-08-17 at 10:32 -0500, Hui Chen wrote: > Hello, > > Very good point. But did configure the PHP with pgsql support. In > fact, I can successfully connect the postgresql server over > UNIX-domain socket, e.g., this code below uses the UNIX-domain socket > since I do not have include "host" and "port" in "pg_connect" function > call, > $conn = pg_connect("dbname=foodb user=foo password=foo") or die > ("Can not connect to postgres"); > $result=pg_exec("SELECT * FROM footbl"); > $fetch = pg_fetch_row($result); > print ""; > print $fetch[0]; > print ""; > pg_close($conn); // Close this connection > ?> > This code produced the expected result. However, when "host" and > "port" were given, the connection failed. What I can conclude is, > 1) PHP was successfully configured with postgresql support. PHP > connected the database server UNIX-domain socket without any problem; > However, PHP could not establish connection with the database server > over TCP/IP > 2) It seemed the database server accepted TCP/IP connection since I > could locate an entry in the database log file when a telnet attempt > at port 5432 was issued. > 3) PHP did not pass the connection to the database at all because I > did not see any entry for the failed connection in the database log > file. > Am I getting it correctly? How should I do? > > Thanks a lot! > > Gray > > On 8/17/05, shadowbox wrote: > > did you configure your PHP with pgsql support? > > > > On 8/17/05, Hui Chen wrote: > > > Hello, > > > > > > Thanks a lot! > > > > > > I did noticed "-i" option. I am using 8.0 whose manual > > > (http://www.postgresql.org/docs/8.0/interactive/app-postmaster.html) > > > states that "-i" option is deprecated. The manual > > > (http://www.postgresql.org/docs/8.0/interactive/runtime-config.html#RUNTIME-CONFIG-CONNECTION) > > > also says that I can enable "listen_addresses" option in the > > > postgresql.conf to enable the server to listen over TCP/IP. What > > > really puzzles me is that I could actually telnet server at 5432 ports > > > and saw an corresponding entry in the log file; however, when I used > > > PHP to connect the server, the log file did not have an entry for the > > > failed connection attempt at all. Do you think what can go wrong? > > > Thanks! > > > > > > Gray > > > > > > > > > On 8/15/05, operationsengineer1@yahoo.com wrote: > > > > did you enable the "i" flag when you started the > > > > postmaster? if you didn't do that, tcp/ip will not > > > > connect! > > > > > > > > http://www.postgresql.org/docs/7.4/interactive/app-postmaster.html > > > > > > > > good luck. > > > > > > > > --- Hui Chen wrote: > > > > > > > > > Hello, everyone, > > > > > > > > > > Can anyone help me? I am quite frustrating now. I > > > > > have been trying to > > > > > connect PostgreSQL server through TCP/IP connection > > > > > using PHP. I was > > > > > not successful. Could please read the following and > > > > > give me some > > > > > hints. Thanks a million. > > > > > > > > > > OS: Fedora Core 4 ("uname -s -r" yields "Linux > > > > > 2.6.12-1.1398_FC4smp") > > > > > PostgreSQL: version 8.0.3 > > > > > PHP: version 5.0.4 > > > > > > > > > > In postgresql.conf, these three lines were inserted, > > > > > > > > > > listen_addresses = '*' > > > > > port = 5432 > > > > > max_connections = 100 > > > > > > > > > > The following lines were inserted to pg_hba.conf: > > > > > local all all > > > > > password > > > > > host all all 127.0.0.1/32 > > > > > password > > > > > host all all 192.168.0.0/1 > > > > > password > > > > > > > > > > restart posgresql by > > > > > /sbin/service postgresql restart > > > > > The server was restarted OK. > > > > > > > > > > The PHP script used to connect database is as > > > > > follows, > > > > > > > > > $conn = pg_connect("host=localhost port=5432 > > > > > dbname=foodb user=foo > > > > > password=foo") or die ("Can not connect to > > > > > postgres"); > > > > > $result=pg_exec("SELECT * FROM footbl"); > > > > > $fetch = pg_fetch_row($result); > > > > > print ""; > > > > > print $fetch[0]; > > > > > print ""; > > > > > > > > > > pg_close($conn); // Close this connection > > > > > ?> > > > > > > > > > > Assume this PHP script is named as "connectdb.php", > > > > > then on > > > > > commandline, when I run the following, > > > > > php connectedb.php > > > > > I see correct results, e.g., > > > > > foo > > > > > > > > > > On commandline again, I used the following to > > > > > connect database, > > > > > psql -d foodb -h localhost -p 5432 -U foo > > > > > Password: ************ > > > > > Welcome to psql 8.0.3, the PostgreSQL interactive > > > > > terminal. > > > > > > > > > > Type: \copyright for distribution terms > > > > > \h for help with SQL commands > > > > > \? for help with psql commands > > > > > \g or terminate with semicolon to execute > > > > > query > > > > > \q to quit > > > > > > > > > > foodb=> > > > > > > > > > > It is OK. Then I disabled "iptables" temporarily for > > > > > testing purpose by > > > > > /sbin/service iptables stop > > > > > Flushing firewall rules: > > > > > [ OK ] > > > > > Setting chains to policy ACCEPT: filter > > > > > [ OK ] > > > > > Unloading iptables modules: > > > > > [ OK ] > > > > > > > > > > On localhost, I tried this command, > > > > > telnet localhost 5432 > > > > > after hit "enters", telnet exited. I checked > > > > > postgresql_%S.log and see > > > > > "LOG: invalid length of startup packet" > > > > > which means postgresql server indeed saw the telnet > > > > > connection. > > > > > > > > > > I tried this on any of my other machines in the LAN, > > > > > I observed the same thing. > > > > > > > > > > In summary, it seemed the postgresql allowed TCP/IP > > > > > connection, and > > > > > worked well. However, when I ran the PHP script > > > > > through web browser, I > > > > > did not get connection. Instead, in Apache web > > > > > server's error_log, I > > > > > see > > > > > [client 192.168.1.10] PHP Warning: pg_connect() [ > > > > href='function.pg-connect'>function.pg-connect]: > > > > > Unable to connect > > > > > to PostgreSQL server: could not connect to server: > > > > > Permission > > > > > denied\n\tIs the server running on host > > > > > "localhost" and > > > > > accepting\n\tTCP/IP connections on port 5432? in > > > > > /foo/connectdb.php on > > > > > line 2 > > > > > > > > > > Interestingly, when I checked the log file for > > > > > postgresql again, it > > > > > did not have anything for this connection failure. > > > > > It seemed the > > > > > connection did not send to the database server at > > > > > all. However, > > > > > 1) I disabled firewall > > > > > 2) I can telnet the ports > > > > > 3) I can run the script from commandline > > > > > > > > > > What could go wrong? > > > > > > > > > > Thanks a lot for your reading this lengthy email. > > > > > Waiting for your help! > > > > > > > > > > Gray > > > > > > > > > > ---------------------------(end of > > > > > broadcast)--------------------------- > > > > > TIP 4: Have you searched our list archives? > > > > > > > > > > http://archives.postgresql.org > > > > > > > > > > > > > > > > > __________________________________________________ > > > > Do You Yahoo!? > > > > Tired of spam? Yahoo! Mail has the best spam protection around > > > > http://mail.yahoo.com > > > > > > > > > > ---------------------------(end of broadcast)--------------------------- > > > TIP 2: Don't 'kill -9' the postmaster > > > > > > > ---------------------------(end of broadcast)--------------------------- > TIP 9: In versions below 8.0, the planner will ignore your desire to > choose an index scan if your joining column's datatypes do not > match -- David Rogers vnet 777-6522 Network Security Operations Center From gray.chenhui@gmail.com Wed Aug 17 17:46:18 2005 X-Original-To: pgsql-php-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 4C395529C2 for ; Wed, 17 Aug 2005 14:46:18 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 69371-03 for ; Wed, 17 Aug 2005 17:46:16 +0000 (GMT) Received: from wproxy.gmail.com (wproxy.gmail.com [64.233.184.200]) by svr1.postgresql.org (Postfix) with ESMTP id 1F84D5292A for ; Wed, 17 Aug 2005 14:46:15 -0300 (ADT) Received: by wproxy.gmail.com with SMTP id i22so191890wra for ; Wed, 17 Aug 2005 10:46:16 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=l75ps9e+QAMeaQkt+SefqG6PjDOzx8EDOTDMUavXYyYRp5nv9JvRvAVpyAIANJQS/eNoxRxuJLdi1YU0Gh/bVuRi8lX4OCxVU7qoDUZBO5GvC7E2/OEWsmGIOeZhWYs7mDEkKDoa3KYTXcXt1MwNQFSWVq6+NN37xFVJW5AWnqY= Received: by 10.54.36.8 with SMTP id j8mr593979wrj; Wed, 17 Aug 2005 10:46:16 -0700 (PDT) Received: by 10.54.98.9 with HTTP; Wed, 17 Aug 2005 10:46:16 -0700 (PDT) Message-ID: <923c3c140508171046280fe820@mail.gmail.com> Date: Wed, 17 Aug 2005 12:46:16 -0500 From: Hui Chen To: javier wilson Subject: Re: Problem about connecting PostgreSQL through TCP/IP Cc: pgsql-php@postgresql.org In-Reply-To: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline References: <923c3c1405081410326a1c2880@mail.gmail.com> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.071 required=5 tests=[AWL=0.047, RCVD_BY_IP=0.024] X-Spam-Level: X-Archive-Number: 200508/20 X-Sequence-Number: 3232 Hello, Javier, Thanks. I tried accordingly. I change the line in /boot/grub/grob.conf from= =20 kernel /vmlinuz-2.6.12-1.1398_FC4smp ro root=3DLABEL=3D/ rhgb quiet to kernel /vmlinuz-2.6.12-1.1398_FC4smp ro root=3DLABEL=3D/ rhgb quiet selinux= =3D0 . I then reboot the linux. I would assume it will disable SElinux altogehter. The problem remains. I seems like it is not about SElinux. Thanks! Gray On 8/17/05, javier wilson wrote: > could this have something to do with SELinux? can you disable it alltoget= her > and try? > javier > On 8/14/05, Hui Chen wrote: > > Hello, everyone, > > > > Can anyone help me? I am quite frustrating now. I have been trying to > > connect PostgreSQL server through TCP/IP connection using PHP. I was > > not successful. Could please read the following and give me some > > hints. Thanks a million. > > > > OS: Fedora Core 4 ("uname -s -r" yields "Linux 2.6.12-1.1398_FC4smp") > > PostgreSQL: version 8.0.3 > > PHP: version 5.0.4 > > In postgresql.conf, these three lines were inserted, > > listen_addresses =3D '*' > > port =3D 5432 > > max_connections =3D 100 > > > > The following lines were inserted to pg_hba.conf: > > local all all password > > host all all 127.0.0.1/32 password > > host all all 192.168.0.0/1 password > > > > restart posgresql by > > /sbin/service postgresql restart > > The server was restarted OK. > > > > The PHP script used to connect database is as follows, > > > $conn =3D pg_connect("host=3Dlocalhost port=3D5432 dbname=3Dfoodb use= r=3Dfoo > > password=3Dfoo") or die ("Can not connect to postgres"); > > $result=3Dpg_exec("SELECT * FROM footbl"); > > $fetch =3D pg_fetch_row($result); > > print ""; > > print $fetch[0]; > > print ""; > > > > pg_close($conn); // Close this connection > > ?> > > > > Assume this PHP script is named as "connectdb.php", then on > > commandline, when I run the following, > > php connectedb.php > > I see correct results, e.g., > > foo > > > > On commandline again, I used the following to connect database, > > psql -d foodb -h localhost -p 5432 -U foo > > Password: ************ > > Welcome to psql 8.0.3, the PostgreSQL interactive terminal. > > > > Type: \copyright for distribution terms > > \h for help with SQL commands > > \? for help with psql commands > > \g or terminate with semicolon to execute query > > \q to quit > > > > foodb=3D> > > > > It is OK. Then I disabled "iptables" temporarily for testing purpose by > > /sbin/service iptables stop > > Flushing firewall rules: [ OK ] > > Setting chains to policy ACCEPT: filter [ OK ] > > Unloading iptables modules: [ OK ] > > > > On localhost, I tried this command, > > telnet localhost 5432 > > after hit "enters", telnet exited. I checked postgresql_%S.log and see > > "LOG: invalid length of startup packet" > > which means postgresql server indeed saw the telnet connection. > > > > I tried this on any of my other machines in the LAN, I observed the sam= e thing. > > > > In summary, it seemed the postgresql allowed TCP/IP connection, and > > worked well. However, when I ran the PHP script through web browser, I > > did not get connection. Instead, in Apache web server's error_log, I > > see > > [client 192.168.1.10] PHP Warning: pg_connect() [ > href=3D'function.pg-connect'>function.pg-connect]: Unable to connec= t > > to PostgreSQL server: could not connect to server: Permission > > denied\n\tIs the server running on host "localhost" and > > accepting\n\tTCP/IP connections on port 5432? in /foo/connectdb.php on > > line 2 > > > > Interestingly, when I checked the log file for postgresql again, it > > did not have anything for this connection failure. It seemed the > > connection did not send to the database server at all. However, > > 1) I disabled firewall > > 2) I can telnet the ports > > 3) I can run the script from commandline > > > > What could go wrong? > > > > Thanks a lot for your reading this lengthy email. Waiting for your help= ! > > > > Gray >=20 > could this have something to do with SELinux? can you disable it alltoget= her > and try? >=20 > javier > From gray.chenhui@gmail.com Wed Aug 17 17:48:42 2005 X-Original-To: pgsql-php-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 458C452BFD for ; Wed, 17 Aug 2005 14:48:42 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 69471-05 for ; Wed, 17 Aug 2005 17:48:39 +0000 (GMT) Received: from wproxy.gmail.com (wproxy.gmail.com [64.233.184.204]) by svr1.postgresql.org (Postfix) with ESMTP id CF39A52BE5 for ; Wed, 17 Aug 2005 14:48:38 -0300 (ADT) Received: by wproxy.gmail.com with SMTP id i22so192295wra for ; Wed, 17 Aug 2005 10:48:38 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=B6zg0QJjjD963O/bJoIrBrqfgqts+Z/MiH0uLuCk81QrMexHIFhPNbbjZ+tMlzZxqL7qHmePxoCLThucOI9cHggAJgt0My+OLg6iZxnO6WOwaZi1fvkC1HXsOq8QocW/xawsqPT9w2d/SFZM+yHbxAqpbVsR4NgNgkh+eAPXKYo= Received: by 10.54.142.2 with SMTP id p2mr588178wrd; Wed, 17 Aug 2005 10:48:38 -0700 (PDT) Received: by 10.54.98.9 with HTTP; Wed, 17 Aug 2005 10:48:38 -0700 (PDT) Message-ID: <923c3c1405081710486f4a1bfa@mail.gmail.com> Date: Wed, 17 Aug 2005 12:48:38 -0500 From: Hui Chen To: David Rogers Subject: Re: Problem about connecting PostgreSQL through TCP/IP Cc: pgsql-php@postgresql.org In-Reply-To: <1124296287.3061.13.camel@nsoc6522a.mcilink.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline References: <923c3c1405081410326a1c2880@mail.gmail.com> <20050816021902.73901.qmail@web33304.mail.mud.yahoo.com> <923c3c14050816220347aaa1f9@mail.gmail.com> <923c3c14050817083231e4870@mail.gmail.com> <1124296287.3061.13.camel@nsoc6522a.mcilink.com> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.067 required=5 tests=[AWL=0.043, RCVD_BY_IP=0.024] X-Spam-Level: X-Archive-Number: 200508/19 X-Sequence-Number: 3231 which is what I did. I encounter the connection problem with the configuration the same as what you have shown except that the ip addresses and its masks were different. Thanks! Gray On 8/17/05, David Rogers wrote: > The -i command line switch is depreciated in version 8. A new mechanism > is now preferred. In order to connect via TCP/IP you must tell > PostgreSQL to listen on TCP interfaces in the file >=20 > /var/lib/pgsql/data/postgresql.conf >=20 > Change: >=20 > listen_addresses =3D 'localhost' to listen_addresses =3D '*' >=20 > You must also have appropriate entries in pg_hba.conf for hosts and > authentication type. You could use something like: >=20 > local all all password > host all all 127.0.0.1/32 password > host all all 192.168.1.0/24 password >=20 > Be sure to enter your own subnet instead of 192.168.1.0. >=20 >=20 >=20 > On Wed, 2005-08-17 at 10:32 -0500, Hui Chen wrote: > > Hello, > > > > Very good point. But did configure the PHP with pgsql support. In > > fact, I can successfully connect the postgresql server over > > UNIX-domain socket, e.g., this code below uses the UNIX-domain socket > > since I do not have include "host" and "port" in "pg_connect" function > > call, > > > $conn =3D pg_connect("dbname=3Dfoodb user=3Dfoo password=3Dfoo") or= die > > ("Can not connect to postgres"); > > $result=3Dpg_exec("SELECT * FROM footbl"); > > $fetch =3D pg_fetch_row($result); > > print ""; > > print $fetch[0]; > > print ""; > > pg_close($conn); // Close this connection > > ?> > > This code produced the expected result. However, when "host" and > > "port" were given, the connection failed. What I can conclude is, > > 1) PHP was successfully configured with postgresql support. PHP > > connected the database server UNIX-domain socket without any problem; > > However, PHP could not establish connection with the database server > > over TCP/IP > > 2) It seemed the database server accepted TCP/IP connection since I > > could locate an entry in the database log file when a telnet attempt > > at port 5432 was issued. > > 3) PHP did not pass the connection to the database at all because I > > did not see any entry for the failed connection in the database log > > file. > > Am I getting it correctly? How should I do? > > > > Thanks a lot! > > > > Gray > > > > On 8/17/05, shadowbox wrote: > > > did you configure your PHP with pgsql support? > > > > > > On 8/17/05, Hui Chen wrote: > > > > Hello, > > > > > > > > Thanks a lot! > > > > > > > > I did noticed "-i" option. I am using 8.0 whose manual > > > > (http://www.postgresql.org/docs/8.0/interactive/app-postmaster.html= ) > > > > states that "-i" option is deprecated. The manual > > > > (http://www.postgresql.org/docs/8.0/interactive/runtime-config.html= #RUNTIME-CONFIG-CONNECTION) > > > > also says that I can enable "listen_addresses" option in the > > > > postgresql.conf to enable the server to listen over TCP/IP. What > > > > really puzzles me is that I could actually telnet server at 5432 po= rts > > > > and saw an corresponding entry in the log file; however, when I use= d > > > > PHP to connect the server, the log file did not have an entry for t= he > > > > failed connection attempt at all. Do you think what can go wrong? > > > > Thanks! > > > > > > > > Gray > > > > > > > > > > > > On 8/15/05, operationsengineer1@yahoo.com wrote: > > > > > did you enable the "i" flag when you started the > > > > > postmaster? if you didn't do that, tcp/ip will not > > > > > connect! > > > > > > > > > > http://www.postgresql.org/docs/7.4/interactive/app-postmaster.htm= l > > > > > > > > > > good luck. > > > > > > > > > > --- Hui Chen wrote: > > > > > > > > > > > Hello, everyone, > > > > > > > > > > > > Can anyone help me? I am quite frustrating now. I > > > > > > have been trying to > > > > > > connect PostgreSQL server through TCP/IP connection > > > > > > using PHP. I was > > > > > > not successful. Could please read the following and > > > > > > give me some > > > > > > hints. Thanks a million. > > > > > > > > > > > > OS: Fedora Core 4 ("uname -s -r" yields "Linux > > > > > > 2.6.12-1.1398_FC4smp") > > > > > > PostgreSQL: version 8.0.3 > > > > > > PHP: version 5.0.4 > > > > > > > > > > > > In postgresql.conf, these three lines were inserted, > > > > > > > > > > > > listen_addresses =3D '*' > > > > > > port =3D 5432 > > > > > > max_connections =3D 100 > > > > > > > > > > > > The following lines were inserted to pg_hba.conf: > > > > > > local all all > > > > > > password > > > > > > host all all 127.0.0.1/32 > > > > > > password > > > > > > host all all 192.168.0.0/1 > > > > > > password > > > > > > > > > > > > restart posgresql by > > > > > > /sbin/service postgresql restart > > > > > > The server was restarted OK. > > > > > > > > > > > > The PHP script used to connect database is as > > > > > > follows, > > > > > > > > > > > $conn =3D pg_connect("host=3Dlocalhost port=3D5432 > > > > > > dbname=3Dfoodb user=3Dfoo > > > > > > password=3Dfoo") or die ("Can not connect to > > > > > > postgres"); > > > > > > $result=3Dpg_exec("SELECT * FROM footbl"); > > > > > > $fetch =3D pg_fetch_row($result); > > > > > > print ""; > > > > > > print $fetch[0]; > > > > > > print ""; > > > > > > > > > > > > pg_close($conn); // Close this connection > > > > > > ?> > > > > > > > > > > > > Assume this PHP script is named as "connectdb.php", > > > > > > then on > > > > > > commandline, when I run the following, > > > > > > php connectedb.php > > > > > > I see correct results, e.g., > > > > > > foo > > > > > > > > > > > > On commandline again, I used the following to > > > > > > connect database, > > > > > > psql -d foodb -h localhost -p 5432 -U foo > > > > > > Password: ************ > > > > > > Welcome to psql 8.0.3, the PostgreSQL interactive > > > > > > terminal. > > > > > > > > > > > > Type: \copyright for distribution terms > > > > > > \h for help with SQL commands > > > > > > \? for help with psql commands > > > > > > \g or terminate with semicolon to execute > > > > > > query > > > > > > \q to quit > > > > > > > > > > > > foodb=3D> > > > > > > > > > > > > It is OK. Then I disabled "iptables" temporarily for > > > > > > testing purpose by > > > > > > /sbin/service iptables stop > > > > > > Flushing firewall rules: > > > > > > [ OK ] > > > > > > Setting chains to policy ACCEPT: filter > > > > > > [ OK ] > > > > > > Unloading iptables modules: > > > > > > [ OK ] > > > > > > > > > > > > On localhost, I tried this command, > > > > > > telnet localhost 5432 > > > > > > after hit "enters", telnet exited. I checked > > > > > > postgresql_%S.log and see > > > > > > "LOG: invalid length of startup packet" > > > > > > which means postgresql server indeed saw the telnet > > > > > > connection. > > > > > > > > > > > > I tried this on any of my other machines in the LAN, > > > > > > I observed the same thing. > > > > > > > > > > > > In summary, it seemed the postgresql allowed TCP/IP > > > > > > connection, and > > > > > > worked well. However, when I ran the PHP script > > > > > > through web browser, I > > > > > > did not get connection. Instead, in Apache web > > > > > > server's error_log, I > > > > > > see > > > > > > [client 192.168.1.10] PHP Warning: pg_connect() [ > > > > > href=3D'function.pg-connect'>function.pg-connect]: > > > > > > Unable to connect > > > > > > to PostgreSQL server: could not connect to server: > > > > > > Permission > > > > > > denied\n\tIs the server running on host > > > > > > "localhost" and > > > > > > accepting\n\tTCP/IP connections on port 5432? in > > > > > > /foo/connectdb.php on > > > > > > line 2 > > > > > > > > > > > > Interestingly, when I checked the log file for > > > > > > postgresql again, it > > > > > > did not have anything for this connection failure. > > > > > > It seemed the > > > > > > connection did not send to the database server at > > > > > > all. However, > > > > > > 1) I disabled firewall > > > > > > 2) I can telnet the ports > > > > > > 3) I can run the script from commandline > > > > > > > > > > > > What could go wrong? > > > > > > > > > > > > Thanks a lot for your reading this lengthy email. > > > > > > Waiting for your help! > > > > > > > > > > > > Gray > > > > > > > > > > > > ---------------------------(end of > > > > > > broadcast)--------------------------- > > > > > > TIP 4: Have you searched our list archives? > > > > > > > > > > > > http://archives.postgresql.org > > > > > > > > > > > > > > > > > > > > > __________________________________________________ > > > > > Do You Yahoo!? > > > > > Tired of spam? Yahoo! Mail has the best spam protection around > > > > > http://mail.yahoo.com > > > > > > > > > > > > > ---------------------------(end of broadcast)----------------------= ----- > > > > TIP 2: Don't 'kill -9' the postmaster > > > > > > > > > > > ---------------------------(end of broadcast)--------------------------= - > > TIP 9: In versions below 8.0, the planner will ignore your desire to > > choose an index scan if your joining column's datatypes do not > > match > -- > David Rogers > vnet 777-6522 > Network Security Operations Center >=20 > From s.gnanavel@gmail.com Thu Aug 18 04:37:30 2005 X-Original-To: pgsql-php-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id B564F52808 for ; Thu, 18 Aug 2005 01:37:30 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 65010-01 for ; Thu, 18 Aug 2005 04:37:26 +0000 (GMT) Received: from zproxy.gmail.com (zproxy.gmail.com [64.233.162.205]) by svr1.postgresql.org (Postfix) with ESMTP id 0125C52A8A for ; Thu, 18 Aug 2005 01:37:24 -0300 (ADT) Received: by zproxy.gmail.com with SMTP id z6so218717nzd for ; Wed, 17 Aug 2005 21:37:24 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:references; b=fM4wnKx/Z4pSZTtkbtatXjD/u3K79U+g/CWpQtBaBRtjWljAuC+IicE5rerXYSPL5Fk8PSSDN+Wpl6uwklfXCDnJFIlpgoWHaWTarer4i//rVydQQG4UOzmyQq0so87bsZKXC0tu1xVZxvpE5qWqH6XEP6fW5i7xbGduAdZoobs= Received: by 10.36.221.9 with SMTP id t9mr545585nzg; Wed, 17 Aug 2005 21:37:24 -0700 (PDT) Received: by 10.36.119.19 with HTTP; Wed, 17 Aug 2005 21:37:24 -0700 (PDT) Message-ID: Date: Thu, 18 Aug 2005 10:07:24 +0530 From: Gnanavel S To: Hui Chen Subject: Re: Problem about connecting PostgreSQL through TCP/IP Cc: pgsql-php@postgresql.org In-Reply-To: <923c3c1405081410326a1c2880@mail.gmail.com> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_8920_26248182.1124339844595" References: <923c3c1405081410326a1c2880@mail.gmail.com> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.374 required=5 tests=[AWL=0.183, HTML_40_50=0.086, HTML_MESSAGE=0.001, NORMAL_HTTP_TO_IP=0.08, RCVD_BY_IP=0.024] X-Spam-Level: X-Archive-Number: 200508/21 X-Sequence-Number: 3233 ------=_Part_8920_26248182.1124339844595 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline On 8/14/05, Hui Chen wrote: >=20 > Hello, everyone, >=20 > Can anyone help me? I am quite frustrating now. I have been trying to > connect PostgreSQL server through TCP/IP connection using PHP. I was > not successful. Could please read the following and give me some > hints. Thanks a million. >=20 > OS: Fedora Core 4 ("uname -s -r" yields "Linux 2.6.12-1.1398_FC4smp") > PostgreSQL: version 8.0.3 > PHP: version 5.0.4 >=20 > In postgresql.conf, these three lines were inserted, > listen_addresses =3D '*' > port =3D 5432 > max_connections =3D 100 >=20 > The following lines were inserted to pg_hba.conf: > local all all password > host all all 127.0.0.1/32 password > host all all 192.168.0.0/1 password >=20 > restart posgresql by > /sbin/service postgresql restart > The server was restarted OK. >=20 > The PHP script used to connect database is as follows, > $conn =3D pg_connect("host=3Dlocalhost port=3D5432 dbname=3Dfoodb user=3D= foo > password=3Dfoo") or die ("Can not connect to postgres"); > $result=3Dpg_exec("SELECT * FROM footbl"); > $fetch =3D pg_fetch_row($result); > print ""; > print $fetch[0]; > print ""; >=20 > pg_close($conn); // Close this connection > ?> >=20 > Assume this PHP script is named as "connectdb.php", then on > commandline, when I run the following, > php connectedb.php > I see correct results, e.g., > foo >=20 > On commandline again, I used the following to connect database, > psql -d foodb -h localhost -p 5432 -U foo > Password: ************ Whether the password you typed here is "foo"? Welcome to psql 8.0.3, the PostgreSQL interactive terminal. >=20 > Type: \copyright for distribution terms > \h for help with SQL commands > \? for help with psql commands > \g or terminate with semicolon to execute query > \q to quit >=20 > foodb=3D> >=20 > It is OK. Then I disabled "iptables" temporarily for testing purpose by > /sbin/service iptables stop > Flushing firewall rules: [ OK ] > Setting chains to policy ACCEPT: filter [ OK ] > Unloading iptables modules: [ OK ] >=20 > On localhost, I tried this command, > telnet localhost 5432 > after hit "enters", telnet exited. I checked postgresql_%S.log and see > "LOG: invalid length of startup packet" > which means postgresql server indeed saw the telnet connection. >=20 > I tried this on any of my other machines in the LAN, I observed the same= =20 > thing. >=20 > In summary, it seemed the postgresql allowed TCP/IP connection, and > worked well. However, when I ran the PHP script through web browser, I > did not get connection. Instead, in Apache web server's error_log, I > see > [client 192.168.1.10 ] PHP Warning: pg_connect() [ href=3D'function.pg-connect'>function.pg-connect]: Unable to connect > to PostgreSQL server: could not connect to server: Permission > denied\n\tIs the server running on host "localhost" and > accepting\n\tTCP/IP connections on port 5432? in /foo/connectdb.php on > line 2 >=20 > Interestingly, when I checked the log file for postgresql again, it > did not have anything for this connection failure. It seemed the > connection did not send to the database server at all. However, > 1) I disabled firewall > 2) I can telnet the ports > 3) I can run the script from commandline >=20 > What could go wrong? >=20 > Thanks a lot for your reading this lengthy email. Waiting for your help! >=20 > Gray >=20 > ---------------------------(end of broadcast)--------------------------- > TIP 4: Have you searched our list archives? >=20 > http://archives.postgresql.org >=20 --=20 with regards, S.Gnanavel Satyam Computer Services Ltd. ------=_Part_8920_26248182.1124339844595 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline

On 8/14/05, Hui Chen <gray.che= nhui@gmail.com> wrote:
Hello, everyone,

Can anyone help me? I am quite frustrating now. I h= ave been trying to
connect PostgreSQL server through TCP/IP connection u= sing PHP. I was
not successful. Could please read the following and give= me some
hints. Thanks a million.

OS: Fedora Core 4 ("uname -s -r&qu= ot; yields "Linux 2.6.12-1.1398_FC4smp")
PostgreSQL: version 8= .0.3
PHP: version 5.0.4

In postgresql.conf, these three lines wer= e inserted,
listen_addresses =3D '*'
port =3D 5432
max_connections =3D 100
The following lines were inserted to pg_hba.conf:
local   all         all            =             &nb= sp;            =   password
host    all     &n= bsp;   all         127.0.0.1/32    &nb= sp;       password
host  &n= bsp; all         all         192.168.0.0/1    &= nbsp;     password

restart posgresql by
= /sbin/service postgresql restart
The server was restarted OK.

The= PHP script used to connect database is  as follows,
<?php
  $conn =3D pg_connect("host=3Dlocalhost por= t=3D5432 dbname=3Dfoodb user=3Dfoo
password=3Dfoo") or die ("C= an not connect to postgres");
   $result=3Dpg_exec("= SELECT * FROM footbl");
   $fetch =3D pg_fetch_row($result);
   print "= <html><body>";
   print $fetch[0];
 &= nbsp; print "<body></html>";

   pg_c= lose($conn); // Close this connection
?>

Assume this PHP script is named as "connectdb.php", then oncommandline, when I run the following,
     &= nbsp;           &nbs= p;    php connectedb.php
I see correct results, e.g.,
<html><body>f= oo<body></html>

On commandline again, I used the followi= ng to connect database,
psql -d foodb -h localhost -p 5432 -U foo
Password: ************
Whether the password you typed here= is "foo"?

Welcome= to psql 8.0.3, the PostgreSQL interactive terminal.

Type: &nbs= p;\copyright for distribution terms
       \h for help with SQL commands
&= nbsp;      \? for help with psql commands
 = ;      \g or terminate with semicolon to execute q= uery
       \q to quit

foodb=3D>=

It is OK. Then I disabled "iptables" temporarily for test= ing purpose by
/sbin/service iptables stop
Flushing firewall rules:           &nb= sp;            =            [  OK  ]
Setting chains to policy ACCEPT: filter           &nb= sp;        [  OK &nb= sp;]
Unloading iptables modules:           &= nbsp;           &nbs= p;        [  OK &nbs= p;]

On localhost, I tried this command,
telnet localhost 5432
= after hit "enters", telnet exited. I checked postgresql_%S.log an= d see
"LOG:  invalid length of startup packet"
which means postgresql server indeed saw the telnet connection.

= I tried this on any of my other machines in the LAN, I observed the same th= ing.

In summary, it seemed the postgresql allowed TCP/IP connection,= and
worked well. However, when I ran the PHP script through web browser, I<= br>did not get connection. Instead, in Apache web server's error_log, I
= see
[client 192.168.1.10] PHP Warnin= g:  pg_connect() [<a
href=3D'function.pg-connect'>function.pg-connect</a>]: Unable = to connect
to PostgreSQL server: could not connect to server: Permission=
denied\n\tIs the server running on host &quot;localhost&quot; a= nd
accepting\n\tTCP/IP connections on port 5432? in /foo/connectdb.php on<= br>line 2

Interestingly, when I checked the log file for postgresql = again, it
did not have anything for this connection failure. It seemed t= he
connection did not send to the database server at all. However,
1) I= disabled firewall
2) I can telnet the ports
3) I can run the script = from commandline

What could go wrong?

Thanks a lot for your r= eading this lengthy email. Waiting for your help!

Gray

---------------------------(end of broadcast)----------= -----------------
TIP 4: Have you searched our list archives?

&nb= sp;            =   http://archives.postgresq= l.org



--
with regards,S.Gnanavel
Satyam Computer Services Ltd. ------=_Part_8920_26248182.1124339844595-- From gray.chenhui@gmail.com Thu Aug 18 20:39:50 2005 X-Original-To: pgsql-php-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id A9C965295C for ; Thu, 18 Aug 2005 17:39:50 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 43586-05 for ; Thu, 18 Aug 2005 20:39:45 +0000 (GMT) Received: from wproxy.gmail.com (wproxy.gmail.com [64.233.184.194]) by svr1.postgresql.org (Postfix) with ESMTP id D51FE528D4 for ; Thu, 18 Aug 2005 17:39:44 -0300 (ADT) Received: by wproxy.gmail.com with SMTP id i22so407193wra for ; Thu, 18 Aug 2005 13:39:46 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=S4pmP7RJDph5J6EuhJuMBWD8KYQKtJzSysJhiYHCF9HADUwpkgvvviAHvcsC6+JG0XDA5Lt/rakkbkA+4aAzgyyiWfUYbY8cKT5RLKgg5bjZ1+QRe5QB6NrZ/B33YN29mgilK/ic3zt3Gt9uvFl6rm+OZxTfGv+o0j5sIElHicQ= Received: by 10.54.22.39 with SMTP id 39mr1414512wrv; Thu, 18 Aug 2005 13:39:46 -0700 (PDT) Received: by 10.54.98.9 with HTTP; Thu, 18 Aug 2005 13:39:45 -0700 (PDT) Message-ID: <923c3c14050818133930da1cf0@mail.gmail.com> Date: Thu, 18 Aug 2005 15:39:46 -0500 From: Hui Chen To: Gnanavel S Subject: Re: Problem about connecting PostgreSQL through TCP/IP Cc: pgsql-php@postgresql.org In-Reply-To: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline References: <923c3c1405081410326a1c2880@mail.gmail.com> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.058 required=5 tests=[AWL=0.034, RCVD_BY_IP=0.024] X-Spam-Level: X-Archive-Number: 200508/22 X-Sequence-Number: 3234 Thanks a lot! If I typed the password wrong, I should be able to see a corresponding entry in the log file. The entry should look like "FATAL: password authentication failed for user foo". However, I did not see any entry corresponding to the failed connection at all. Therefore, I ruled out the possibility that the wrong password was the reason. Gray On 8/17/05, Gnanavel S wrote: >=20 >=20 >=20 > On 8/14/05, Hui Chen wrote: > > Hello, everyone, > >=20 > > Can anyone help me? I am quite frustrating now. I have been trying to > > connect PostgreSQL server through TCP/IP connection using PHP. I was > > not successful. Could please read the following and give me some=20 > > hints. Thanks a million. > >=20 > > OS: Fedora Core 4 ("uname -s -r" yields "Linux 2.6.12-1.1398_FC4smp") > > PostgreSQL: version 8.0.3 > > PHP: version 5.0.4 > >=20 > > In postgresql.conf, these three lines were inserted,=20 > > listen_addresses =3D '*' > > port =3D 5432 > > max_connections =3D 100 > >=20 > > The following lines were inserted to pg_hba.conf: > > local all all =20 > password > > host all all 127.0.0.1/32 password > > host all all 192.168.0.0/1 password > >=20 > > restart posgresql by > > /sbin/service postgresql restart > > The server was restarted OK. > >=20 > > The PHP script used to connect database is as follows,=20 > > > $conn =3D pg_connect("host=3Dlocalhost port=3D5432 dbname=3Dfoodb use= r=3Dfoo > > password=3Dfoo") or die ("Can not connect to postgres"); > > $result=3Dpg_exec("SELECT * FROM footbl"); > > $fetch =3D pg_fetch_row($result); > > print ""; > > print $fetch[0]; > > print ""; > >=20 > > pg_close($conn); // Close this connection > > ?> > >=20 > > Assume this PHP script is named as "connectdb.php", then on > > commandline, when I run the following, > > php connectedb.php > > I see correct results, e.g., > > foo > >=20 > > On commandline again, I used the following to connect database, > > psql -d foodb -h localhost -p 5432 -U foo > > Password: ************ > Whether the password you typed here is "foo"? > =20 > >=20 > > Welcome to psql 8.0.3, the PostgreSQL interactive terminal. > >=20 > > Type: \copyright for distribution terms=20 > > \h for help with SQL commands > > \? for help with psql commands > > \g or terminate with semicolon to execute query > > \q to quit > >=20 > > foodb=3D> > >=20 > > It is OK. Then I disabled "iptables" temporarily for testing purpose by= =20 > > /sbin/service iptables stop > > Flushing firewall rules: =20 > [ OK ] > > Setting chains to policy ACCEPT: filter [ > OK ] > > Unloading iptables modules: =20 > [ OK ] > >=20 > > On localhost, I tried this command, > > telnet localhost 5432 > > after hit "enters", telnet exited. I checked postgresql_%S.log and see > > "LOG: invalid length of startup packet"=20 > > which means postgresql server indeed saw the telnet connection. > >=20 > > I tried this on any of my other machines in the LAN, I observed the sam= e > thing. > >=20 > > In summary, it seemed the postgresql allowed TCP/IP connection, and=20 > > worked well. However, when I ran the PHP script through web browser, I > > did not get connection. Instead, in Apache web server's error_log, I > > see > > [client 192.168.1.10] PHP Warning: pg_connect() [ > href=3D'function.pg-connect'>function.pg-connect]: Unable to connec= t > > to PostgreSQL server: could not connect to server: Permission > > denied\n\tIs the server running on host "localhost" and=20 > > accepting\n\tTCP/IP connections on port 5432? in /foo/connectdb.php on > > line 2 > >=20 > > Interestingly, when I checked the log file for postgresql again, it > > did not have anything for this connection failure. It seemed the=20 > > connection did not send to the database server at all. However, > > 1) I disabled firewall > > 2) I can telnet the ports > > 3) I can run the script from commandline > >=20 > > What could go wrong? > >=20 > > Thanks a lot for your reading this lengthy email. Waiting for your help= !=20 > >=20 > > Gray > >=20 > > ---------------------------(end of > broadcast)--------------------------- > > TIP 4: Have you searched our list archives? > >=20 > > http://archives.postgresql.org=20 > >=20 >=20 >=20 >=20 > --=20 > with regards, > S.Gnanavel > Satyam Computer Services Ltd.