首页 > 数据库技术 > 详细

postgresql删除数据库口令 Linux

时间:2019-05-07 14:20:01      阅读:386      评论:0      收藏:0      [点我收藏+]

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下找到)用户名,删除数据库。

 

 

 

技术分享图片

 

postgresql删除数据库口令 Linux

原文:https://www.cnblogs.com/louissica/p/10824938.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!