5.9. PostgreSQL deletes the database

发布时间 : 2025-10-25 13:32:27 UTC      

Page Views: 9 views

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.

5.9.1. DROP DATABASE deletes the database

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:

DROP DATABASE [ IF EXISTS ] name 

参数说明:

  • 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:

postgres=# DROP DATABASE runoobdb; 

5.9.2. Dropdb command to delete database

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:

dropdb [connection-option...] [option...] dbname 

参数说明:

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:

$ cd /Library/PostgreSQL/11/bin/ $ dropdb -h localhost -p 5432 -U postgres runoobdb password ****** 

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.

5.9.3. The pgAdmin tool deletes the database

The pgAdmin tool provides complete functionality for manipulating the database:

Image0

《地理信息系统原理、技术与方法》  97

最近几年来,地理信息系统无论是在理论上还是应用上都处在一个飞速发展的阶段。 GIS被应用于多个领域的建模和决策支持,如城市管理、区划、环境整治等等,地理信息成为信息时代重要的组成部分之一; “数字地球”概念的提出,更进一步推动了作为其技术支撑的GIS的发展。 与此同时,一些学者致力于相关的理论研究,如空间感知、空间数据误差、空间关系的形式化等等。 这恰好说明了地理信息系统作为应用技术和学科的两个方面,并且这两个方面构成了相互促进的发展过程。