Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit75b1521

Browse files
committed
Add decoding of sequences to built-in replication
This commit adds support for decoding of sequences to the built-inreplication (the infrastructure was added by commit0da92dc).The syntax and behavior mostly mimics handling of tables, i.e. apublication may be defined as FOR ALL SEQUENCES (replicating allsequences in a database), FOR ALL SEQUENCES IN SCHEMA (replicatingall sequences in a particular schema) or individual sequences.To publish sequence modifications, the publication has to include'sequence' action. The protocol is extended with a new message,describing sequence increments.A new system view pg_publication_sequences lists all the sequencesadded to a publication, both directly and indirectly. Various psqlcommands (\d and \dRp) are improved to also display publicationsincluding a given sequence, or sequences included in a publication.Author: Tomas Vondra, Cary HuangReviewed-by: Peter Eisentraut, Amit Kapila, Hannu Krosing, Andres Freund, Petr JelinekDiscussion:https://postgr.es/m/d045f3c2-6cfb-06d3-5540-e63c320df8bc@enterprisedb.comDiscussion:https://postgr.es/m/1710ed7e13b.cd7177461430746.3372264562543607781@highgo.ca
1 parent0adb3dc commit75b1521

File tree

40 files changed

+3235
-468
lines changed

40 files changed

+3235
-468
lines changed

‎doc/src/sgml/catalogs.sgml

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6281,6 +6281,16 @@ SCRAM-SHA-256$<replaceable>&lt;iteration count&gt;</replaceable>:<replaceable>&l
62816281
Reference to schema
62826282
</para></entry>
62836283
</row>
6284+
6285+
<row>
6286+
<entry role="catalog_table_entry"><para role="column_definition">
6287+
<structfield>pntype</structfield> <type>char</type>
6288+
Determines which object type is included from this schema.
6289+
</para>
6290+
<para>
6291+
Reference to schema
6292+
</para></entry>
6293+
</row>
62846294
</tbody>
62856295
</tgroup>
62866296
</table>
@@ -9598,6 +9608,11 @@ SCRAM-SHA-256$<replaceable>&lt;iteration count&gt;</replaceable>:<replaceable>&l
95989608
<entry>prepared transactions</entry>
95999609
</row>
96009610

9611+
<row>
9612+
<entry><link linkend="view-pg-publication-sequences"><structname>pg_publication_sequences</structname></link></entry>
9613+
<entry>publications and their associated sequences</entry>
9614+
</row>
9615+
96019616
<row>
96029617
<entry><link linkend="view-pg-publication-tables"><structname>pg_publication_tables</structname></link></entry>
96039618
<entry>publications and their associated tables</entry>
@@ -11433,6 +11448,72 @@ SELECT * FROM pg_locks pl LEFT JOIN pg_prepared_xacts ppx
1143311448

1143411449
</sect1>
1143511450

11451+
<sect1 id="view-pg-publication-sequences">
11452+
<title><structname>pg_publication_sequences</structname></title>
11453+
11454+
<indexterm zone="view-pg-publication-sequences">
11455+
<primary>pg_publication_sequences</primary>
11456+
</indexterm>
11457+
11458+
<para>
11459+
The view <structname>pg_publication_sequences</structname> provides
11460+
information about the mapping between publications and the sequences they
11461+
contain. Unlike the underlying catalog
11462+
<link linkend="catalog-pg-publication-rel"><structname>pg_publication_rel</structname></link>,
11463+
this view expands
11464+
publications defined as <literal>FOR ALL SEQUENCES</literal>, so for such
11465+
publications there will be a row for each eligible sequence.
11466+
</para>
11467+
11468+
<table>
11469+
<title><structname>pg_publication_sequences</structname> Columns</title>
11470+
<tgroup cols="1">
11471+
<thead>
11472+
<row>
11473+
<entry role="catalog_table_entry"><para role="column_definition">
11474+
Column Type
11475+
</para>
11476+
<para>
11477+
Description
11478+
</para></entry>
11479+
</row>
11480+
</thead>
11481+
11482+
<tbody>
11483+
<row>
11484+
<entry role="catalog_table_entry"><para role="column_definition">
11485+
<structfield>pubname</structfield> <type>name</type>
11486+
(references <link linkend="catalog-pg-publication"><structname>pg_publication</structname></link>.<structfield>pubname</structfield>)
11487+
</para>
11488+
<para>
11489+
Name of publication
11490+
</para></entry>
11491+
</row>
11492+
11493+
<row>
11494+
<entry role="catalog_table_entry"><para role="column_definition">
11495+
<structfield>schemaname</structfield> <type>name</type>
11496+
(references <link linkend="catalog-pg-namespace"><structname>pg_namespace</structname></link>.<structfield>nspname</structfield>)
11497+
</para>
11498+
<para>
11499+
Name of schema containing sequence
11500+
</para></entry>
11501+
</row>
11502+
11503+
<row>
11504+
<entry role="catalog_table_entry"><para role="column_definition">
11505+
<structfield>sequencename</structfield> <type>name</type>
11506+
(references <link linkend="catalog-pg-class"><structname>pg_class</structname></link>.<structfield>relname</structfield>)
11507+
</para>
11508+
<para>
11509+
Name of sequence
11510+
</para></entry>
11511+
</row>
11512+
</tbody>
11513+
</tgroup>
11514+
</table>
11515+
</sect1>
11516+
1143611517
<sect1 id="view-pg-publication-tables">
1143711518
<title><structname>pg_publication_tables</structname></title>
1143811519

‎doc/src/sgml/protocol.sgml

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7065,6 +7065,125 @@ Relation
70657065
</listitem>
70667066
</varlistentry>
70677067

7068+
<varlistentry id="protocol-logicalrep-message-formats-Sequence">
7069+
<term>
7070+
Sequence
7071+
</term>
7072+
<listitem>
7073+
<para>
7074+
7075+
<variablelist>
7076+
<varlistentry>
7077+
<term>
7078+
Byte1('X')
7079+
</term>
7080+
<listitem>
7081+
<para>
7082+
Identifies the message as a sequence message.
7083+
</para>
7084+
</listitem>
7085+
</varlistentry>
7086+
<varlistentry>
7087+
<term>
7088+
Int32 (TransactionId)
7089+
</term>
7090+
<listitem>
7091+
<para>
7092+
Xid of the transaction (only present for streamed transactions).
7093+
This field is available since protocol version 2.
7094+
</para>
7095+
</listitem>
7096+
</varlistentry>
7097+
<varlistentry>
7098+
<term>
7099+
Int8(0)
7100+
</term>
7101+
<listitem>
7102+
<para>
7103+
Flags; currently unused.
7104+
</para>
7105+
</listitem>
7106+
</varlistentry>
7107+
<varlistentry>
7108+
<term>
7109+
Int64 (XLogRecPtr)
7110+
</term>
7111+
<listitem>
7112+
<para>
7113+
The LSN of the sequence increment.
7114+
</para>
7115+
</listitem>
7116+
</varlistentry>
7117+
<varlistentry>
7118+
<term>
7119+
String
7120+
</term>
7121+
<listitem>
7122+
<para>
7123+
Namespace (empty string for <literal>pg_catalog</literal>).
7124+
</para>
7125+
</listitem>
7126+
</varlistentry>
7127+
<varlistentry>
7128+
<term>
7129+
String
7130+
</term>
7131+
<listitem>
7132+
<para>
7133+
Relation name.
7134+
</para>
7135+
</listitem>
7136+
</varlistentry>
7137+
7138+
<varlistentry>
7139+
<term>
7140+
Int8
7141+
</term>
7142+
<listitem>
7143+
<para>
7144+
1 if the sequence update is transactions, 0 otherwise.
7145+
</para>
7146+
</listitem>
7147+
</varlistentry>
7148+
7149+
<varlistentry>
7150+
<term>
7151+
Int64
7152+
</term>
7153+
<listitem>
7154+
<para>
7155+
<structfield>last_value</structfield> value of the sequence.
7156+
</para>
7157+
</listitem>
7158+
</varlistentry>
7159+
7160+
<varlistentry>
7161+
<term>
7162+
Int64
7163+
</term>
7164+
<listitem>
7165+
<para>
7166+
<structfield>log_cnt</structfield> value of the sequence.
7167+
</para>
7168+
</listitem>
7169+
</varlistentry>
7170+
7171+
<varlistentry>
7172+
<term>
7173+
Int8
7174+
</term>
7175+
<listitem>
7176+
<para>
7177+
<structfield>is_called</structfield> value of the sequence.
7178+
</para>
7179+
</listitem>
7180+
</varlistentry>
7181+
7182+
</variablelist>
7183+
</para>
7184+
</listitem>
7185+
</varlistentry>
7186+
70687187
<varlistentry id="protocol-logicalrep-message-formats-Type">
70697188
<term>
70707189
Type

‎doc/src/sgml/ref/alter_publication.sgml

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ ALTER PUBLICATION <replaceable class="parameter">name</replaceable> RENAME TO <r
3131
<phrase>where <replaceable class="parameter">publication_object</replaceable> is one of:</phrase>
3232

3333
TABLE [ ONLY ] <replaceable class="parameter">table_name</replaceable> [ * ] [ WHERE ( <replaceable class="parameter">expression</replaceable> ) ] [, ... ]
34+
SEQUENCE <replaceable class="parameter">sequence_name</replaceable> [, ... ]
3435
ALL TABLES IN SCHEMA { <replaceable class="parameter">schema_name</replaceable> | CURRENT_SCHEMA } [, ... ]
36+
ALL SEQUENCES IN SCHEMA { <replaceable class="parameter">schema_name</replaceable> | CURRENT_SCHEMA } [, ... ]
3537
</synopsis>
3638
</refsynopsisdiv>
3739

@@ -44,13 +46,13 @@ ALTER PUBLICATION <replaceable class="parameter">name</replaceable> RENAME TO <r
4446
</para>
4547

4648
<para>
47-
The first three variants change which tables/schemas are part of the
48-
publication. The <literal>SET</literal> clause will replace the list of
49-
tables/schemas in the publication with the specified list; the existing
50-
tables/schemas that were present in the publication will be removed. The
51-
<literal>ADD</literal> and <literal>DROP</literal> clauses will add and
52-
remove one or moretables/schemas from the publication. Note that adding
53-
tables/schemasto a publication that is already subscribed to will require an
49+
The first three variants change whichobjects (tables, sequences or schemas)
50+
are part of thepublication. The <literal>SET</literal> clause will replace
51+
the list of objects in the publication with the specified list; the existing
52+
objects that were present in the publication will be removed.
53+
The<literal>ADD</literal> and <literal>DROP</literal> clauses will add and
54+
remove one or moreobjects from the publication. Note that adding objects
55+
to a publication that is already subscribed to will require an
5456
<literal>ALTER SUBSCRIPTION ... REFRESH PUBLICATION</literal> action on the
5557
subscribing side in order to become effective. Note also that the combination
5658
of <literal>DROP</literal> with a <literal>WHERE</literal> clause is not
@@ -122,6 +124,15 @@ ALTER PUBLICATION <replaceable class="parameter">name</replaceable> RENAME TO <r
122124
</listitem>
123125
</varlistentry>
124126

127+
<varlistentry>
128+
<term><replaceable class="parameter">sequence_name</replaceable></term>
129+
<listitem>
130+
<para>
131+
Name of an existing sequence.
132+
</para>
133+
</listitem>
134+
</varlistentry>
135+
125136
<varlistentry>
126137
<term><replaceable class="parameter">schema_name</replaceable></term>
127138
<listitem>

‎doc/src/sgml/ref/alter_subscription.sgml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,8 @@ ALTER SUBSCRIPTION <replaceable class="parameter">name</replaceable> RENAME TO <
148148
<listitem>
149149
<para>
150150
Fetch missing table information from publisher. This will start
151-
replication of tables that were added to the subscribed-to publications
152-
since <command>CREATE SUBSCRIPTION</command> or
151+
replication of tablesand sequencesthat were added to the subscribed-to
152+
publicationssince <command>CREATE SUBSCRIPTION</command> or
153153
the last invocation of <command>REFRESH PUBLICATION</command>.
154154
</para>
155155

@@ -167,8 +167,8 @@ ALTER SUBSCRIPTION <replaceable class="parameter">name</replaceable> RENAME TO <
167167
The default is <literal>true</literal>.
168168
</para>
169169
<para>
170-
Previously subscribed tables are not copied, even if a table's row
171-
filter <literal>WHERE</literal> clause has since been modified.
170+
Previously subscribed tablesand sequencesare not copied, even if a
171+
table's rowfilter <literal>WHERE</literal> clause has since been modified.
172172
</para>
173173
</listitem>
174174
</varlistentry>

‎doc/src/sgml/ref/create_publication.sgml

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,21 @@ PostgreSQL documentation
2222
<refsynopsisdiv>
2323
<synopsis>
2424
CREATE PUBLICATION <replaceable class="parameter">name</replaceable>
25-
[ FOR ALLTABLES
25+
[ FOR ALL<replaceable class="parameter">object_type</replaceable> [, ...]
2626
| FOR <replaceable class="parameter">publication_object</replaceable> [, ... ] ]
2727
[ WITH ( <replaceable class="parameter">publication_parameter</replaceable> [= <replaceable class="parameter">value</replaceable>] [, ... ] ) ]
2828

29+
<phrase>where <replaceable class="parameter">object type</replaceable> is one of:</phrase>
30+
31+
TABLES
32+
SEQUENCES
33+
2934
<phrase>where <replaceable class="parameter">publication_object</replaceable> is one of:</phrase>
3035

3136
TABLE [ ONLY ] <replaceable class="parameter">table_name</replaceable> [ * ] [ WHERE ( <replaceable class="parameter">expression</replaceable> ) ] [, ... ]
37+
SEQUENCE <replaceable class="parameter">sequence_name</replaceable> [ * ] [, ... ]
3238
ALL TABLES IN SCHEMA { <replaceable class="parameter">schema_name</replaceable> | CURRENT_SCHEMA } [, ... ]
39+
ALL SEQUENCES IN SCHEMA { <replaceable class="parameter">schema_name</replaceable> | CURRENT_SCHEMA } [, ... ]
3340
</synopsis>
3441
</refsynopsisdiv>
3542

@@ -107,27 +114,43 @@ CREATE PUBLICATION <replaceable class="parameter">name</replaceable>
107114
</listitem>
108115
</varlistentry>
109116

117+
<varlistentry>
118+
<term><literal>FOR SEQUENCE</literal></term>
119+
<listitem>
120+
<para>
121+
Specifies a list of sequences to add to the publication.
122+
</para>
123+
124+
<para>
125+
Specifying a sequence that is part of a schema specified by <literal>FOR
126+
ALL SEQUENCES IN SCHEMA</literal> is not supported.
127+
</para>
128+
</listitem>
129+
</varlistentry>
130+
110131
<varlistentry>
111132
<term><literal>FOR ALL TABLES</literal></term>
133+
<term><literal>FOR ALL SEQUENCES</literal></term>
112134
<listitem>
113135
<para>
114-
Marks the publication as one that replicates changes for all tables in
115-
the database, including tables created in the future.
136+
Marks the publication as one that replicates changes for all tables/sequences in
137+
the database, including tables/sequences created in the future.
116138
</para>
117139
</listitem>
118140
</varlistentry>
119141

120142
<varlistentry>
121143
<term><literal>FOR ALL TABLES IN SCHEMA</literal></term>
144+
<term><literal>FOR ALL SEQUENCES IN SCHEMA</literal></term>
122145
<listitem>
123146
<para>
124-
Marks the publication as one that replicates changes for all tables in
125-
the specified list of schemas, including tables created in the future.
147+
Marks the publication as one that replicates changes for allsequences/tables in
148+
the specified list of schemas, includingsequences/tables created in the future.
126149
</para>
127150

128151
<para>
129-
Specifying a schema along with a table which belongs to the specified
130-
schema using <literal>FOR TABLE</literal> is not supported.
152+
Specifying a schema along with asequence/table which belongs to the specified
153+
schema using <literal>FORSEQUENCE</literal>/<literal>FORTABLE</literal> is not supported.
131154
</para>
132155

133156
<para>
@@ -202,10 +225,9 @@ CREATE PUBLICATION <replaceable class="parameter">name</replaceable>
202225
<title>Notes</title>
203226

204227
<para>
205-
If <literal>FOR TABLE</literal>, <literal>FOR ALL TABLES</literal> or
206-
<literal>FOR ALL TABLES IN SCHEMA</literal> are not specified, then the
207-
publication starts out with an empty set of tables. That is useful if
208-
tables or schemas are to be added later.
228+
If <literal>FOR TABLE</literal>, <literal>FOR SEQUENCE</literal>, etc. is
229+
not specified, then the publication starts out with an empty set of tables
230+
and sequences. That is useful if objects are to be added later.
209231
</para>
210232

211233
<para>
@@ -220,10 +242,9 @@ CREATE PUBLICATION <replaceable class="parameter">name</replaceable>
220242
</para>
221243

222244
<para>
223-
To add a table to a publication, the invoking user must have ownership
224-
rights on the table. The <command>FOR ALL TABLES</command> and
225-
<command>FOR ALL TABLES IN SCHEMA</command> clauses require the invoking
226-
user to be a superuser.
245+
To add a table or a sequence to a publication, the invoking user must
246+
have ownership rights on the object. The <command>FOR ALL ...</command>
247+
clauses require the invoking user to be a superuser.
227248
</para>
228249

229250
<para>

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp