Postgres Database Automatic Reconnect

556 views
Skip to first unread message

Ryan Quinn

unread,
Apr 22, 2021, 7:36:26 PM4/22/21
to golang-nuts
Hi!

I have a little, low-traffic web app which connects to postgres 10 using the pgx library (https://pkg.go.dev/github.com/jackc/pgx), and the database connection gets closed causing 500 server error to be returned. I'm pretty sure this is related to the db server being rebooted after updates and restarting the application fixes the problem.

I found the blog post below about how to process reconnects, and I was wondering how other people handle the db auto-reconnect scenario.

Synopsis: The author attaches functions to the db.Conn variable, and one of the functions has logic to check if the connection is valid then reconnect if the connection is invalid.


Ryan
Reply all
Reply to author
Forward
0 new messages