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

Commit04ff636

Browse files
Add GUC option to control maximum active replication origins.
This commit introduces a new GUC option max_active_replication_originsto control the maximum number of active replicationorigins. Previously, this was controlled by'max_replication_slots'. Having a separate GUC option provides betterflexibility for setting up subscribers, as they may not requirereplication slots (for cascading replication) but always requirereplication origins.Author: Euler Taveira <euler@eulerto.com>Reviewed-by: Amit Kapila <amit.kapila16@gmail.com>Reviewed-by: Masahiko Sawada <sawada.mshk@gmail.com>Reviewed-by: Peter Eisentraut <peter@eisentraut.org>Reviewed-by: vignesh C <vignesh21@gmail.com>Discussion:https://postgr.es/m/b81db436-8262-4575-b7c4-bc0c1551000b@app.fastmail.com
1 parent0e032a2 commit04ff636

File tree

12 files changed

+93
-93
lines changed

12 files changed

+93
-93
lines changed

‎doc/src/sgml/config.sgml

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4476,13 +4476,6 @@ restore_command = 'copy "C:\\server\\archivedir\\%f" "%p"' # Windows
44764476
to <literal>replica</literal> or higher to allow replication slots to
44774477
be used.
44784478
</para>
4479-
4480-
<para>
4481-
Note that this parameter also applies on the subscriber side, but with
4482-
a different meaning. See <xref linkend="guc-max-replication-slots-subscriber"/>
4483-
in <xref linkend="runtime-config-replication-subscriber"/> for more
4484-
details.
4485-
</para>
44864479
</listitem>
44874480
</varlistentry>
44884481

@@ -5228,10 +5221,10 @@ ANY <replaceable class="parameter">num_sync</replaceable> ( <replaceable class="
52285221

52295222
<variablelist>
52305223

5231-
<varlistentry id="guc-max-replication-slots-subscriber" xreflabel="max_replication_slots">
5232-
<term><varname>max_replication_slots</varname> (<type>integer</type>)
5224+
<varlistentry id="guc-max-active-replication-origins" xreflabel="max_active_replication_origins">
5225+
<term><varname>max_active_replication_origins</varname> (<type>integer</type>)
52335226
<indexterm>
5234-
<primary><varname>max_replication_slots</varname> configuration parameter</primary>
5227+
<primary><varname>max_active_replication_origins</varname> configuration parameter</primary>
52355228
<secondary>in a subscriber</secondary>
52365229
</indexterm>
52375230
</term>
@@ -5243,18 +5236,13 @@ ANY <replaceable class="parameter">num_sync</replaceable> ( <replaceable class="
52435236
be created on the server. Setting it to a lower value than the current
52445237
number of tracked replication origins (reflected in
52455238
<link linkend="view-pg-replication-origin-status">pg_replication_origin_status</link>)
5246-
will prevent the server from starting.
5247-
<literal>max_replication_slots</literal> must be set to at least the
5239+
will prevent the server from starting. It defaults to 10. This parameter
5240+
can only be set at server start.
5241+
5242+
<literal>max_active_replication_origins</literal> must be set to at least the
52485243
number of subscriptions that will be added to the subscriber, plus some
52495244
reserve for table synchronization.
52505245
</para>
5251-
5252-
<para>
5253-
Note that this parameter also applies on a sending server, but with
5254-
a different meaning. See <xref linkend="guc-max-replication-slots"/>
5255-
in <xref linkend="runtime-config-replication-sender"/> for more
5256-
details.
5257-
</para>
52585246
</listitem>
52595247
</varlistentry>
52605248

‎doc/src/sgml/logical-replication.sgml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2370,10 +2370,8 @@ CONTEXT: processing remote data for replication origin "pg_16395" during "INSER
23702370
<title>Configuration Settings</title>
23712371

23722372
<para>
2373-
Logical replication requires several configuration options to be set. Most
2374-
options are relevant only on one side of the replication. However,
2375-
<varname>max_replication_slots</varname> is used on both the publisher and
2376-
the subscriber, but it has a different meaning for each.
2373+
Logical replication requires several configuration options to be set. These
2374+
options are relevant only on one side of the replication.
23772375
</para>
23782376

23792377
<sect2 id="logical-replication-config-publisher">
@@ -2413,7 +2411,7 @@ CONTEXT: processing remote data for replication origin "pg_16395" during "INSER
24132411
<title>Subscribers</title>
24142412

24152413
<para>
2416-
<link linkend="guc-max-replication-slots-subscriber"><varname>max_replication_slots</varname></link>
2414+
<link linkend="guc-max-active-replication-origins"><varname>max_active_replication_origins</varname></link>
24172415
must be set to at least the number of subscriptions that will be added to
24182416
the subscriber, plus some reserve for table synchronization.
24192417
</para>
@@ -2580,7 +2578,7 @@ CONTEXT: processing remote data for replication origin "pg_16395" during "INSER
25802578
<listitem>
25812579
<para>
25822580
The new cluster must have
2583-
<link linkend="guc-max-replication-slots"><varname>max_replication_slots</varname></link>
2581+
<link linkend="guc-max-active-replication-origins"><varname>max_active_replication_origins</varname></link>
25842582
configured to a value greater than or equal to the number of
25852583
subscriptions present in the old cluster.
25862584
</para>

‎doc/src/sgml/ref/pg_createsubscriber.sgml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ PostgreSQL documentation
334334

335335
<para>
336336
The target server must be used as a physical standby. The target server
337-
must have <xref linkend="guc-max-replication-slots"/> and <xref
337+
must have <xref linkend="guc-max-active-replication-origins"/> and <xref
338338
linkend="guc-max-logical-replication-workers"/> configured to a value
339339
greater than or equal to the number of specified databases. The target
340340
server must have <xref linkend="guc-max-worker-processes"/> configured to a

‎src/backend/replication/logical/launcher.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
#include"postmaster/bgworker.h"
3232
#include"postmaster/interrupt.h"
3333
#include"replication/logicallauncher.h"
34-
#include"replication/slot.h"
34+
#include"replication/origin.h"
3535
#include"replication/walreceiver.h"
3636
#include"replication/worker_internal.h"
3737
#include"storage/ipc.h"
@@ -325,10 +325,10 @@ logicalrep_worker_launch(LogicalRepWorkerType wtype,
325325
subname)));
326326

327327
/* Report this after the initial starting message for consistency. */
328-
if (max_replication_slots==0)
328+
if (max_active_replication_origins==0)
329329
ereport(ERROR,
330330
(errcode(ERRCODE_CONFIGURATION_LIMIT_EXCEEDED),
331-
errmsg("cannot start logical replication workers when \"max_replication_slots\"=0")));
331+
errmsg("cannot start logical replication workers when \"max_active_replication_origins\"=0")));
332332

333333
/*
334334
* We need to do the modification of the shared memory under lock so that

‎src/backend/replication/logical/origin.c

Lines changed: 31 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@
9090
#include"storage/lmgr.h"
9191
#include"utils/builtins.h"
9292
#include"utils/fmgroids.h"
93+
#include"utils/guc.h"
9394
#include"utils/pg_lsn.h"
9495
#include"utils/rel.h"
9596
#include"utils/snapmgr.h"
@@ -99,6 +100,9 @@
99100
#definePG_REPLORIGIN_CHECKPOINT_FILENAME PG_LOGICAL_DIR "/replorigin_checkpoint"
100101
#definePG_REPLORIGIN_CHECKPOINT_TMPFILE PG_REPLORIGIN_CHECKPOINT_FILENAME ".tmp"
101102

103+
/* GUC variables */
104+
intmax_active_replication_origins=10;
105+
102106
/*
103107
* Replay progress of a single remote node.
104108
*/
@@ -151,7 +155,7 @@ typedef struct ReplicationStateCtl
151155
{
152156
/* Tranche to use for per-origin LWLocks */
153157
inttranche_id;
154-
/* Array of lengthmax_replication_slots */
158+
/* Array of lengthmax_active_replication_origins */
155159
ReplicationStatestates[FLEXIBLE_ARRAY_MEMBER];
156160
}ReplicationStateCtl;
157161

@@ -162,10 +166,7 @@ TimestampTz replorigin_session_origin_timestamp = 0;
162166

163167
/*
164168
* Base address into a shared memory array of replication states of size
165-
* max_replication_slots.
166-
*
167-
* XXX: Should we use a separate variable to size this rather than
168-
* max_replication_slots?
169+
* max_active_replication_origins.
169170
*/
170171
staticReplicationState*replication_states;
171172

@@ -186,12 +187,12 @@ static ReplicationState *session_replication_state = NULL;
186187
#defineREPLICATION_STATE_MAGIC ((uint32) 0x1257DADE)
187188

188189
staticvoid
189-
replorigin_check_prerequisites(boolcheck_slots,boolrecoveryOK)
190+
replorigin_check_prerequisites(boolcheck_origins,boolrecoveryOK)
190191
{
191-
if (check_slots&&max_replication_slots==0)
192+
if (check_origins&&max_active_replication_origins==0)
192193
ereport(ERROR,
193194
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
194-
errmsg("cannot query or manipulate replication origin when \"max_replication_slots\" is 0")));
195+
errmsg("cannot query or manipulate replication origin when \"max_active_replication_origins\" is 0")));
195196

196197
if (!recoveryOK&&RecoveryInProgress())
197198
ereport(ERROR,
@@ -352,7 +353,7 @@ replorigin_state_clear(RepOriginId roident, bool nowait)
352353
restart:
353354
LWLockAcquire(ReplicationOriginLock,LW_EXCLUSIVE);
354355

355-
for (i=0;i<max_replication_slots;i++)
356+
for (i=0;i<max_active_replication_origins;i++)
356357
{
357358
ReplicationState*state=&replication_states[i];
358359

@@ -511,18 +512,13 @@ ReplicationOriginShmemSize(void)
511512
{
512513
Sizesize=0;
513514

514-
/*
515-
* XXX: max_replication_slots is arguably the wrong thing to use, as here
516-
* we keep the replay state of *remote* transactions. But for now it seems
517-
* sufficient to reuse it, rather than introduce a separate GUC.
518-
*/
519-
if (max_replication_slots==0)
515+
if (max_active_replication_origins==0)
520516
returnsize;
521517

522518
size=add_size(size, offsetof(ReplicationStateCtl,states));
523519

524520
size=add_size(size,
525-
mul_size(max_replication_slots,sizeof(ReplicationState)));
521+
mul_size(max_active_replication_origins,sizeof(ReplicationState)));
526522
returnsize;
527523
}
528524

@@ -531,7 +527,7 @@ ReplicationOriginShmemInit(void)
531527
{
532528
boolfound;
533529

534-
if (max_replication_slots==0)
530+
if (max_active_replication_origins==0)
535531
return;
536532

537533
replication_states_ctl= (ReplicationStateCtl*)
@@ -548,7 +544,7 @@ ReplicationOriginShmemInit(void)
548544

549545
replication_states_ctl->tranche_id=LWTRANCHE_REPLICATION_ORIGIN_STATE;
550546

551-
for (i=0;i<max_replication_slots;i++)
547+
for (i=0;i<max_active_replication_origins;i++)
552548
{
553549
LWLockInitialize(&replication_states[i].lock,
554550
replication_states_ctl->tranche_id);
@@ -570,7 +566,7 @@ ReplicationOriginShmemInit(void)
570566
*
571567
* So its just the magic, followed by the statically sized
572568
* ReplicationStateOnDisk structs. Note that the maximum number of
573-
* ReplicationState is determined bymax_replication_slots.
569+
* ReplicationState is determined bymax_active_replication_origins.
574570
* ---------------------------------------------------------------------------
575571
*/
576572
void
@@ -583,7 +579,7 @@ CheckPointReplicationOrigin(void)
583579
uint32magic=REPLICATION_STATE_MAGIC;
584580
pg_crc32ccrc;
585581

586-
if (max_replication_slots==0)
582+
if (max_active_replication_origins==0)
587583
return;
588584

589585
INIT_CRC32C(crc);
@@ -625,7 +621,7 @@ CheckPointReplicationOrigin(void)
625621
LWLockAcquire(ReplicationOriginLock,LW_SHARED);
626622

627623
/* write actual data */
628-
for (i=0;i<max_replication_slots;i++)
624+
for (i=0;i<max_active_replication_origins;i++)
629625
{
630626
ReplicationStateOnDiskdisk_state;
631627
ReplicationState*curstate=&replication_states[i];
@@ -718,7 +714,7 @@ StartupReplicationOrigin(void)
718714
already_started= true;
719715
#endif
720716

721-
if (max_replication_slots==0)
717+
if (max_active_replication_origins==0)
722718
return;
723719

724720
INIT_CRC32C(crc);
@@ -728,8 +724,8 @@ StartupReplicationOrigin(void)
728724
fd=OpenTransientFile(path,O_RDONLY |PG_BINARY);
729725

730726
/*
731-
* might have hadmax_replication_slots == 0 last run, or we just brought
732-
* up a standby.
727+
* might have hadmax_active_replication_origins == 0 last run, or we just
728+
*broughtup a standby.
733729
*/
734730
if (fd<0&&errno==ENOENT)
735731
return;
@@ -796,10 +792,10 @@ StartupReplicationOrigin(void)
796792

797793
COMP_CRC32C(crc,&disk_state,sizeof(disk_state));
798794

799-
if (last_state==max_replication_slots)
795+
if (last_state==max_active_replication_origins)
800796
ereport(PANIC,
801797
(errcode(ERRCODE_CONFIGURATION_LIMIT_EXCEEDED),
802-
errmsg("could not find free replication state, increase \"max_replication_slots\"")));
798+
errmsg("could not find free replication state, increase \"max_active_replication_origins\"")));
803799

804800
/* copy data to shared memory */
805801
replication_states[last_state].roident=disk_state.roident;
@@ -852,7 +848,7 @@ replorigin_redo(XLogReaderState *record)
852848

853849
xlrec= (xl_replorigin_drop*)XLogRecGetData(record);
854850

855-
for (i=0;i<max_replication_slots;i++)
851+
for (i=0;i<max_active_replication_origins;i++)
856852
{
857853
ReplicationState*state=&replication_states[i];
858854

@@ -917,7 +913,7 @@ replorigin_advance(RepOriginId node,
917913
* Search for either an existing slot for the origin, or a free one we can
918914
* use.
919915
*/
920-
for (i=0;i<max_replication_slots;i++)
916+
for (i=0;i<max_active_replication_origins;i++)
921917
{
922918
ReplicationState*curstate=&replication_states[i];
923919

@@ -958,7 +954,7 @@ replorigin_advance(RepOriginId node,
958954
(errcode(ERRCODE_CONFIGURATION_LIMIT_EXCEEDED),
959955
errmsg("could not find free replication state slot for replication origin with ID %d",
960956
node),
961-
errhint("Increase \"max_replication_slots\" and try again.")));
957+
errhint("Increase \"max_active_replication_origins\" and try again.")));
962958

963959
if (replication_state==NULL)
964960
{
@@ -1024,7 +1020,7 @@ replorigin_get_progress(RepOriginId node, bool flush)
10241020
/* prevent slots from being concurrently dropped */
10251021
LWLockAcquire(ReplicationOriginLock,LW_SHARED);
10261022

1027-
for (i=0;i<max_replication_slots;i++)
1023+
for (i=0;i<max_active_replication_origins;i++)
10281024
{
10291025
ReplicationState*state;
10301026

@@ -1110,7 +1106,7 @@ replorigin_session_setup(RepOriginId node, int acquired_by)
11101106
registered_cleanup= true;
11111107
}
11121108

1113-
Assert(max_replication_slots>0);
1109+
Assert(max_active_replication_origins>0);
11141110

11151111
if (session_replication_state!=NULL)
11161112
ereport(ERROR,
@@ -1124,7 +1120,7 @@ replorigin_session_setup(RepOriginId node, int acquired_by)
11241120
* Search for either an existing slot for the origin, or a free one we can
11251121
* use.
11261122
*/
1127-
for (i=0;i<max_replication_slots;i++)
1123+
for (i=0;i<max_active_replication_origins;i++)
11281124
{
11291125
ReplicationState*curstate=&replication_states[i];
11301126

@@ -1159,7 +1155,7 @@ replorigin_session_setup(RepOriginId node, int acquired_by)
11591155
(errcode(ERRCODE_CONFIGURATION_LIMIT_EXCEEDED),
11601156
errmsg("could not find free replication state slot for replication origin with ID %d",
11611157
node),
1162-
errhint("Increase \"max_replication_slots\" and try again.")));
1158+
errhint("Increase \"max_active_replication_origins\" and try again.")));
11631159
elseif (session_replication_state==NULL)
11641160
{
11651161
/* initialize new slot */
@@ -1195,7 +1191,7 @@ replorigin_session_reset(void)
11951191
{
11961192
ConditionVariable*cv;
11971193

1198-
Assert(max_replication_slots!=0);
1194+
Assert(max_active_replication_origins!=0);
11991195

12001196
if (session_replication_state==NULL)
12011197
ereport(ERROR,
@@ -1536,7 +1532,7 @@ pg_show_replication_origin_status(PG_FUNCTION_ARGS)
15361532
* filled. Note that we do not take any locks, so slightly corrupted/out
15371533
* of date values are a possibility.
15381534
*/
1539-
for (i=0;i<max_replication_slots;i++)
1535+
for (i=0;i<max_active_replication_origins;i++)
15401536
{
15411537
ReplicationState*state;
15421538
Datumvalues[REPLICATION_ORIGIN_PROGRESS_COLS];

‎src/backend/utils/misc/guc_tables.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3374,6 +3374,18 @@ struct config_int ConfigureNamesInt[] =
33743374
NULL,NULL,NULL
33753375
},
33763376

3377+
{
3378+
{"max_active_replication_origins",
3379+
PGC_POSTMASTER,
3380+
REPLICATION_SUBSCRIBERS,
3381+
gettext_noop("Sets the maximum number of active replication origins."),
3382+
NULL
3383+
},
3384+
&max_active_replication_origins,
3385+
10,0,MAX_BACKENDS,
3386+
NULL,NULL,NULL
3387+
},
3388+
33773389
{
33783390
{"log_rotation_age",PGC_SIGHUP,LOGGING_WHERE,
33793391
gettext_noop("Sets the amount of time to wait before forcing "

‎src/backend/utils/misc/postgresql.conf.sample

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,8 @@
389389

390390
# These settings are ignored on a publisher.
391391

392+
#max_active_replication_origins = 10# max number of active replication origins
393+
# (change requires restart)
392394
#max_logical_replication_workers = 4# taken from max_worker_processes
393395
# (change requires restart)
394396
#max_sync_workers_per_subscription = 2# taken from max_logical_replication_workers

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp