I am using Postgres 9.1.5. The JDBC works fine on the very first instance but it starts refusing connection when I try to do it again. For example, I logged in to my web-application using JDBC, works fine. But then, I try to use the connection to fetch some other data, its raises an exception: Connection refused. I am sure that there is nothing wrong with my code because the login JDBC, that worked fine last time also raises an exception: Connection Refused.
It works again after I restart the postgres windows service. Then,login JDBC, some data gets fetched and then connection refused. I have tried reinstallation. Is there something wrong with my laptop?
Also, PGAdmin, suffers from the same problem. It would run some queries and then starts showing the error message: Postgres service has stopped. Is there anything I can do? Please advice. Also, if there is any extra information required, please let me know.
Hard to guess, looks like it starts up properly but gets into problems later on. Your first stop in these cases should always be the logfile. A quick check could be to verify max_connections
in the configuration file (doc here), it might be preset at a ridiculously low value. If in pgAdminIII you click on the server node, you can see all open connections under the "statistics" tab as well, maybe there's some issue with a process that eats up all available connections.
Another way of figuring out what happens would be to start the postgres server interactively (ie, have it output all its messages in the window you started it in) as explained in the official documentation.
Also, if your server runs on Linux, ps can help you, postgres connections are managed by individual processes, ie they appear individually in ps:
ps ax | grep postgres:
....
20528 ? Ss 0:00 postgres: username dbname clienraddress(48679) idle