PSQL command to help with session termination
I find the following PSQL command quite useful for terminating session for a specific database in Postgres.
Let say you want to alter the database name but there's tons of connections.
ALTER DATABASE "keycloak" RENAME TO "keycloakcurrent"
So first you see which process is active in the database
SELECT * FROM pg_stat_activity where datname='keycloak'
Then you issue multiple command to terminate the session.
SELECT pg_terminate_backend(9026)
If you bump into an error whereby you need to be a member of pg_signal_backend, then you can use this command to grant yourself a member to that role called pg_signal_backend.
GRANT pg_signal_backend TO psqladmin
Comments