1CREATE PUBLICATION(7)    PostgreSQL 11.6 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
14

DESCRIPTION

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

PARAMETERS

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

NOTES

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

EXAMPLES

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

COMPATIBILITY

105       CREATE PUBLICATION is a PostgreSQL extension.
106

SEE ALSO

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