[Solved] PostgreSQL ERROR: There is 1 other session using the database.
In PostgreSQL, if you have active connection to the database and if you try to DROP the database, you will get the following error.
ERROR: database "catalog" is being accessed by other users DETAIL: There is 1 other session using the database.
To rectify this error and to drop the database, follow the steps given below.
Step 1: First, you need to close all the active connections from programs or tools like PGAdmin. Quit all the applications connecting to the database.
Step 2: Execute the following query from on PostgreSQL to terminate all active connections. Replace
catalog with your database name.
SELECT pg_terminate_backend(pg_stat_activity.pid) FROM pg_stat_activity WHERE pg_stat_activity.datname = 'catalog';
You will get the following output.
pg_terminate_backend ---------------------- t (1 row)
Step 3: Delete the database using the DROP command.
DROP DATABASE dvdrental;