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

 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=# 

我们已经删除成功了

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

DBA圈小圈

你的鼓励是我最大的动力!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值