We are using https://github.com/go-gorm/gorm/ ORM in our backend and scripts to connect to our PostgreSQL database.
Sometimes while a script is in progress, we kill the job manually by pressing Ctrl + C on local or killing the pod / process in production. We do have a defer DB.Close() in all scripts and I also added handling SIGINT / SIGTERM signals to do DB.Close() on kill.
Issue is even after closing the connection, any existing queries which were already running do not get killed and kept on eating DB resources. Is there a way to kill any queries started by this connection pool before exiting either directly from gorm or through some other hack.
Thought of using pg_backend_pid() and killing queries using pg_stat_activity, but pid we get while running new pg_backend_pid() will not be same as the running ones.
Version: jinzhu/gorm v1.9.2
context.Contextis for. Have you read about that? - Flimzydb.WithContextmethod mentioned on gorm doc is not available it seems. We are currently at v1 jinzhu/gorm v1.9.2. If there is any example which I can look at, that would be really helpful. Will also read up on Context meantime. - pratpor