19
21

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

PostgreSQLでロックを解除する方法

Last updated at Posted at 2019-08-06

ロックの確認方法

様々なサイトで以下の方法でロックされているpidを探す記事がほとんどだった。

SELECT l.pid,l.granted,d.datname,l.locktype,relation,relation::regclass,transactionid,l.mode
    FROM pg_locks l  LEFT JOIN pg_database d ON l.database = d.oid
    WHERE  l.pid != pg_backend_pid()
    ORDER BY l.pid;
select * from pg_stat_activity;

ロックの解除方法

SELECT pg_cancel_backend(プロセスID)

プロセスIDには以下を指定

pg_stat_activity.procid
pg_locks.pid

これでも、プロセスが消えない場合は以下で解決。

SELECT pg_terminate_backend(プロセスID)

参考サイト

19
21
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
19
21

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?