Reputation: 5403
I have a rails app on heroku that users log in to. I periodically get this exception:
UserSessionsController# (ActiveRecord::StatementInvalid) "PGError: FATAL: terminating connection due to administrator command\nserver closed the connection unexpectedly\n\tThis probably means the server terminated abnormally\n\tbef...
URL
POST http://secure.huckberry.com/user_sessions
What's a likely cause of this? I'd appreciate any help.
Upvotes: 47
Views: 130124
Reputation: 7228
For me this was caused by unattended upgrades as mentioned by this answer https://stackoverflow.com/a/76928063/2828480
But interesting fact is postgres itself wasn't being upgraded but some dependency of postgres that caused the restart.
I did some digging and I stumbled upon this answer https://askubuntu.com/a/1530298
in /etc/needrestart/conf.d
directory create file and name it like postgres-no-restart.conf
and paste this content:
# Disable automatic restart of PostgreSQL services
$nrconf{override_rc} = {
'[email protected]' => 0,
qr/^postgresql[@].*\.service$/ => 0 # This will match all postgresql@ services
};
This should prevent postgres restarting automatically when one of it's dependencies is automatically upgraded by unattended-upgrades
Upvotes: 1
Reputation: 81
The solution that worked for me here was simply to vaccum my bloated tables.
You can also turn autoVaccum off for your db, but i would NOT RECOMMEND this as it can have a massive negative impact on your DB performance.
VACUUM FULL VERBOSE ANALYZE <table_name>;
Upvotes: 0
Reputation: 674
This can also be caused by PostgreSQL receiving an unattended upgrade (/var/log/apt/history.log
on Ubuntu) - in PostgreSQL's logs you will see
2023-08-18 06:29:57 UTC LOG: received fast shutdown request
2023-08-18 06:29:57 UTC LOG: aborting any active transactions
2023-08-18 06:29:57 UTC FATAL: terminating connection due to administrator command
Upvotes: 2
Reputation: 119
This error may also appear, if you run a test suite which utilizes a database connection (PSQL in this case) and the test is still running (asynchronously). A tear down hook may terminate the connection when the test is still running and this ends up in this error message.
Upvotes: 3
Reputation: 783
This probably means that something sent the server process a SIGTERM signal. This could happen is if the postmaster gets a SIGINT from something. However, if you are able to reconnect that's not the case, because the postmaster would disallow new connections.
You're probably having a clash of some kind in your application. Enable query logging and check for something unusual.
Upvotes: 5
Reputation: 349
I had this error happen to me. My Application server had an open connection to the database. In my SSH terminal I added an ipaddress to the ph_hba.conf file and restarted the postgreSQL server.
That is when this error showed up. I refreshed my web page one time and the error was gone.
Upvotes: 3
Reputation: 467
Assuming you saw this recently, this is due to a recent bit of high-priority maintenance work to enable continuous backups on shared databases -- involving a server restart. You shouldn't worry about this error, provided it does not reproduce. I don't think that's very likely, so happy hacking!
Upvotes: 21