Hello again, On Tue, Aug 13, 2024 at 12:48 AM Euler Taveira <eu...@eulerto.com> wrote: > I'm curious about your use case. Is it just because the internal function has > a > different signature or your tool is capable of apply logical replication > changes > in parallel using the SQL API?
The latter is correct, it applies logical replication changes in parallel. Since multiple connections may commit, we need all of them to be able to advance the replication origin. > * no documentation changes. Since the function you are changing has a new > signature, this change should be reflected in the documentation. > * no need for a new internal function. The second parameter (PID) can be > optional and defaults to 0 in this case. See how we changed the > pg_create_logical_replication_slot along the years add some IN parameters like > twophase and failover in the recent versions. I updated/rewrote the patch to reflect these suggestions. It now has the same DEFAULT 0 style used in pg_create_logical_replication_slot. I also updated the documentation. > * add a CF entry [1] for this patch so we don't forget it. Another advantage > is > that this patch is covered by CI [2][3]. Sadly I still can't log in to the Commitfest due to the cool-off period. I will create an entry as soon as this period ends. Thanks for all the feedback, Doruk Yılmaz
From b9c54f3d217f67c24ce74ffa7c1f2812d784333e Mon Sep 17 00:00:00 2001 From: Doruk <do...@mixrank.com> Date: Thu, 15 Aug 2024 23:34:26 +0300 Subject: [PATCH] add new parameter to pg_replication_origin_session_setup --- doc/src/sgml/func.sgml | 2 +- src/backend/catalog/system_functions.sql | 9 ++++++++- src/backend/replication/logical/origin.c | 8 +++++--- src/include/catalog/pg_proc.dat | 2 +- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml index 5dd95d73a1..7db5a8ed52 100644 --- a/doc/src/sgml/func.sgml +++ b/doc/src/sgml/func.sgml @@ -29486,7 +29486,7 @@ DETAIL: Make sure pg_wal_replay_wait() isn't called within a transaction with a <indexterm> <primary>pg_replication_origin_session_setup</primary> </indexterm> - <function>pg_replication_origin_session_setup</function> ( <parameter>node_name</parameter> <type>text</type> ) + <function>pg_replication_origin_session_setup</function> ( <parameter>node_name</parameter> <type>text</type>, <parameter>acquired_by</parameter> <type>integer</type> <literal>DEFAULT</literal> <literal>0</literal> ) <returnvalue>void</returnvalue> </para> <para> diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql index 623b9539b1..4aae06e06d 100644 --- a/src/backend/catalog/system_functions.sql +++ b/src/backend/catalog/system_functions.sql @@ -639,6 +639,13 @@ LANGUAGE INTERNAL CALLED ON NULL INPUT VOLATILE PARALLEL SAFE AS 'pg_stat_reset_slru'; +CREATE OR REPLACE FUNCTION + pg_replication_origin_session_setup(node_name text, acquired_by integer DEFAULT 0) +RETURNS void +LANGUAGE INTERNAL +STRICT VOLATILE +AS 'pg_replication_origin_session_setup'; + -- -- The default permissions for functions mean that anyone can execute them. -- A number of functions shouldn't be executable by just anyone, but rather @@ -736,7 +743,7 @@ REVOKE EXECUTE ON FUNCTION pg_replication_origin_session_progress(boolean) FROM REVOKE EXECUTE ON FUNCTION pg_replication_origin_session_reset() FROM public; -REVOKE EXECUTE ON FUNCTION pg_replication_origin_session_setup(text) FROM public; +REVOKE EXECUTE ON FUNCTION pg_replication_origin_session_setup(text,integer) FROM public; REVOKE EXECUTE ON FUNCTION pg_replication_origin_xact_reset() FROM public; diff --git a/src/backend/replication/logical/origin.c b/src/backend/replication/logical/origin.c index 419e4814f0..e50bcc8466 100644 --- a/src/backend/replication/logical/origin.c +++ b/src/backend/replication/logical/origin.c @@ -1351,13 +1351,15 @@ pg_replication_origin_session_setup(PG_FUNCTION_ARGS) { char *name; RepOriginId origin; - + int pid; + replorigin_check_prerequisites(true, false); name = text_to_cstring((text *) DatumGetPointer(PG_GETARG_DATUM(0))); origin = replorigin_by_name(name, false); - replorigin_session_setup(origin, 0); - + pid = PG_GETARG_INT32(1); + replorigin_session_setup(origin, pid); + replorigin_session_origin = origin; pfree(name); diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat index 4abc6d9526..a490d4fc6e 100644 --- a/src/include/catalog/pg_proc.dat +++ b/src/include/catalog/pg_proc.dat @@ -11948,7 +11948,7 @@ { oid => '6006', descr => 'configure session to maintain replication progress tracking for the passed in origin', proname => 'pg_replication_origin_session_setup', provolatile => 'v', - proparallel => 'u', prorettype => 'void', proargtypes => 'text', + proparallel => 'u', prorettype => 'void', proargtypes => 'text int4', prosrc => 'pg_replication_origin_session_setup' }, { oid => '6007', descr => 'teardown configured replication progress tracking', -- 2.39.2