【PostgreSQL】从零开始:(十一)PostgreSQL-Dropdb命令删除数据库

发布时间:2023年12月18日

?dropdb命令删除数据库

命令

[postgres@postgre-sql bin]$ dropdb --help
dropdb removes a PostgreSQL database.

Usage:
  dropdb [OPTION]... DBNAME

Options:
  -e, --echo                show the commands being sent to the server
  -f, --force               try to terminate other connections before dropping
  -i, --interactive         prompt before deleting anything
  -V, --version             output version information, then exit
  --if-exists               don't report error if database doesn't exist
  -?, --help                show this help, then exit

Connection options:
  -h, --host=HOSTNAME       database server host or socket directory
  -p, --port=PORT           database server port
  -U, --username=USERNAME   user name to connect as
  -w, --no-password         never prompt for password
  -W, --password            force password prompt
  --maintenance-db=DBNAME   alternate maintenance database

Report bugs to <pgsql-bugs@lists.postgresql.org>.
PostgreSQL home page: <https://www.postgresql.org/>
[postgres@postgre-sql bin]$ 

参数

参数说明
-e, --echo显示发送到服务端的命令
-f, --force尝试在删除之前终止其他连接
-i, --interactive在删除任何内容之前提示
-V, --version查看版本信息
--if-exists如果数据库不存在,不要报告错误
-?, --help查看帮助并退出
-h, --host=HOSTNAME指定数据库编码或IP
-p, --port=PORT数据库服务器端口号
-U, --username=USERNAME连接的用户名
-w, --no-password永远不提示输入口令
-W, --password强制提示输入口令
--maintenance-db=DBNAME备用维护数据库

例子

查看数据库列表

postgres=# \l
                                                            List of databases
        Name        |   Owner   | Encoding | Locale Provider |   Collate   |    Ctype    | ICU Locale | ICU Rules |   Access privileges   
--------------------+-----------+----------+-----------------+-------------+-------------+------------+-----------+-----------------------
 ci_database_test01 | postgres  | UTF8     | libc            | zh_CN.UTF-8 | zh_CN.UTF-8 |            |           | 
 ci_database_test02 | postgres  | EUC_TW   | libc            | C           | C           |            |           | 
 ci_database_test03 | circledba | UTF8     | libc            | zh_CN.UTF-8 | zh_CN.UTF-8 |            |           | 
 circledba_test     | postgres  | UTF8     | libc            | zh_CN.UTF-8 | zh_CN.UTF-8 |            |           | 
 postgres           | postgres  | UTF8     | libc            | zh_CN.UTF-8 | zh_CN.UTF-8 |            |           | 
 template0          | postgres  | UTF8     | libc            | zh_CN.UTF-8 | zh_CN.UTF-8 |            |           | =c/postgres          +
                    |           |          |                 |             |             |            |           | postgres=CTc/postgres
 template1          | postgres  | UTF8     | libc            | zh_CN.UTF-8 | zh_CN.UTF-8 |            |           | =c/postgres          +
                    |           |          |                 |             |             |            |           | postgres=CTc/postgres
(7 rows)

postgres=# 

使用dropdb删除ci_database_test02数据库

[postgres@postgre-sql bin]$ ./dropdb -h 127.0.0.1 -p5432 -U postgres ci_database_test02
Password: 
[postgres@postgre-sql bin]$ 

再次查看数据库列表

postgres=# \l
                                                            List of databases
        Name        |   Owner   | Encoding | Locale Provider |   Collate   |    Ctype    | ICU Locale | ICU Rules |   Access privileges   
--------------------+-----------+----------+-----------------+-------------+-------------+------------+-----------+-----------------------
 ci_database_test01 | postgres  | UTF8     | libc            | zh_CN.UTF-8 | zh_CN.UTF-8 |            |           | 
 ci_database_test03 | circledba | UTF8     | libc            | zh_CN.UTF-8 | zh_CN.UTF-8 |            |           | 
 circledba_test     | postgres  | UTF8     | libc            | zh_CN.UTF-8 | zh_CN.UTF-8 |            |           | 
 postgres           | postgres  | UTF8     | libc            | zh_CN.UTF-8 | zh_CN.UTF-8 |            |           | 
 template0          | postgres  | UTF8     | libc            | zh_CN.UTF-8 | zh_CN.UTF-8 |            |           | =c/postgres          +
                    |           |          |                 |             |             |            |           | postgres=CTc/postgres
 template1          | postgres  | UTF8     | libc            | zh_CN.UTF-8 | zh_CN.UTF-8 |            |           | =c/postgres          +
                    |           |          |                 |             |             |            |           | postgres=CTc/postgres
(6 rows)

postgres=# 

我们已经删除成功了

文章来源:https://blog.csdn.net/sinat_36528886/article/details/135042330
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。