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

CREATE PUBLICATION

CREATE PUBLICATION <refpurpose>define a new publication</refpurpose> — 新しいパブリケーションを定義する

概要

CREATE PUBLICATION name
    [ FOR ALL TABLES
      | FOR publication_object [, ... ] ]
    [ WITH ( publication_parameter [= value] [, ... ] ) ]


<phrase>where <replaceable class="parameter">publication_object</replaceable> is one of:</phrase>

ここでpublication_objectは以下のいずれかです。

    TABLE [ ONLY ] table_name [ * ] [ ( column_name [, ... ] ) ] [ WHERE ( expression ) ] [, ... ]
    TABLES IN SCHEMA { schema_name | CURRENT_SCHEMA } [, ... ]

説明

<title>Description</title>

<command>CREATE PUBLICATION</command> adds a new publication into the current database. The publication name must be distinct from the name of any existing publication in the current database. CREATE PUBLICATIONは現在のデータベースに新しいパブリケーションを追加します。 パブリケーションの名前は現在のデータベースに存在するどのパブリケーションの名前とも異なるものでなければなりません。

A publication is essentially a group of tables whose data changes are intended to be replicated through logical replication. See <xref linkend="logical-replication-publication"/> for details about how publications fit into the logical replication setup. パブリケーションは本質的にはテーブルの集合で、それらのテーブルのデータの変更が、論理レプリケーションを通じて複製されることが意図されているものです。 論理レプリケーションの設定で、パブリケーションがどのように位置づけられるかの詳細については、31.1を参照してください。

パラメータ

<title>Parameters</title>
name #

The name of the new publication. 新しいパブリケーションの名前です。

FOR TABLE #

Specifies a list of tables to add to the publication. If <literal>ONLY</literal> is specified before the table name, only that table is added to the publication. If <literal>ONLY</literal> is not specified, the table and all its descendant tables (if any) are added. Optionally, <literal>*</literal> can be specified after the table name to explicitly indicate that descendant tables are included. This does not apply to a partitioned table, however. The partitions of a partitioned table are always implicitly considered part of the publication, so they are never explicitly added to the publication. パブリケーションに追加するテーブルのリストを指定します。 テーブル名の前にONLYが指定されているときは、そのテーブルだけがパブリケーションに追加されます。 ONLYが指定されていないときは、そのテーブルと、そのすべての子テーブル(あれば)が追加されます。 オプションで、テーブル名の後に*を指定して、子テーブルが含まれることを明示的に示すことができます。 しかしながら、これはパーティションテーブルには適用されません。 パーティションテーブルのパーティションは、パブリケーションに含まれると常に暗黙的にみなされますので、パブリケーションに明示的に追加されることは決してありません。

If the optional <literal>WHERE</literal> clause is specified, it defines a <firstterm>row filter</firstterm> expression. Rows for which the <replaceable class="parameter">expression</replaceable> evaluates to false or null will not be published. Note that parentheses are required around the expression. It has no effect on <literal>TRUNCATE</literal> commands. オプションのWHERE句を指定すると、行フィルタ式が定義されます。 expressionが偽またはNULLと評価される行はパブリッシュされません。 式を括弧で囲む必要があることに注意してください。 TRUNCATEコマンドには影響しません。

When a column list is specified, only the named columns are replicated. If no column list is specified, all columns of the table are replicated through this publication, including any columns added later. It has no effect on <literal>TRUNCATE</literal> commands. See <xref linkend="logical-replication-col-lists"/> for details about column lists. 列リストを指定すると、指定した列のみが複製されます。 列リストが指定されていない場合は、後で追加される列も含めて、テーブルのすべての列がこのパブリケーションを介して複製されます。 TRUNCATEコマンドには影響しません。 列リストの詳細は31.4を参照してください。

Only persistent base tables and partitioned tables can be part of a publication. Temporary tables, unlogged tables, foreign tables, materialized views, and regular views cannot be part of a publication. パブリケーションに含めることができるのは、永続的なベーステーブルとパーティションテーブルだけです。 一時テーブル、ログを取らないテーブル、外部テーブル、マテリアライズドビュー、通常のビューはパブリケーションに含めることはできません。

Specifying a column list when the publication also publishes <literal>FOR TABLES IN SCHEMA</literal> is not supported. パブリケーションがFOR TABLES IN SCHEMAもパブリッシュする場合に列リストを指定することはサポートされていません。

When a partitioned table is added to a publication, all of its existing and future partitions are implicitly considered to be part of the publication. So, even operations that are performed directly on a partition are also published via publications that its ancestors are part of. パーティションテーブルがパブリケーションに追加された場合、既存のパーティションと将来のものすべてがパブリケーションに含められたと暗黙的にみなされます。 ですので、パーティションに対して直接実行された操作であっても、その先祖を含むパブリケーション経由でパブリッシュされます。

FOR ALL TABLES #

Marks the publication as one that replicates changes for all tables in the database, including tables created in the future. そのパブリケーションでは、将来作成されるテーブルも含め、そのデータベース内の全テーブルについての変更を複製するものとして印をつけます。

FOR TABLES IN SCHEMA #

Marks the publication as one that replicates changes for all tables in the specified list of schemas, including tables created in the future. そのパブリケーションでは、将来作成されるテーブルも含め、指定されたスキーマのリスト内の全テーブルについての変更を複製するものとして印をつけます。

Specifying a schema when the publication also publishes a table with a column list is not supported. パブリケーションが列リストを持つテーブルもパブリッシュする場合のスキーマの指定はサポートされていません。

Only persistent base tables and partitioned tables present in the schema will be included as part of the publication. Temporary tables, unlogged tables, foreign tables, materialized views, and regular views from the schema will not be part of the publication. パブリケーションに含めることができるのは、スキーマ内に存在する永続的なベーステーブルとパーティションテーブルだけです。 一時テーブル、ログを取らないテーブル、外部テーブル、マテリアライズドビュー、通常のビューはパブリケーションに含めることはできません。

When a partitioned table is published via schema level publication, all of its existing and future partitions are implicitly considered to be part of the publication, regardless of whether they are from the publication schema or not. So, even operations that are performed directly on a partition are also published via publications that its ancestors are part of. パーティションテーブルがスキーマレベルのパブリケーションでパブリッシュされた場合、パブリケーションスキーマからのものかどうかに関わらず、既存のパーティションと将来のものすべてがパブリケーションに含められたと暗黙的にみなされます。 ですので、パーティションに対して直接実行された操作であっても、その先祖を含むパブリケーション経由でパブリッシュされます。

WITH ( publication_parameter [= value] [, ... ] ) #

This clause specifies optional parameters for a publication. The following parameters are supported: この句ではパブリケーションのオプションパラメータを指定します。 以下のパラメータがサポートされています。

publish (string) #

This parameter determines which DML operations will be published by the new publication to the subscribers. The value is comma-separated list of operations. The allowed operations are <literal>insert</literal>, <literal>update</literal>, <literal>delete</literal>, and <literal>truncate</literal>. The default is to publish all actions, and so the default value for this option is <literal>'insert, update, delete, truncate'</literal>. このパラメータは、新しいパブリケーションがどのDML操作をサブスクライバーにパブリッシュするかを指定します。 値はカンマで区切られた操作のリストです。 使用できる操作はinsertupdatedeletetruncateです。 デフォルトではすべての動作をパブリッシュするので、このオプションのデフォルト値は'insert, update, delete, truncate'です。

This parameter only affects DML operations. In particular, the initial data synchronization (see <xref linkend="logical-replication-snapshot"/>) for logical replication does not take this parameter into account when copying existing table data. このパラメータはDML操作にのみ影響します。 特に、論理レプリケーションの初期データ同期化(31.7.1を参照)では、既存のテーブルデータをコピーするときにこのパラメータは考慮されません。

publish_via_partition_root (boolean) #

This parameter determines whether changes in a partitioned table (or on its partitions) contained in the publication will be published using the identity and schema of the partitioned table rather than that of the individual partitions that are actually changed; the latter is the default. Enabling this allows the changes to be replicated into a non-partitioned table or a partitioned table consisting of a different set of partitions. このパラメータは、パブリケーションに含まれるパーティションテーブル(またはそのパーティション)での変更を、実際に変更された個々のパーティションではなく、パーティションテーブルの識別とスキーマを使ってパブリッシュするかどうかを決めます。実際に変更された個々のパーティションのものでパブリッシュされるのがデフォルトです。 これを有効にすると、パーティション化されていないテーブルやパーティションの異なる集合からなるパーティションテーブルへ変更を複製できるようになります。

There can be a case where a subscription combines multiple publications. If a partitioned table is published by any subscribed publications which set <literal>publish_via_partition_root = true</literal>, changes on this partitioned table (or on its partitions) will be published using the identity and schema of this partitioned table rather than that of the individual partitions. 1つのサブスクリプションが複数のパブリケーションを組み合わせている場合があります。 publish_via_partition_root = trueを設定しサブスクライブされたパブリケーションがパーティションテーブルをパブリッシュする場合、このパーティションテーブル(またはそのパーティション)の変更は、個々のパーティションのものではなく、このパーティションテーブルのIDとスキーマを使用してパブリッシュされます。

This parameter also affects how row filters and column lists are chosen for partitions; see below for details. このパラメータは、パーティション用の行フィルタと列リストの選択方法にも影響します。 詳細は以下を参照してください。

If this is enabled, <literal>TRUNCATE</literal> operations performed directly on partitions are not replicated. これが有効な場合、パーティションに対して直接実行されたTRUNCATE操作は複製されません。

When specifying a parameter of type <type>boolean</type>, the <literal>=</literal> <replaceable class="parameter">value</replaceable> part can be omitted, which is equivalent to specifying <literal>TRUE</literal>. boolean型のパラメータを指定する場合、= valueの部分を省略できます。これはTRUEを指定するのと同じです。

注釈

<title>Notes</title>

If <literal>FOR TABLE</literal>, <literal>FOR ALL TABLES</literal> or <literal>FOR TABLES IN SCHEMA</literal> are not specified, then the publication starts out with an empty set of tables. That is useful if tables or schemas are to be added later. FOR TABLEFOR ALL TABLESFOR TABLES IN SCHEMAのいずれも指定されていない場合、パブリケーションは空のテーブルの集合で作られます。 これは後でテーブルを追加したい場合に便利です。

The creation of a publication does not start replication. It only defines a grouping and filtering logic for future subscribers. パブリケーションを作るだけでは、レプリケーションは開始されません。 これは単に将来のサブスクライバーのためにグループとフィルタの論理を定義するだけです。

To create a publication, the invoking user must have the <literal>CREATE</literal> privilege for the current database. (Of course, superusers bypass this check.) パブリケーションを作成するには、それを実行するユーザは現在のデータベースにCREATE権限を持っていなければなりません。 (もちろん、スーパーユーザにはこの検査は適用されません。)

To add a table to a publication, the invoking user must have ownership rights on the table. The <command>FOR ALL TABLES</command> and <command>FOR TABLES IN SCHEMA</command> clauses require the invoking user to be a superuser. パブリケーションにテーブルを追加するには、それを実行するユーザがそのテーブルの所有権を持っていなければなりません。 FOR ALL TABLES句やFOR TABLES IN SCHEMA句は、それを実行するユーザがスーパーユーザである必要があります。

The tables added to a publication that publishes <command>UPDATE</command> and/or <command>DELETE</command> operations must have <literal>REPLICA IDENTITY</literal> defined. Otherwise those operations will be disallowed on those tables. UPDATEまたはDELETEをパブリッシュするパブリケーションに追加されるテーブルにはREPLICA IDENTITYが定義されていなければなりません。 そうでなければ、それらのテーブルに対して、それらの操作は禁止されることになります。

Any column list must include the <literal>REPLICA IDENTITY</literal> columns in order for <command>UPDATE</command> or <command>DELETE</command> operations to be published. There are no column list restrictions if the publication publishes only <command>INSERT</command> operations. UPDATEまたはDELETE操作をパブリッシュするには、すべての列リストにREPLICA IDENTITY列が含まれている必要があります。 パブリケーションがINSERT操作のみをパブリッシュする場合は、列リストの制限はありません。

A row filter expression (i.e., the <literal>WHERE</literal> clause) must contain only columns that are covered by the <literal>REPLICA IDENTITY</literal>, in order for <command>UPDATE</command> and <command>DELETE</command> operations to be published. For publication of <command>INSERT</command> operations, any column may be used in the <literal>WHERE</literal> expression. The row filter allows simple expressions that don't have user-defined functions, user-defined operators, user-defined types, user-defined collations, non-immutable built-in functions, or references to system columns. 行フィルタ式(すなわち、WHERE句)には、UPDATEおよびDELETE操作をパブリッシュするために、REPLICA IDENTITYでカバーされる列のみを含めることが必要です。 INSERT操作のパブリッシュでは、WHERE式で任意の列を使用できます。 行フィルタでは、ユーザー定義関数、ユーザー定義演算子、ユーザー定義型、ユーザー定義照合順序、不変でない組み込み関数、またはシステム列への参照を持たない単純な式を使用できます。

The row filter on a table becomes redundant if <literal>FOR TABLES IN SCHEMA</literal> is specified and the table belongs to the referred schema. FOR TABLES IN SCHEMAが指定され、そのテーブルが参照されたスキーマに属している場合、テーブルの行フィルタは冗長になります。

For published partitioned tables, the row filter for each partition is taken from the published partitioned table if the publication parameter <literal>publish_via_partition_root</literal> is true, or from the partition itself if it is false (the default). See <xref linkend="logical-replication-row-filter"/> for details about row filters. Similarly, for published partitioned tables, the column list for each partition is taken from the published partitioned table if the publication parameter <literal>publish_via_partition_root</literal> is true, or from the partition itself if it is false. パブリッシュされたパーティションテーブルの場合、各パーティションの行フィルタは、パブリケーションパラメータpublish_via_partition_rootが真の場合にはパブリッシュされたパーティションテーブルから、偽の場合(デフォルト)にはパーティション自体から取得されます。 行フィルタの詳細は31.3を参照してください。 同様に、パブリッシュされたパーティションテーブルの場合、各パーティションの列リストは、パブリケーションパラメータpublish_via_partition_rootが真の場合にはパブリッシュされたパーティションテーブルから、偽の場合にはパーティション自体から取得されます。

For an <command>INSERT ... ON CONFLICT</command> command, the publication will publish the operation that results from the command. Depending on the outcome, it may be published as either <command>INSERT</command> or <command>UPDATE</command>, or it may not be published at all. INSERT ... ON CONFLICTコマンドに対しては、パブリケーションはコマンドの結果として起こった操作をパブリッシュします。 その結果に応じてINSERTあるいはUPDATEのいずれかとしてパブリッシュするか、あるいは何もパブリッシュしないかもしれません。

For a <command>MERGE</command> command, the publication will publish an <command>INSERT</command>, <command>UPDATE</command>, or <command>DELETE</command> for each row inserted, updated, or deleted. MERGEコマンドに対しては、パブリケーションは挿入、更新、または削除された行ごとにINSERTUPDATE、またはDELETEをパブリッシュします。

<command>ATTACH</command>ing a table into a partition tree whose root is published using a publication with <literal>publish_via_partition_root</literal> set to <literal>true</literal> does not result in the table's existing contents being replicated. publish_via_partition_roottrueに設定したルートがパブリッシュされたパブリケーションを使用してパーティションツリーにテーブルをATTACHしても、テーブルの既存の内容は複製されません。

<command>COPY ... FROM</command> commands are published as <command>INSERT</command> operations. COPY ... FROMコマンドはINSERTの操作としてパブリッシュされます。

<acronym>DDL</acronym> operations are not published. DDLの操作はパブリッシュされません。

The <literal>WHERE</literal> clause expression is executed with the role used for the replication connection. WHERE句の式は、レプリケーション接続に使用されるロールで実行されます。

<title>Examples</title>

Create a publication that publishes all changes in two tables: 2つのテーブルのすべての変更をパブリッシュするパブリケーションを作成します。

CREATE PUBLICATION mypublication FOR TABLE users, departments;

Create a publication that publishes all changes from active departments: 活発な部署(active departments)からのすべての変更をパブリッシュするパブリケーションを作成します。

CREATE PUBLICATION active_departments FOR TABLE departments WHERE (active IS TRUE);

Create a publication that publishes all changes in all tables: すべてのテーブルのすべての変更をパブリッシュするパブリケーションを作成します。

CREATE PUBLICATION alltables FOR ALL TABLES;

Create a publication that only publishes <command>INSERT</command> operations in one table: 1つのテーブルのINSERTの操作のみをパブリッシュするパブリケーションを作成します。

CREATE PUBLICATION insert_only FOR TABLE mydata
    WITH (publish = 'insert');

Create a publication that publishes all changes for tables <structname>users</structname>, <structname>departments</structname> and all changes for all the tables present in the schema <structname>production</structname>: テーブルusersdepartmentsのすべての変更、およびスキーマproductionに存在するすべてのテーブルのすべての変更をパブリッシュするパブリケーションを作成します。

CREATE PUBLICATION production_publication FOR TABLE users, departments, TABLES IN SCHEMA production;

Create a publication that publishes all changes for all the tables present in the schemas <structname>marketing</structname> and <structname>sales</structname>: スキーマmarketingおよびsalesに存在するすべてのテーブルに対するすべての変更をパブリッシュするパブリケーションを作成します。

CREATE PUBLICATION sales_publication FOR TABLES IN SCHEMA marketing, sales;

Create a publication that publishes all changes for table <structname>users</structname>, but replicates only columns <structname>user_id</structname> and <structname>firstname</structname>: テーブルusersのすべての変更をパブリッシュするものの、列user_idfirstnameのみを複製するパブリケーションを作成します。

CREATE PUBLICATION users_filtered FOR TABLE users (user_id, firstname);

互換性

<title>Compatibility</title>

<command>CREATE PUBLICATION</command> is a <productname>PostgreSQL</productname> extension. CREATE PUBLICATIONPostgreSQLの拡張です。

関連項目

<title>See Also</title> ALTER PUBLICATION, DROP PUBLICATION, CREATE SUBSCRIPTION, ALTER SUBSCRIPTION