PostgreSQL can delete a database in the following three ways:
1、使用 DROP DATABASE SQL 语句来删除。
2、使用 dropdb 命令来删除。
3、使用 pgAdmin 工具。
注意: Delete the database with caution. Once deleted, all information will disappear. DROP DATABASE deletes the system directory entries for the database and deletes the file directory that contains the data. DROP DATABASE can only be executed by a Super Admin or database owner. The DROP DATABASE command needs to be executed in the PostgreSQL command window and the syntax format is as follows: 参数说明: IF EXISTS Issue a prompt message instead of an error message if the database does not exist name The name of the database to delete For example, let’s delete a database for runoobdb: Dropdb is the wrapper for DROP DATABASE. Dropdb is used to delete the PostgreSQL database. The dropdb command can only be executed by a super administrator or database owner. The syntax format of the dropdb command is as follows: 参数说明: dbname The name of the database to delete options The parameter is optional, which can be the following values: Serial number Option & description 1 -e Displays the commands generated by dropdb and sends them to the database server. 2 -I Issue a validation prompt before doing the deletion. 3 -V Print the dropdb version and exit. 4 – if-exists Issue a prompt message instead of an error message if the database does not exist. 5 – help Displays help information about the dropdb command. 6 -h host Specifies the hostname on which the server is running. 7 -p port Specify the port on which the server listens, or the socket file. 8 -U username The user name to connect to the database. 9 -w Ignore entering a password when connecting. 10 -W A password is required when connecting. 11 – maintenance-db=dbname Specify the database to which you are connected when you delete the database, default to postgres, and use template1 if it does not exist. Next we open a command window, go to the PostgreSQL installation directory, and go to the bin directory, the dropdb name is located in PostgreSQL安装目录/bin Under, execute the command to delete the database: In the above command, we used the superuser postgres to log in to the PostgreSQL database with host address localhost and port number 5432 and delete the runoobdb database. The pgAdmin tool provides complete functionality for manipulating the database: 5.9.1. DROP DATABASE deletes the database ¶
DROP DATABASE [ IF EXISTS ] name
postgres=# DROP DATABASE runoobdb;
5.9.2. Dropdb command to delete database ¶
dropdb [connection-option...] [option...] dbname
$ cd /Library/PostgreSQL/11/bin/
$ dropdb -h localhost -p 5432 -U postgres runoobdb
password ******
5.9.3. The pgAdmin tool deletes the database ¶
