gorm icon indicating copy to clipboard operation
gorm copied to clipboard

Automatic database reconnect

Open henning opened this issue 3 years ago • 7 comments

Describe the feature

GORM should try to reconnect to a database when connection is lost (e.g. Network error, DB restart)

After the DB restarts, the gorm application usually isnt able to recover and get back to normal operations. That should be solved.

To reproduce the behaviour that I want to avoid - working with Postgres, I get:

  • start your DB
  • run you gorm app
  • use your gorm app
  • shutdown DB
  • try using gorm app
  • see it failing with db connection error: "FATAL: terminating connection due to administrator command (SQLSTATE 57P01)"
  • restart DB
  • Try using App
  • See it still getting the same error

Expecation would be that the application reconnects to the DB and continue to work without a restart.

Motivation

GORM applications without DB connection do not work very well.

Related Issues

Multiple issues have been created with that, but all have been closed, but without mentioning a reason or a workaround:

https://github.com/go-gorm/gorm/issues?q=reconnect

There are also some chat messages about it: https://gitter.im/jinzhu/gorm?at=5a59df94ba39a53f1a0e36f2 - but it's not clear to me why gorm doesn't come out of the box with that reconnect behaviour - are there important downsides to configure it by default to reconnect automatically?

I'd be happy to try find a solution for that thing or add some documentation with a workaround if I get some guidance for more experienced gorm developers about how to do it best... maybe there is a reason why it has not been implemented before, or maybe I am overseeing something that makes it not a useful feature.

henning avatar Aug 12 '22 16:08 henning

This issue has been automatically marked as stale because it has been open 360 days with no activity. Remove stale label or comment or this will be closed in 180 days

github-actions[bot] avatar Aug 08 '23 02:08 github-actions[bot]

I need this feature

sincerefly avatar Aug 23 '23 03:08 sincerefly

any updates?

borzovplus avatar Sep 10 '23 08:09 borzovplus

I just started googling this topic and landed on this stale issue. Any hints to prebuilt solutions would be of much help (if there are any)

flaxinger avatar Oct 11 '23 11:10 flaxinger

I need this feature too.

nk915 avatar Jan 25 '24 02:01 nk915

Is there any solution now?

2015WUJI01 avatar Jun 21 '24 07:06 2015WUJI01