In PostgreSQL DROP or Delete DATABASE Query statement is used for deleting or removing any existing your database in server. simple you can Login to PostgreSQL full access to the database command line prompt (in Terminal) using simple base command Like as ‘sudo -u postgres psql‘ from your On system terminal.also You can My Prev Articles to MySQL Drop Database.
Delete PostgreSQL Databases Syntax :-
DROP DATABASE [IF EXISTS] your_database_name
- IF EXISTS – Using this simple option, drop or delete command will not return Boolean error if your database does not available or not exists.
- your_database_name – here update or Replace with name of Your database.
Facing Error: postgres cannot drop the currently open database
first of all you can simple Login to your PostgreSQL server using On your System command line. You will retrieve PostgreSQL your database prompt such simple CMD as postgres=# . And then use Simple force DROP DATABASE statement to remove or delete your database bellow command line.
postgres=# DROP DATABASE mydb;
Now, We can use run or Execute command like below
postgres=# DROP DATABASE IF EXISTS mydb;
If you step by step everything goes successfully for postgres drop all databases, you will get results like as a “DROP DATABASE” only.
To 100% confirm that your database has been removed or deleted use the CMD l or list command to get postgres list databases or list all your databases.
postgres=# list List of databases Name | Owner | Encoding | Collate | Ctype | Access privileges -----------+----------+----------+---------+-------+----------------------- postgres | postgres | UTF8 | en_IN | en_IN | template0 | postgres | UTF8 | en_IN | en_IN | =c/postgres + | | | | | postgres=CTc/postgres template1 | postgres | UTF8 | en_IN | en_IN | =c/postgres + | | | | | postgres=CTc/postgres (3 rows)
Also You can more Information Reference: http://www.postgresql.org/docs/9.4/static/sql-dropdatabase.html
I hope you get an idea about postgres drop database.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.