I have set up my Rails application as follows:
- Rails: 3.0.5 (under Apache proxy), running on RHEL 5.6
- Postgres: 8.4, running on Windows Server 2008 2 servers are on the same local network.
The problem is that after some downtime, when I make a new request to the Rails application, it causes the following error:
ActiveRecord::StatementInvalid (PGError: server closed the connection unexpectedly This probably means the server terminated abnormally before or while processing the request.
From what I investigated, it seems that database connections are being deleted after some Postgres timeout. During this time, from Rails,
- If I make a request to Rails (1st request), it will display a connection error as above
- If I make another Rails request (second request), Rails seems to connect to Postgres again and function correctly.
This means that I will always experience the first connection error, and then again we will get all the normal work, which is very serious in my case, since I would like to provide an error response for my client.
I looked through the following questions and answers, but they do not seem to be suitable for my case:
Do you have any tips to make my application free of db connection errors? Thanks.
source share