Postgres Drop Database Error: "pq: cannot drop the currently open database"
This error occurs when attempting to drop the database you are currently connected to. According to Postgres documentation, one cannot drop a database that has an open connection. To rectify this issue, connect to a different database and execute the DROP DATABASE command on that connection.
Alternatively, if other clients are connected to the database, you can forcibly disconnect them to allow for the drop operation. This requires superuser privileges, however. To forcibly disconnect clients from a database named "mydb," use the following command:
If PostgreSQL < 9.2: SELECT pg_terminate_backend(procpid) FROM pg_stat_activity WHERE datname = 'mydb'; Else: SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname = 'mydb';
Once all clients have been disconnected, you can connect to a different database and execute the DROP DATABASE command to remove the desired database.
以上是如何解決 PostgreSQL 中的「pq:無法刪除目前開啟的資料庫」錯誤?的詳細內容。更多資訊請關注PHP中文網其他相關文章!