linux停止postgresql数据库,postgresql删除数据库口令 Linux

PostgreSQL删除数据库

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

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

使用DROP DATABASE从 SQL命令.

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

0dde82ceb707a1a2fa97757b278d8275.png

标签:postgresql,name,删除,database,数据库,DROP,口令,Linux,dropdb

来源: https://www.cnblogs.com/louissica/p/10824938.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值