Skip to content

Commit ecc6def

Browse files
DorukCommitfest Bot
Doruk
authored and
Commitfest Bot
committed
pg_replication_origin_session_setup: pid parameter
Since the introduction of parallel apply workers (commit 216a784), the replorigin_session_setup() was extended to accept an extra parameter: pid. This process ID is used to inform that multiple processes are sharing the same replication origin to apply changes in parallel. The replorigin_session_setup function has a SQL user interface: pg_replication_origin_session_setup. This commit adds an optional parameter that passes the process ID to the internal function replorigin_session_setup. It allows multiple processes to use the same replication origin if you are using the replication functions.
1 parent 0dca5d6 commit ecc6def

File tree

4 files changed

+19
-4
lines changed

4 files changed

+19
-4
lines changed

doc/src/sgml/func.sgml

+7-1
Original file line numberDiff line numberDiff line change
@@ -29786,14 +29786,20 @@ postgres=# SELECT '0/0'::pg_lsn + pd.segment_number * ps.setting::int + :offset
2978629786
<indexterm>
2978729787
<primary>pg_replication_origin_session_setup</primary>
2978829788
</indexterm>
29789-
<function>pg_replication_origin_session_setup</function> ( <parameter>node_name</parameter> <type>text</type> )
29789+
<function>pg_replication_origin_session_setup</function> ( <parameter>node_name</parameter> <type>text</type> <optional>, <parameter>pid</parameter> <type>integer</type> <literal>DEFAULT</literal> <literal>0</literal></optional> )
2979029790
<returnvalue>void</returnvalue>
2979129791
</para>
2979229792
<para>
2979329793
Marks the current session as replaying from the given
2979429794
origin, allowing replay progress to be tracked.
2979529795
Can only be used if no origin is currently selected.
2979629796
Use <function>pg_replication_origin_session_reset</function> to undo.
29797+
If multiple processes can safely use the same replication origin (for
29798+
example, parallel apply processes), the optional <parameter>pid</parameter>
29799+
parameter can be used to specify the process ID of the first process.
29800+
The first process must provide <parameter>pid</parameter> equals to
29801+
<literal>0</literal> and the other processes that share the same
29802+
replication origin should provide the process ID of the first process.
2979729803
</para></entry>
2979829804
</row>
2979929805

src/backend/catalog/system_functions.sql

+8-1
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,13 @@ LANGUAGE INTERNAL
650650
CALLED ON NULL INPUT VOLATILE PARALLEL SAFE
651651
AS 'pg_stat_reset_slru';
652652

653+
CREATE OR REPLACE FUNCTION
654+
pg_replication_origin_session_setup(node_name text, pid integer DEFAULT 0)
655+
RETURNS void
656+
LANGUAGE INTERNAL
657+
STRICT VOLATILE
658+
AS 'pg_replication_origin_session_setup';
659+
653660
--
654661
-- The default permissions for functions mean that anyone can execute them.
655662
-- A number of functions shouldn't be executable by just anyone, but rather
@@ -751,7 +758,7 @@ REVOKE EXECUTE ON FUNCTION pg_replication_origin_session_progress(boolean) FROM
751758

752759
REVOKE EXECUTE ON FUNCTION pg_replication_origin_session_reset() FROM public;
753760

754-
REVOKE EXECUTE ON FUNCTION pg_replication_origin_session_setup(text) FROM public;
761+
REVOKE EXECUTE ON FUNCTION pg_replication_origin_session_setup(text, integer) FROM public;
755762

756763
REVOKE EXECUTE ON FUNCTION pg_replication_origin_xact_reset() FROM public;
757764

src/backend/replication/logical/origin.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -1351,12 +1351,14 @@ pg_replication_origin_session_setup(PG_FUNCTION_ARGS)
13511351
{
13521352
char *name;
13531353
RepOriginId origin;
1354+
int pid;
13541355

13551356
replorigin_check_prerequisites(true, false);
13561357

13571358
name = text_to_cstring((text *) DatumGetPointer(PG_GETARG_DATUM(0)));
13581359
origin = replorigin_by_name(name, false);
1359-
replorigin_session_setup(origin, 0);
1360+
pid = PG_GETARG_INT32(1);
1361+
replorigin_session_setup(origin, pid);
13601362

13611363
replorigin_session_origin = origin;
13621364

src/include/catalog/pg_proc.dat

+1-1
Original file line numberDiff line numberDiff line change
@@ -12152,7 +12152,7 @@
1215212152
{ oid => '6006',
1215312153
descr => 'configure session to maintain replication progress tracking for the passed in origin',
1215412154
proname => 'pg_replication_origin_session_setup', provolatile => 'v',
12155-
proparallel => 'u', prorettype => 'void', proargtypes => 'text',
12155+
proparallel => 'u', prorettype => 'void', proargtypes => 'text int4',
1215612156
prosrc => 'pg_replication_origin_session_setup' },
1215712157

1215812158
{ oid => '6007', descr => 'teardown configured replication progress tracking',

0 commit comments

Comments
 (0)