postgresql 无法删除数据库

30byixjq  于 2023-03-17  发布在  PostgreSQL
关注(0)|答案(4)|浏览(344)

我是PostgreSQL的新手,我觉得一个简单的命令DROP DATABASEDROPDB有问题,为什么下面的命令不能删除我的数据库?

postgres=# drop database clientms
postgres-# \l
                                    List of databases
   Name    |    Owner     | Encoding |   Collate   |    Ctype    |   Access privileges   
-----------+--------------+----------+-------------+-------------+-----------------------
 clientms  | clientmsuser | UTF8     | en_GB.UTF-8 | en_GB.UTF-8 | 
 postgres  | postgres     | UTF8     | en_GB.UTF-8 | en_GB.UTF-8 | 
 template0 | postgres     | UTF8     | en_GB.UTF-8 | en_GB.UTF-8 | =c/postgres          +
           |              |          |             |             | postgres=CTc/postgres
 template1 | postgres     | UTF8     | en_GB.UTF-8 | en_GB.UTF-8 | =c/postgres          +
           |              |          |             |             | postgres=CTc/postgres
(4 rows)

postgres-# dropdb clientms
postgres-# \l
                                    List of databases
   Name    |    Owner     | Encoding |   Collate   |    Ctype    |   Access privileges   
-----------+--------------+----------+-------------+-------------+-----------------------
 clientms  | clientmsuser | UTF8     | en_GB.UTF-8 | en_GB.UTF-8 | 
 postgres  | postgres     | UTF8     | en_GB.UTF-8 | en_GB.UTF-8 | 
 template0 | postgres     | UTF8     | en_GB.UTF-8 | en_GB.UTF-8 | =c/postgres          +
           |              |          |             |             | postgres=CTc/postgres
 template1 | postgres     | UTF8     | en_GB.UTF-8 | en_GB.UTF-8 | =c/postgres          +
           |              |          |             |             | postgres=CTc/postgres
(4 rows)
vm0i2vca

vm0i2vca1#

您忘记了命令后的分号;。请尝试:

DROP DATABASE clientms;

不完整的命令也会由提示符指示:-而不是=。这是为了允许多行命令。
对于其他情况,不考虑简单语法问题:

  • 存在活动连接时删除DB
yqkkidmi

yqkkidmi2#

**使用PGAdmin:**检查您是否与服务器连接,转到您的数据库并右键单击它,然后删除该数据库。刷新数据库或重新打开服务器!
手动执行:

$ sudo -u postgres psql
# \l                         // check db in list
# q                          // to quit that menu
# Drop Database <db_name>;
ru9i0ody

ru9i0ody3#

令人恼火的是,我已经解决了这个问题,但一年多以后又遇到了这个问题,而且用了一种不同的方法来解决它,因为我没有注意到我已经得到了如何解决它的笔记。
http://www.itsupportforum.net/topic/unable-to-delete-drop-postgresql-database/
总之,我不能删除数据库,因为我用来删除它的接口正在使用它。

qoefvg9y

qoefvg9y4#

显然destroydb clientms工作正常(不过我花了很多时间)link(http://www.yolinux.com/TUTORIALS/LinuxTutorialPostgreSQL.html)

相关问题