5.9. PostgreSQL deletes the database

发布时间 :2025-10-25 12:30:52 UTC      

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

Principles, Technologies, and Methods of Geographic Information Systems  102

In recent years, Geographic Information Systems (GIS) have undergone rapid development in both theoretical and practical dimensions. GIS has been widely applied for modeling and decision-making support across various fields such as urban management, regional planning, and environmental remediation, establishing geographic information as a vital component of the information era. The introduction of the “Digital Earth” concept has further accelerated the advancement of GIS, which serves as its technical foundation. Concurrently, scholars have been dedicated to theoretical research in areas like spatial cognition, spatial data uncertainty, and the formalization of spatial relationships. This reflects the dual nature of GIS as both an applied technology and an academic discipline, with the two aspects forming a mutually reinforcing cycle of progress.