We will use the databases created in the PostgreSQL create database tutorial for the demonstration. Third, execute the DROP DATABASE statement: DROP DATABASE Code language: HTML, XML ( xml ) PostgreSQL DROP DATABASE examples Notice that if you use PostgreSQL version 9.1 or earlier, use the procpidcolumn instead of the pidcolumn because PostgreSQL changed procidcolumn to pidcolumn since version 9.2 WHERE pg_stat_activity.datname = '' Code language: SQL (Structured Query Language) ( sql ) Second, terminate the active connections by issuing the following query: SELECT pg_terminate_backend (pid) WHERE datname = '' Code language: SQL (Structured Query Language) ( sql ) To delete the database that has active connections, you can follow these steps:įirst, find the activities associated with the database by querying the pg_stat_activity view: SELECT * 1) Drop a database that has active connections The dropdb program executes the DROP DATABASE statement behind the scenes. PostgreSQL also provides a utility program named dropdbthat allows you to remove a database. In this case, you need to disconnect from the database and connect to another database e.g., postgres to execute the DROP DATABASE statement. In addition, you cannot execute the DROP DATABASE statement if the database still has active connections. Only superusers and the database owner can execute the DROP DATABASE statement. This action cannot be undone so you have to use it with caution. The DROP DATABASE statement deletes catalog entries and data directory permanently. Use IF EXISTS to prevent an error from removing a non-existent database.Specify the name of the database that you want to delete after the DROP DATABASE clause.The following illustrates the syntax of the DROP DATABASE statement: DROP DATABASE database_name Code language: SQL (Structured Query Language) ( sql ) Once a database is no longer needed, you can drop it by using the DROP DATABASE statement. Introduction to PostgreSQL DROP DATABASE statement Summary: in this tutorial, you will learn how to use the PostgreSQL DROP DATABASE statement to drop a database.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |