美文网首页
postgresql删除数据库失败:DETAIL: There

postgresql删除数据库失败:DETAIL: There

作者: 沙漠中的猴 | 来源:发表于2019-07-18 11:04 被阅读0次

在终端执行:dropdb earth

$ dropdb earth

dropdb: database removal failed: ERROR:  database "earth" is being accessed by other users
DETAIL:  There are 2 other sessions using the database.
  1. 连接数据库
$ psql -d earth
psql (9.6.11)
Type "help" for help.

earth=#
  1. 查看现有的连接:
 datid | datname |  pid  | usesysid | usename | application_name | client_addr | client_hostname | client_port |         backend_start         |          xact_start           |          query_start          |         state_change          | wait_event_type | wait_event | state  | backend_xid | backend_xmin |                                                                                                                                                                                                   query
-------+---------+-------+----------+---------+------------------+-------------+-----------------+-------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-----------------+------------+--------+-------------+--------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 16559 | earth   | 43784 |       10 | cszk    | Navicat          | ::1         |                 |       57079 | 2019-07-18 10:28:22.265543+08 |                               | 2019-07-18 10:28:22.282577+08 | 2019-07-18 10:28:22.331031+08 |                 |            | idle   |             |              | SELECT d.oid, d.datname AS databasename, d.datacl, d.datistemplate, d.datallowconn, pg_get_userbyid(d.datdba) AS databaseowner, d.datcollate, d.datctype, shobj_description(d.oid, 'pg_database') AS description, d.datconnlimit, t.spcname, d.encoding, pg_encoding_to_char(d.encoding) AS encodingname FROM pg_database d LEFT JOIN pg_tablespace t ON d.dattablespace = t.oid WHERE d.datname = 'earth'
 16559 | earth   | 43958 |       10 | cszk    | psql             |             |                 |          -1 | 2019-07-18 10:36:28.180986+08 | 2019-07-18 10:39:54.169337+08 | 2019-07-18 10:39:54.169337+08 | 2019-07-18 10:39:54.169357+08 |                 |            | active |             |         2947 | SELECT * FROM pg_stat_activity;
 53271 | polaris | 33807 |       10 | cszk    | Navicat          | ::1         |                 |       50518 | 2019-07-17 19:40:29.525597+08 |                               | 2019-07-17 19:40:38.368099+08 | 2019-07-17 19:40:38.369753+08 |                 |            | idle   |             |              | SELECT t.oid, n.nspname, t.typtype, t.typname FROM pg_type t LEFT JOIN pg_namespace n ON t.typnamespace = n.oid ORDER BY n.nspname, t.typname
 16559 | earth   | 25219 |       10 | cszk    |                  | 127.0.0.1   |                 |       65448 | 2019-07-17 18:41:46.976526+08 |                               | 2019-07-17 20:47:06.493901+08 | 2019-07-17 20:47:06.493988+08 |                 |            | idle   |             |              | COMMIT
 53271 | polaris | 33808 |       10 | cszk    | Navicat          | ::1         |                 |       50519 | 2019-07-17 19:40:29.722659+08 |                               | 2019-07-17 19:40:29.737185+08 | 2019-07-17 19:40:29.747907+08 |                 |            | idle   |             |              | SELECT opr.oid, opr.oprname, nsp.nspname FROM pg_operator opr, pg_namespace nsp WHERE opr.oprnamespace = nsp.oid
 53185 | pisces  | 30329 |       10 | cszk    |                  | 127.0.0.1   |                 |       51996 | 2019-07-17 18:50:53.2512+08   |                               | 2019-07-17 19:33:32.707033+08 | 2019-07-17 19:33:32.707218+08 |                 |            | idle   |             |              | COMMIT
(6 rows)
  1. 退出数据库并,删除掉pid对应的进程
earth=# \q
(cszk)
# Carter-MacBook-Pro in ~ on git:feature/taobusi_user x [11:00:02]
$ kill -9 43784
(cszk)

  1. 删除数据库
$ dropdb earth

相关文章

网友评论

      本文标题:postgresql删除数据库失败:DETAIL: There

      本文链接:https://www.haomeiwen.com/subject/xsuuhqtx.html