pg.ddx.io  pgsql-php@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Matthew Terenzio <matt@jobsforge.com>
To: Hui Chen <gray.chenhui@gmail.com>
Cc: pgsql-php@postgresql.org
Subject: Re: Problem about connecting PostgreSQL through TCP/IP
Date: Mon, 15 Aug 2005 10:30:12 -0400
Message-ID: <ee2aa556c95d6a67036023dc63cfdba9@jobsforge.com> (raw)
In-Reply-To: <923c3c1405081410326a1c2880@mail.gmail.com>
References: <923c3c1405081410326a1c2880@mail.gmail.com>

>
> 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,
> <?php
>   $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 "<html><body>";
>    print $fetch[0];
>    print "<body></html>";
>
>    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.,
> <html><body>foo<body></html>
>
> 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() [<a
> href='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; 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
>





view thread (14+ messages)  latest in thread

Message-ID: <ee2aa556c95d6a67036023dc63cfdba9@jobsforge.com>
Permalink:  ../ee2aa556c95d6a67036023dc63cfdba9@jobsforge.com/
Also on:    postgresql.org/message-id/ee2aa556c95d6a67036023dc63cfdba9@jobsforge.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-php@postgresql.org
  Cc: matt@jobsforge.com, gray.chenhui@gmail.com
  Subject: Re: Problem about connecting PostgreSQL through TCP/IP
  In-Reply-To: <ee2aa556c95d6a67036023dc63cfdba9@jobsforge.com>
  References: <923c3c1405081410326a1c2880@mail.gmail.com> <ee2aa556c95d6a67036023dc63cfdba9@jobsforge.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox