Please take our Survey
logo       

Choosing A Webhost:
A web hosting service is a type of Internet hosting service that allows individuals and organizations to provide their own website accessible via the World Wide Web. Web hosts are companies that provide space on a server they own for use by their clients as well as providing Internet connectivity, typically in a data center. Web hosts can also provide data center space and connectivity to the Internet for servers they do not own to be located in their data center, called colocation. more...

Re: Problem about connecting PostgreSQL through TCP/IP: msg#00001

Subject: Re: Problem about connecting PostgreSQL through TCP/IP
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 <gray.chenhui@xxxxxxxxx> 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,
> <?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
> 


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

---------------------------(end of broadcast)---------------------------
TIP 3: Have you checked our extensive FAQ?

               http://www.postgresql.org/docs/faq



<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

Recently Viewed:
user-groups.jax...    php.zend.framew...    os.solaris.open...    web.quixote.use...    java.openjdk.ho...    ietf.secmech/20...    gnu.glpk/2004-0...    recreation.cars...    network.smokepi...    linux.drivers.i...    cms.opencms.dev...    fonts.gfontview...    text.xml.soap.u...    voip.nist-sip/2...    debian.ports.hp...    xfree86.interna...    science.biology...    qnx.openqnx.dev...    mail.sylpheed.c...    busybox/bios/20...    emulators.kvm.s...    hardware.openco...    apple.fink.begi...    kde.german/2006...   
Home | advertise | OSDir is an inevitable website. super tiny logo

Free Magazines

Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe

Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe

The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business.
subscribe

Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe

Total Telecom Total Telecom is "The Economist of the communications industry".
subscribe

Navigation