在 openGauss 数据库中,可以通过 drop database 语句删除一个数据库。
但是,删除数据库,当然有一些约束条件。
- 需要以属主身份执行
以其他用户执行,会提示:ERROR: must be owner of database enmotech
postgres=> drop database enmotech;
ERROR: must be owner of database enmotech
postgres-> \q
- 不能删除当前打开的数据库
例如,以属主连接到要删除的数据库,执行删除,收到提示:ERROR: cannot drop the currently open database
[root@ecs-514e-0004 ~]# gsql -d enmotech -U enmotech -W'Enm0t3ch' -h 192.168.1.94 -p 8888
gsql ((openGauss 1.0 build ec0e781b) compiled at 2020-04-27 17:25:57 commit 2144 last mr 131 )
Non-SSL connection (SSL connection is recommended when requiring high-security)
Type "help" for help.
enmotech=> drop database enmotech;
ERROR: cannot drop the currently open database
enmotech-> \q
- 以属主非删除数据库连接
以属主连接,非删除数据库,则可以顺利删除。
[root@ecs-514e-0004 ~]# gsql -d enmotech -U enmotech -W'Enm0t3ch' -h 192.168.1.94 -p 8888
gsql ((openGauss 1.0 build ec0e781b) compiled at 2020-04-27 17:25:57 commit 2144 last mr 131 )
Non-SSL connection (SSL connection is recommended when requiring high-security)
Type "help" for help.
enmotech=> drop database enmotech;
ERROR: cannot drop the currently open database
enmotech=> \c omm
Password for user enmotech:
Non-SSL connection (SSL connection is recommended when requiring high-security)
You are now connected to database "omm" as user "enmotech".
omm=> drop database enmotech;
DROP DATABASE
但是需要提示,任何时候,删除数据库都是高风险,需要慎重的。
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




