How to fix Database dropped in PostgreSQL

PostgreSQLINTERMEDIATEHIGHUpdated Dec 28, 2025ยท 212 views

When dropping a PostgreSQL database fails or was completed unexpectedly, it usually means the database is still in use or recovery incomplete. Learn how to safely drop databases and recover from failed drop operations.

Quick fix

Fixes Database dropped

SELECT * FROM pg_stat_activity WHERE datname = 'your_database';
  1. Verify the database exists and check active connections
  2. Terminate all active connections to the database
  3. Ensure you are not connected to the target database
  4. Drop the database using the appropriate method
postgresql โ€” error
SELECT * FROM pg_stat_activity WHERE datname = 'your_database';
Database dropped

What this error means

The "database dropped" error occurs when PostgreSQL encounters issues while executing a DROP DATABASE command or when a database has been partially dropped during recovery. This can happen due to active connections, permission issues, transaction states, or incomplete recovery from a previous operation. PostgreSQL prevents dropping databases that are currently connected to, ensuring data consistency and preventing accidental data loss.

Typical symptoms

  • DROP DATABASE command fails with "cannot drop the currently open database"
  • Error: "database is being accessed by other users"
  • FATAL error: "cannot connect to invalid database" after a failed drop
  • DROP DATABASE command appears to hang or take longer than expected
  • Database entry remains in pg_database catalog after recovery

Common causes

  1. Active connections to the target database exist
  2. Executed DROP DATABASE while connected to the database being dropped
  3. Transaction block contains DROP DATABASE command
  4. Recovery process was interrupted while dropping a database
  5. Logical replication slots or subscriptions are active on the database
  6. Prepared transactions exist in the database

How to fix "Database dropped"

1Verify the database exists and check active connections

Connect to the postgres or template1 database and check if there are active connections to your target database:

sql
SELECT * FROM pg_stat_activity WHERE datname = 'your_database';

This shows all active sessions connected to the database. If the output is empty, no sessions are connected.

2Terminate all active connections to the database

If active connections exist, terminate them using:

sql
SELECT pg_terminate_backend(pg_stat_activity.pid)
FROM pg_stat_activity
WHERE pg_stat_activity.datname = 'your_database'
AND pid <> pg_backend_pid();

This safely terminates all connections except your current session.

3Ensure you are not connected to the target database

Connect to a different database before dropping. Use the postgres or template1 database:

bash
psql -U postgres -d postgres

Then verify your connection:

sql
SELECT current_database();
4Drop the database using the appropriate method

For PostgreSQL 13 and later with active connections, use the FORCE option:

sql
DROP DATABASE your_database WITH (FORCE);

For earlier versions or to prevent errors if the database does not exist:

sql
DROP DATABASE IF EXISTS your_database;

Or the standard command:

sql
DROP DATABASE your_database;
5Verify the database was successfully dropped

List all databases to confirm the target database no longer exists:

sql
\l

Or use the query:

sql
SELECT datname FROM pg_database WHERE datname = 'your_database';

An empty result confirms the database was successfully dropped.

Advanced notes

For PostgreSQL versions 13 and earlier without FORCE support, manually terminate connections and close all client applications before dropping. If a database is stuck in an invalid state after failed recovery (showing "cannot connect to invalid database"), connect as superuser to the postgres database and use DROP DATABASE to clean up the invalid entry in pg_database catalog. Logical replication slots or subscriptions can prevent database drops even with FORCE; remove these first using DROP SUBSCRIPTION or DROP REPLICATION SLOT. For point-in-time recovery scenarios, ensure WAL archiving and recovery configuration are complete before attempting database drops. The dropdb utility is a convenient wrapper: dropdb --force your_database.

Frequently asked questions

What does "Database dropped" mean?
The "database dropped" error occurs when PostgreSQL encounters issues while executing a DROP DATABASE command or when a database has been partially dropped during recovery. This can happen due to active connections, permission issues, transaction states, or incomplete recovery from a previous operation. PostgreSQL prevents dropping databases that are currently connected to, ensuring data consistency and preventing accidental data loss.
How do I fix "Database dropped"?
When dropping a PostgreSQL database fails or was completed unexpectedly, it usually means the database is still in use or recovery incomplete. Learn how to safely drop databases and recover from failed drop operations.
What causes "Database dropped"?
Active connections to the target database exist Executed DROP DATABASE while connected to the database being dropped Transaction block contains DROP DATABASE command
Is the "Database dropped" error serious?
Yes. This is a high-severity error that usually blocks work until it is fixed, but the steps above resolve it.

Official resources & further reading