[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=#
我们已经删除成功了