[Solved] PostgreSQL ERROR: There is 1 other session using the database.
- Last Updated On: August 25, 2022
- By: Scriptcrunch Editorial
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;
Scriptcrunch Editorial
Other Interesting Blogs
Linux Foundation Coupon for March 2024
Hi Techies, I wanted to let you know about a pretty sweet deal with the Linux Foundation Coupon that is running now.
[25% OFF] Linux Foundation LFCA, LFCS & LFCT Exam Voucher Codes
Linux Foundation has announced up to a $284 discount on its Linux certification programs Linux Foundation Certified IT Associate (LFCA) and Linux
[Solved] couldn’t get current server API group list: Get “http://localhost:8080/api?timeout connect: connection refused
Issue: When trying to access the kubernetes cluster using kubectl you might get the couldn’t get current server API – connection refuse
1 thought on “[Solved] PostgreSQL ERROR: There is 1 other session using the database.”
thank you so much for this, been struggling to delete a database that was being used even if I disconnected from it.