バージョンごとのドキュメント一覧

31.4. 列リスト #

<title>Column Lists</title>

Each publication can optionally specify which columns of each table are replicated to subscribers. The table on the subscriber side must have at least all the columns that are published. If no column list is specified, then all columns on the publisher are replicated. See <xref linkend="sql-createpublication"/> for details on the syntax. 各パブリケーションでは、オプションで各テーブルのどの列をサブスクライバーにレプリケーションするかを指定できます。 サブスクライバー側のテーブルには、少なくとも発行されるすべての列が必要です。 列リストが指定されていない場合は、パブリッシャーのすべての列がレプリケーションされます。 構文の詳細はCREATE PUBLICATIONを参照してください。

The choice of columns can be based on behavioral or performance reasons. However, do not rely on this feature for security: a malicious subscriber is able to obtain data from columns that are not specifically published. If security is a consideration, protections can be applied at the publisher side. 列の選択は、動作またはパフォーマンスの理由に基づいて行うことができます。 ただし、セキュリティのためにこの機能に依存しないでください。 悪意のあるサブスクライバーが、特に公開されていない列からデータを取得する可能性があります。 セキュリティを考慮する場合は、発行者側で保護を適用できます。

If no column list is specified, any columns added later are automatically replicated. This means that having a column list which names all columns is not the same as having no column list at all. 列リストが指定されていない場合、後で追加された列は自動的にレプリケーションされます。 つまり、すべての列に名前を付ける列リストがあることは、列リストがないこととは異なります。

A column list can contain only simple column references. The order of columns in the list is not preserved. 列リストには、単純な列参照のみを含めることができます。 リスト内の列の順序は保持されません。

Specifying a column list when the publication also publishes <link linkend="sql-createpublication-for-tables-in-schema"><literal>FOR TABLES IN SCHEMA</literal></link> is not supported. 《マッチ度[62.500000]》パブリケーションもパブリッシュする場合の列リストの指定FOR TABLES IN SCHEMAはサポートされていません。 《機械翻訳》パブリケーションがFOR TABLES IN SCHEMAもパブリッシュする場合、列リストを指定することはサポートされていません。

For partitioned tables, the publication parameter <link linkend="sql-createpublication-with-publish-via-partition-root"><literal>publish_via_partition_root</literal></link> determines which column list is used. If <literal>publish_via_partition_root</literal> is <literal>true</literal>, the root partitioned table's column list is used. Otherwise, if <literal>publish_via_partition_root</literal> is <literal>false</literal> (the default), each partition's column list is used. 《マッチ度[80.753138]》パーティション化テーブルの場合、パブリケーション・パラメータpublish_via_partition_rootによって使用される列リストが決定されます。 publish_via_partition_roottrueの場合、ルートのパーティション化テーブルの列リストが使用されます。 それ以外の場合、publish_via_partition_rootfalse(デフォルト)の場合、各パーティションの列リストが使用されます。 《機械翻訳》パーティション化されたテーブルの場合、パブリケーションパラメータ publish_via_partition_root は、どの列リストを使用するかを決定します。 publish_via_partition_roottrueの場合、ルートパーティション表の列リストが使用されます。 そうでない場合、publish_via_partition_rootfalse(デフォルト)の場合、各パーティションの列リストが使用されます。

If a publication publishes <command>UPDATE</command> or <command>DELETE</command> operations, any column list must include the table's replica identity columns (see <xref linkend="sql-altertable-replica-identity"/>). If a publication publishes only <command>INSERT</command> operations, then the column list may omit replica identity columns. パブリケーションがUPDATEまたはDELETE操作をパブリッシュする場合、どの列リストにもテーブルのレプリカID列が含まれている必要があります(REPLICA IDENTITYを参照)。 パブリケーションがINSERT操作のみをパブリッシュする場合列リストでレプリカID列を省略できます。

Column lists have no effect for the <literal>TRUNCATE</literal> command. 列リストは、TRUNCATEコマンドには影響しません。

During initial data synchronization, only the published columns are copied. However, if the subscriber is from a release prior to 15, then all the columns in the table are copied during initial data synchronization, ignoring any column lists. 初期データの同期化時には、公開済の列のみがコピーされます。 ただし、サブスクライバーが15より前のリリースの場合は、テーブルのすべての列が初期データの同期化時にコピーされ、列リストは無視されます。

警告: 複数のパブリケーションからの列リストの統合

<title>Warning: Combining Column Lists from Multiple Publications</title>

There's currently no support for subscriptions comprising several publications where the same table has been published with different column lists. <xref linkend="sql-createsubscription"/> disallows creating such subscriptions, but it is still possible to get into that situation by adding or altering column lists on the publication side after a subscription has been created. 現在、同じテーブルが異なる列リストで発行されている複数のパブリケーションで構成されるサブスクリプションはサポートされていません。 CREATE SUBSCRIPTIONではこのようなサブスクリプションの作成はできませんが、サブスクリプションの作成後にパブリケーション側で列リストを追加または変更することで、このような状況になる可能性はあります。

This means changing the column lists of tables on publications that are already subscribed could lead to errors being thrown on the subscriber side. つまり、すでにサブスクライブされているパブリケーションのテーブルの列リストを変更すると、サブスクライバ側でエラーになる可能性があります。

If a subscription is affected by this problem, the only way to resume replication is to adjust one of the column lists on the publication side so that they all match; and then either recreate the subscription, or use <literal>ALTER SUBSCRIPTION ... DROP PUBLICATION</literal> to remove one of the offending publications and add it again. サブスクリプションがこの問題の影響を受ける場合、レプリケーションを再開する唯一の方法は、パブリケーション側の列リストの1つを調整してすべて一致させてから、サブスクリプションを再作成するか、ALTER SUBSCRIPTION ... DROP PUBLICATIONを使用して問題のパブリケーションの1つを削除し、再度追加することです。

31.4.1. 例 #

<title>Examples</title>

Create a table <literal>t1</literal> to be used in the following example. 次の例で使用するテーブルt1を作成します。

test_pub=# CREATE TABLE t1(id int, a text, b text, c text, d text, e text, PRIMARY KEY(id));
CREATE TABLE

Create a publication <literal>p1</literal>. A column list is defined for table <literal>t1</literal> to reduce the number of columns that will be replicated. Notice that the order of column names in the column list does not matter. パブリケーションp1を作成します。 レプリケーションされる列数を減らすために、テーブルt1に対して列リストが定義されます。 列リスト内の列名の順序は重要ではないことに注意してください。

test_pub=# CREATE PUBLICATION p1 FOR TABLE t1 (id, b, a, d);
CREATE PUBLICATION

<literal>psql</literal> can be used to show the column lists (if defined) for each publication. psqlを使用して、各パブリケーションの列リストを表示することができます(定義されている場合)。

test_pub=# \dRp+
                               Publication p1
  Owner   | All tables | Inserts | Updates | Deletes | Truncates | Via root
----------+------------+---------+---------+---------+-----------+----------
 postgres | f          | t       | t       | t       | t         | f
Tables:
    "public.t1" (id, a, b, d)

<literal>psql</literal> can be used to show the column lists (if defined) for each table. psqlを使用して、各テーブルの列リストを表示することができます(定義されている場合)。

test_pub=# \d t1
                 Table "public.t1"
 Column |  Type   | Collation | Nullable | Default
--------+---------+-----------+----------+---------
 id     | integer |           | not null |
 a      | text    |           |          |
 b      | text    |           |          |
 c      | text    |           |          |
 d      | text    |           |          |
 e      | text    |           |          |
Indexes:
    "t1_pkey" PRIMARY KEY, btree (id)
Publications:
    "p1" (id, a, b, d)

On the subscriber node, create a table <literal>t1</literal> which now only needs a subset of the columns that were on the publisher table <literal>t1</literal>, and also create the subscription <literal>s1</literal> that subscribes to the publication <literal>p1</literal>. サブスクライバーノードで、パブリッシャーテーブルt1にあった列のサブセットだけが必要なテーブルt1を作成し、パブリケーションp1をサブスクライブするサブスクリプションs1も作成します。

test_sub=# CREATE TABLE t1(id int, b text, a text, d text, PRIMARY KEY(id));
CREATE TABLE
test_sub=# CREATE SUBSCRIPTION s1
test_sub-# CONNECTION 'host=localhost dbname=test_pub application_name=s1'
test_sub-# PUBLICATION p1;
CREATE SUBSCRIPTION

On the publisher node, insert some rows to table <literal>t1</literal>. パブリッシャーノードで、テーブルt1に行を挿入します。

test_pub=# INSERT INTO t1 VALUES(1, 'a-1', 'b-1', 'c-1', 'd-1', 'e-1');
INSERT 0 1
test_pub=# INSERT INTO t1 VALUES(2, 'a-2', 'b-2', 'c-2', 'd-2', 'e-2');
INSERT 0 1
test_pub=# INSERT INTO t1 VALUES(3, 'a-3', 'b-3', 'c-3', 'd-3', 'e-3');
INSERT 0 1
test_pub=# SELECT * FROM t1 ORDER BY id;
 id |  a  |  b  |  c  |  d  |  e
----+-----+-----+-----+-----+-----
  1 | a-1 | b-1 | c-1 | d-1 | e-1
  2 | a-2 | b-2 | c-2 | d-2 | e-2
  3 | a-3 | b-3 | c-3 | d-3 | e-3
(3 rows)

Only data from the column list of publication <literal>p1</literal> is replicated. パブリケーションp1の列リストからのデータのみがレプリケーションされます。

test_sub=# SELECT * FROM t1 ORDER BY id;
 id |  b  |  a  |  d
----+-----+-----+-----
  1 | b-1 | a-1 | d-1
  2 | b-2 | a-2 | d-2
  3 | b-3 | a-3 | d-3
(3 rows)