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 >