微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

postgresql删除数据库口令 Linux

Postgresql删除数据库

来源:网络整理    由 易百 更新版本    浏览:人次

       

在本章中,我们将讨论如何删除在Postgresql数据库。有两个选择方法删除数据库

 

  1. 使用DROP DATABASE从 sql命令.

     

  2. 使用dropdb 一个命令行可执行文件.

使用此操作之前要小心,因为会导致失去所有存储在数据库中的所有信息。

使用 DROP DATABASE

此命令可删除数据库。它消除了目录数据库删除包含数据的目录条目。它只能由数据库所有者执行。此命令不能执行,而或其他人连接到目标数据库。 (连接到Postgres或任何其他数据库发出此命令。)

语法

DROP DATABASE 的语法如下:

 

DROP DATABASE [ IF EXISTS ] name  

参数

下表列出了参数及其说明.

参数描述
IF EXISTS Do not throw an error if the database does not exist. A notice is issued in this case.
name The name of the database to remove.
我们不能删除一个数据库有任何打开的连接,包括我们自己的的连接frompsql或pgAdmin III 。如果我们要删除当前连接到的数据库,必须切换到另一个数据库或template1。因此,它可能是更方便使用程序DROPDB来代替,这是一个包装这个命令

实例

下面是一个简单的例子,这将删除Postgresql模式testdb :

 

postgres=# DROP DATABASE testdb;
postgres-#  www.yiibai.com 

使用DROPDB命令

Postgresql的命令行可执行DROPDB围绕sql命令DROP DATABASE命令行包装。通过此实用工具删除数据库和通过其他方法访问服务器之间有没有实际的区别。 DROPDB破坏现有Postgresql数据库。执行此命令的用户必须是数据库超级用户数据库所有者。

语法

createdb 的语法如下所示:

 

dropdb  [option...] dbname yiibai.com 

参数

下表列出了参数,对它们的描述。

 

参数描述
dbname The name of a database to be deleted.
option command-line arguments which dropdb accepts.

选项

下表列出了命令行参数DROPDB接收:

选项描述
-e Shows the commands being sent to the server.
-i Issues a verification prompt before doing anything destructive.
-V Print the dropdb version and exit.
--if-exists Do not throw an error if the database does not exist. A notice is issued in this case.
--help Show help about dropdb command line arguments, and exit.
-h host Specifies the host name of the machine on which the server is running.
-p port Specifies the TCP port or the local Unix domain socket file extension on which the server is listening for connections.
-U username User name to connect as.
-w Never issue a password prompt.
-W Force dropdb to prompt for a password before connecting to a database.
--maintenance-db=dbname Specifies the name of the database to connect to in order to drop the target database.

实例

下面的例子演示从OS命令提示符,删除数据库

 

dropdb -h localhost -p 5432 -U postgress testdb
Password for user postgress: ****
  

上面的命令删除数据库TESTDB。在这里使用postgres(template1 pg_roles下找到)用户名删除数据库

 

 

 

 

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐