本文主要是介绍【PostgreSQL】从零开始:(十一)PostgreSQL-Dropdb命令删除数据库,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
dropdb命令删除数据库
命令
[postgres@postgre-sql bin]$ dropdb --help
dropdb removes a PostgreSQL database.Usage:dropdb [OPTION]... DBNAMEOptions:-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 exitConnection 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 databaseReport 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=# \lList of databasesName | 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/postgrestemplate1 | 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=# \lList of databasesName | 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/postgrestemplate1 | postgres | UTF8 | libc | zh_CN.UTF-8 | zh_CN.UTF-8 | | | =c/postgres +| | | | | | | | postgres=CTc/postgres
(6 rows)postgres=#
我们已经删除成功了
这篇关于【PostgreSQL】从零开始:(十一)PostgreSQL-Dropdb命令删除数据库的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!