55000 Object Not In Prerequisite State
If you are dropping a tablespace and encounter an error message like this, it means that some database objects exist in the tablespace.
mydb=# DROP TABLESPACE dbspace;
ERROR: tablespace "dbspace" is not empty
You can check system catalogs to see what objects are in the tablespace:
SELECT n.nspname AS schema_name,
c.relname AS object_name,
CASE c.relkind
WHEN 'r' THEN 'table'
WHEN 'i' THEN 'index'
WHEN 'u' THEN 'undo'
WHEN 't' THEN 'TOAST table'
WHEN 'm' THEN 'materialized view'
WHEN 'f' THEN 'foreign table'
WHEN 'p' THEN 'partitioned table'
ELSE c.relkind::text
END AS object_type
FROM pg_class c
JOIN pg_namespace n ON n.oid = c.relnamespace
JOIN pg_tablespace t ON c.reltablespace = t.oid
WHERE
t.spcname = 'dbspace';
If you really want to drop the tablespace, you need to drop objects in the tablespace first.
You may encounter an error message like following.
FATAL: database "mydb" is not currently accepting connections
This message is only emitted if the database is not allowed for accepting connections. This is mainly used to protect the template database (eg: template1
) from accidental modification, or for temporary database maintenance tasks. To allow the database mydb
to accept connections:
ALTER DATABASE mydb ALLOW_CONNECTIONS true;