1CREATE PUBLICATION(7)    PostgreSQL 10.7 Documentation   CREATE PUBLICATION(7)
2
3
4

NAME

6       CREATE_PUBLICATION - define a new publication
7

SYNOPSIS

9       CREATE PUBLICATION name
10           [ FOR TABLE [ ONLY ] table_name [ * ] [, ...]
11             | FOR ALL TABLES ]
12           [ WITH ( publication_parameter [= value] [, ... ] ) ]
13

DESCRIPTION

15       CREATE PUBLICATION adds a new publication into the current database.
16       The publication name must be distinct from the name of any existing
17       publication in the current database.
18
19       A publication is essentially a group of tables whose data changes are
20       intended to be replicated through logical replication. See Section 31.1
21       for details about how publications fit into the logical replication
22       setup.
23

PARAMETERS

25       name
26           The name of the new publication.
27
28       FOR TABLE
29           Specifies a list of tables to add to the publication. If ONLY is
30           specified before the table name, only that table is added to the
31           publication. If ONLY is not specified, the table and all its
32           descendant tables (if any) are added. Optionally, * can be
33           specified after the table name to explicitly indicate that
34           descendant tables are included.
35
36           Only persistent base tables can be part of a publication. Temporary
37           tables, unlogged tables, foreign tables, materialized views,
38           regular views, and partitioned tables cannot be part of a
39           publication. To replicate a partitioned table, add the individual
40           partitions to the publication.
41
42       FOR ALL TABLES
43           Marks the publication as one that replicates changes for all tables
44           in the database, including tables created in the future.
45
46       WITH ( publication_parameter [= value] [, ... ] )
47           This clause specifies optional parameters for a publication. The
48           following parameters are supported:
49
50           publish (string)
51               This parameter determines which DML operations will be
52               published by the new publication to the subscribers. The value
53               is comma-separated list of operations. The allowed operations
54               are insert, update, and delete. The default is to publish all
55               actions, and so the default value for this option is 'insert,
56               update, delete'.
57
58

NOTES

60       If neither FOR TABLE nor FOR ALL TABLES is specified, then the
61       publication starts out with an empty set of tables. That is useful if
62       tables are to be added later.
63
64       The creation of a publication does not start replication. It only
65       defines a grouping and filtering logic for future subscribers.
66
67       To create a publication, the invoking user must have the CREATE
68       privilege for the current database. (Of course, superusers bypass this
69       check.)
70
71       To add a table to a publication, the invoking user must have ownership
72       rights on the table. The FOR ALL TABLES clause requires the invoking
73       user to be a superuser.
74
75       The tables added to a publication that publishes UPDATE and/or DELETE
76       operations must have REPLICA IDENTITY defined. Otherwise those
77       operations will be disallowed on those tables.
78
79       For an INSERT ... ON CONFLICT command, the publication will publish the
80       operation that actually results from the command. So depending of the
81       outcome, it may be published as either INSERT or UPDATE, or it may not
82       be published at all.
83
84       COPY ... FROM commands are published as INSERT operations.
85
86       TRUNCATE and DDL operations are not published.
87

EXAMPLES

89       Create a publication that publishes all changes in two tables:
90
91           CREATE PUBLICATION mypublication FOR TABLE users, departments;
92
93       Create a publication that publishes all changes in all tables:
94
95           CREATE PUBLICATION alltables FOR ALL TABLES;
96
97       Create a publication that only publishes INSERT operations in one
98       table:
99
100           CREATE PUBLICATION insert_only FOR TABLE mydata
101               WITH (publish = 'insert');
102

COMPATIBILITY

104       CREATE PUBLICATION is a PostgreSQL extension.
105

SEE ALSO

107       ALTER PUBLICATION (ALTER_PUBLICATION(7)), DROP PUBLICATION
108       (DROP_PUBLICATION(7))
109
110
111
112PostgreSQL 10.7                      2019                CREATE PUBLICATION(7)
Impressum