Drop Database in PostgreSQL 13
Warning: The information provided here is based on unsupported development version of PostgreSQL 13.
DROP DATABASE drops a database. It removes the catalog entries for the database and deletes the directory containing the data. It can only be executed by the database owner. It cannot be executed while you are connected to the target database.
Here, from PostgreSQL v13 on wards you have an option to drop database forcefully even if an external session is connected.
It doesn’t terminate if prepared transactions, active logical replication slots or subscriptions are present in the target database.
This will fail if the current user has no permissions to terminate other connections.
To drop a database use “DROP DATABASE” command.
1 2 3 4 5 |
DROP DATABASE [ IF EXISTS ] name [ [ WITH ] ( option [, ...] ) ] where option can be: FORCE |
Example.,
[postgres@testdb ~]$ psql -d p13
psql (13devel)
Type “help” for help.
1 2 3 4 5 6 7 8 9 10 11 |
p13=# \h DROP DATABASE Command: DROP DATABASE Description: remove a database Syntax: DROP DATABASE [ IF EXISTS ] name [ [ WITH ] ( option [, ...] ) ] where option can be: FORCE URL: https://www.postgresql.org/docs/devel/sql-dropdatabase.html |
Let us try that.
[postgres@testdb bin]$ psql
psql (13devel)
Type “help” for help.
To create a database in PostgreSQL 13 we use below command
1 2 3 |
postgres=# create database p13; CREATE DATABASE postgres=# |
To drop a database in PostgreSQL 13 we use below command
Syntax: drop database p13 with (force);
1 2 3 |
postgres=# drop database p13 with (force); DROP DATABASE postgres=# |
Thank you for giving your valuable time to read the above information. I hope the content served your purpose in reaching out to the blog.
Suggestions for improvement of the blog are highly appreciable. Please contact us for any information/suggestions/feedback.
If you want to be updated with all our articles
please follow us on Facebook | Twitter
Please subscribe to our newsletter.