Skip to content

Commit 13aeaf0

Browse files
Add worker type to pg_stat_subscription.
Thanks to commit 2a8b40e, the logical replication worker type is easily determined. The worker type could already be deduced via other columns such as leader_pid and relid, but that is unnecessary complexity for users. Bumps catversion. Author: Peter Smith Reviewed-by: Michael Paquier, Maxim Orlov, Amit Kapila Discussion: https://postgr.es/m/CAHut%2BPtmbSMfErSk0S7xxVdZJ9XVE3xVLhqBTmT91kf57BeKDQ%40mail.gmail.com
1 parent 849d367 commit 13aeaf0

File tree

7 files changed

+37
-8
lines changed

7 files changed

+37
-8
lines changed

doc/src/sgml/monitoring.sgml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1993,6 +1993,17 @@ description | Waiting for a newly initialized WAL file to reach durable storage
19931993
</para></entry>
19941994
</row>
19951995

1996+
<row>
1997+
<entry role="catalog_table_entry"><para role="column_definition">
1998+
<structfield>worker_type</structfield> <type>text</type>
1999+
</para>
2000+
<para>
2001+
Type of the subscription worker process. Possible types are
2002+
<literal>apply</literal>, <literal>parallel apply</literal>, and
2003+
<literal>table synchronization</literal>.
2004+
</para></entry>
2005+
</row>
2006+
19962007
<row>
19972008
<entry role="catalog_table_entry"><para role="column_definition">
19982009
<structfield>pid</structfield> <type>integer</type>
@@ -2008,7 +2019,7 @@ description | Waiting for a newly initialized WAL file to reach durable storage
20082019
</para>
20092020
<para>
20102021
Process ID of the leader apply worker if this process is a parallel
2011-
apply worker; NULL if this process is a leader apply worker or a
2022+
apply worker; NULL if this process is a leader apply worker or a table
20122023
synchronization worker
20132024
</para></entry>
20142025
</row>

src/backend/catalog/system_views.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -949,6 +949,7 @@ CREATE VIEW pg_stat_subscription AS
949949
SELECT
950950
su.oid AS subid,
951951
su.subname,
952+
st.worker_type,
952953
st.pid,
953954
st.leader_pid,
954955
st.relid,

src/backend/replication/logical/launcher.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1278,7 +1278,7 @@ GetLeaderApplyWorkerPid(pid_t pid)
12781278
Datum
12791279
pg_stat_get_subscription(PG_FUNCTION_ARGS)
12801280
{
1281-
#define PG_STAT_GET_SUBSCRIPTION_COLS 9
1281+
#define PG_STAT_GET_SUBSCRIPTION_COLS 10
12821282
Oid subid = PG_ARGISNULL(0) ? InvalidOid : PG_GETARG_OID(0);
12831283
int i;
12841284
ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo;
@@ -1339,6 +1339,22 @@ pg_stat_get_subscription(PG_FUNCTION_ARGS)
13391339
else
13401340
values[8] = TimestampTzGetDatum(worker.reply_time);
13411341

1342+
switch (worker.type)
1343+
{
1344+
case WORKERTYPE_APPLY:
1345+
values[9] = CStringGetTextDatum("apply");
1346+
break;
1347+
case WORKERTYPE_PARALLEL_APPLY:
1348+
values[9] = CStringGetTextDatum("parallel apply");
1349+
break;
1350+
case WORKERTYPE_TABLESYNC:
1351+
values[9] = CStringGetTextDatum("table synchronization");
1352+
break;
1353+
case WORKERTYPE_UNKNOWN:
1354+
/* Should never happen. */
1355+
elog(ERROR, "unknown worker type");
1356+
}
1357+
13421358
tuplestore_putvalues(rsinfo->setResult, rsinfo->setDesc,
13431359
values, nulls);
13441360

src/include/catalog/catversion.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,6 @@
5757
*/
5858

5959
/* yyyymmddN */
60-
#define CATALOG_VERSION_NO 202309221
60+
#define CATALOG_VERSION_NO 202309251
6161

6262
#endif

src/include/catalog/pg_proc.dat

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5484,9 +5484,9 @@
54845484
proname => 'pg_stat_get_subscription', prorows => '10', proisstrict => 'f',
54855485
proretset => 't', provolatile => 's', proparallel => 'r',
54865486
prorettype => 'record', proargtypes => 'oid',
5487-
proallargtypes => '{oid,oid,oid,int4,int4,pg_lsn,timestamptz,timestamptz,pg_lsn,timestamptz}',
5488-
proargmodes => '{i,o,o,o,o,o,o,o,o,o}',
5489-
proargnames => '{subid,subid,relid,pid,leader_pid,received_lsn,last_msg_send_time,last_msg_receipt_time,latest_end_lsn,latest_end_time}',
5487+
proallargtypes => '{oid,oid,oid,int4,int4,pg_lsn,timestamptz,timestamptz,pg_lsn,timestamptz,text}',
5488+
proargmodes => '{i,o,o,o,o,o,o,o,o,o,o}',
5489+
proargnames => '{subid,subid,relid,pid,leader_pid,received_lsn,last_msg_send_time,last_msg_receipt_time,latest_end_lsn,latest_end_time,worker_type}',
54905490
prosrc => 'pg_stat_get_subscription' },
54915491
{ oid => '2026', descr => 'statistics: current backend PID',
54925492
proname => 'pg_backend_pid', provolatile => 's', proparallel => 'r',

src/test/regress/expected/rules.out

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2118,6 +2118,7 @@ pg_stat_ssl| SELECT pid,
21182118
WHERE (client_port IS NOT NULL);
21192119
pg_stat_subscription| SELECT su.oid AS subid,
21202120
su.subname,
2121+
st.worker_type,
21212122
st.pid,
21222123
st.leader_pid,
21232124
st.relid,
@@ -2127,7 +2128,7 @@ pg_stat_subscription| SELECT su.oid AS subid,
21272128
st.latest_end_lsn,
21282129
st.latest_end_time
21292130
FROM (pg_subscription su
2130-
LEFT JOIN pg_stat_get_subscription(NULL::oid) st(subid, relid, pid, leader_pid, received_lsn, last_msg_send_time, last_msg_receipt_time, latest_end_lsn, latest_end_time) ON ((st.subid = su.oid)));
2131+
LEFT JOIN pg_stat_get_subscription(NULL::oid) st(subid, relid, pid, leader_pid, received_lsn, last_msg_send_time, last_msg_receipt_time, latest_end_lsn, latest_end_time, worker_type) ON ((st.subid = su.oid)));
21312132
pg_stat_subscription_stats| SELECT ss.subid,
21322133
s.subname,
21332134
ss.apply_error_count,

src/test/subscription/t/004_sync.pl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080

8181
# wait for it to start
8282
$node_subscriber->poll_query_until('postgres',
83-
"SELECT pid IS NOT NULL FROM pg_stat_subscription WHERE subname = 'tap_sub2' AND relid IS NULL"
83+
"SELECT pid IS NOT NULL FROM pg_stat_subscription WHERE subname = 'tap_sub2' AND worker_type = 'apply'"
8484
) or die "Timed out while waiting for subscriber to start";
8585

8686
# and drop both subscriptions

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy