0
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 1 year has passed since last update.

[PostgreSQL]pg_subscriptionはクラスタ内の全データベースで共有される

Posted at

作成したサブスクリプションの情報はpg_subscriptionを参照することで確認できます。

postgres=# \x
Expanded display is on.
postgres=# SELECT * FROM pg_subscription;
-[ RECORD 1 ]----+----------------------------------------------------------------------------------------
oid              | 284607
subdbid          | 17135
subskiplsn       | 0/0
subname          | sub
subowner         | 10
subenabled       | t
subbinary        | f
substream        | f
subtwophasestate | d
subdisableonerr  | f
subconninfo      | dbname=example host=example.com user=replication
subslotname      | sub
subsynccommit    | off
subpublications  | {pub}

pg_subscriptionはクラスタ内の全データベースで共有されます。
つまり、サブスクリプションを設定したデータベースでなくても、上記SQLを叩くと同じ出力が返ってきます。
マニュアルに以下のように記載があります。

ほとんどのシステムカタログとは異なり、pg_subscriptionはクラスタ内の全データベースで共有されます。 つまりクラスタごとにpg_subscriptionの実体は1つだけ存在し、データベースごとに1つではありません。

自分は、サブスクリプションを設定していないデータベースにpsqlで入って上記SQLを叩いてサブスクリプションが設定されていないことを確認しようとして、びびりました。あれ?なんで、レコードが出力されるのかな…と思いました。

subdbid列がサブスクリプションが存在するデータベースのOIDになるので、サブスクリプションが設定されていないことを確認するには

postgres=# SELECT oid, datname FROM pg_database;
  oid  |   datname
-------+--------------
     5 | postgres
 17135 | publicuserdb
     1 | template1
     4 | template0
(4 rows)

と合わせて確認すればOKです。

0
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
0
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?