Sign up ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free.

Folowing this question by CountZero, apparently i'm facing same problem here. When my site trying to open connection with the database, SOMETIME (Not Always) i get following error:

Warning: pg_connect() [function.pg-connect]: Unable to connect to PostgreSQL server: server closed the connection unexpectedly This probably means the server terminated abnormally before or while processing the request. in E:\htdocs\trial_pg\client_1a.php on line 3

Here is my client1a.php script:

<?php
  $connString = 'dbname=movies user=xxxxxx password=xxxxxx';
  $connHandler = pg_connect($connString);
  echo 'Connected to '.pg_dbname($connHandler);
?>

This happens often, especially when I refresh the page (F5) repeatedly to test the connection. I'm new with postgresql, and this is the developing environment of my site:

OS: Windows 7 Professional

Web Server: Apache/2.2.14 (Win32) DAV/2 mod_ssl/2.2.14 OpenSSL/0.9.8l mod_autoindex_color mod_apreq2-20090110/2.7.1 mod_perl/2.0.4 Perl/v5.10.1

PHP: 5.3.1

PostgreSQL: 8.4.3

Are there any configuration i miss? Any hints?

Thanks!

share|improve this question
    
+1 for a very neatly presented question –  user201788 Sep 9 '10 at 15:27
    
The script name it is looking for has an '_' (underscore). client_1a.php –  user201788 Sep 9 '10 at 15:28
    
Could it be that php doesn't immediately close the connection on script end? I see no explicit pg_close() in your code. Look at the postgres logs for any possible details of this. –  Fanis Sep 9 '10 at 17:14
1  
PHP should run pg_close automatically at script end. How many times are you trying to open the connection (per script run)? Once? Twice? More? Look for max_connections here postgresql.org/docs/8.4/static/runtime-config-connection.html then check your config, if you're at default of 100 that should be plenty, and sounds like it's something with the server itself. If you're opening 20+ connections on each script run (instead of reusing them) Then that could be the problem. –  Viper_Sb Sep 9 '10 at 18:14
    
@AJ: Hmm, it should be client_1a.php. Thanks for the correction :) –  GuyFreakz Sep 12 '10 at 13:22

2 Answers 2

Okay, so here is the answer of my question ;)

JUST RESTART THE POSTGRESQL SERVICE :)

I hope if everyone encountered the same problem, you know what you should do to solve it :D

share|improve this answer

Sometimes this kind of problems are caused by over-enthusiastic antivirus software, if it monitors TCP connections. Do you have any antivirus running there?

share|improve this answer
    
I don't think so. I've been using Eset Smart Security for over 2 yrs and it's working fine even for Oracle. I think the problems is the postgresql itself ;) –  GuyFreakz Sep 12 '10 at 13:36

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.