1
0

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 3 years have passed since last update.

PostgreSQLを調査するときのメモ

Posted at

PostgreSQLでトラブル起きた時、何をするんだっけ?

何をするか毎回忘れてあたふたするので、備忘録として。

そもそもDBが何セッション許容しているか調べる時

SHOW max_connections;
postgresql.conf
max_connections = 100                   # (change requires restart)

現在のセッションの接続数は?

SELECT COUNT(*) FROM pg_stat_activity;

セッションが一杯になっていないか確認できる。
その他にも色々調査できそう。

postgres=# \d pg_stat_activity;
 datid            | oid                      |           |          | 
 datname          | name                     |           |          | 
 pid              | integer                  |           |          | 
 usesysid         | oid                      |           |          | 
 usename          | name                     |           |          | 
 application_name | text                     |           |          | 
 client_addr      | inet                     |           |          | 
 client_hostname  | text                     |           |          | 
 client_port      | integer                  |           |          | 
 backend_start    | timestamp with time zone |           |          | 
 xact_start       | timestamp with time zone |           |          | 
 query_start      | timestamp with time zone |           |          | 
 state_change     | timestamp with time zone |           |          | 
 wait_event_type  | text                     |           |          | 
 wait_event       | text                     |           |          | 
 state            | text                     |           |          | 
 backend_xid      | xid                      |           |          | 
 backend_xmin     | xid                      |           |          | 
 query            | text                     |           |          | 
 backend_type     | text                     |           |          | 

以下でトランザクションの調査ができる

postgres=# select datname, usename, state, query from pg_stat_activity;
postgres=# select procpid, datname, client_addr from pg_stat_activity where datname = '{DB名}';

postgresql.conf変更した際に再起動必要か確認

postgres=# select name, setting, context from pg_settings;
1
0
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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?