Postgresql刪除資料庫失敗解決方法

2021-10-09 09:04:25 字數 425 閱讀 3723

pgadmin右鍵建立資料庫很簡單起個名字就可以了。本以為刪除也很簡單,右鍵刪除drop就可以了,可是偏偏刪除的時候報錯「error: database "dbname" is being accessed by other users

detail: there are 2 other sessions using the database.」

需斷開資料庫所有連線執行

select pg_terminate_backend(pg_stat_activity.pid)

from pg_stat_activity

where datname='dbname' and pid<>pg_backend_pid();

執行之後,即可刪除。

注:如果刪除,需要「disconnect database」 。

PostgreSQL刪除資料庫資料但保留表結構

找了一圈沒有看到postgresql有合適的命令,發現有人可以通過指令碼來實現 獲得所有的表結構刪除命令,比如資料庫名為open lmis select concat truncate table table name,cascade from information schema.tables w...

PostgreSql 刪除資料庫需要用到的操作記錄

記錄一下平時資料庫的操作,以備不時之需 為了驗證某些測試環境無法出現的bug,於是從生產環境dump下來了資料庫。現在我需要 建立乙個資料庫使用者,這個使用者可以一直用 create user with password 新建乙個資料庫並將owner指定為我們對應的使用者 create databa...

PostgreSQL資料庫建立 刪除

方法1 系統命令 sudo su postgres 切換到postgres使用者 系統使用者 createdb weichen 建立資料庫 psql 直接訪問資料庫 預設進入本地postgres資料庫 l 檢視資料庫列表 q 退出列表頁面 q 退出client dropdb weichen 刪除資料...