Hi, As discussed in the thread that introduced d140f2f3 to rename receivedUpto to flushedUpto and add writtenUpto to the WAL receiver's shared memory information, the equivalent columns in pg_stat_wal_receiver have not been renamed: https://www.postgresql.org/message-id/ca+hukgj06d3h5jeotav4h52n0vg1jopzxqmcn5fysjquvza...@mail.gmail.com
When I have implemented this system view, the idea was to keep a one-one mapping between the SQL interface and the shmem info even if we are not compatible with past versions, hence I think that before beta1 we had better fix that and: - rename received_lsn to flushed_lsn. - add one column for writtenUpto. Attached is a patch to do that. This needs also a catalog version bump, and I am adding an open item. Thanks, -- Michael
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat index 9edae40ed8..24d8128339 100644 --- a/src/include/catalog/pg_proc.dat +++ b/src/include/catalog/pg_proc.dat @@ -5244,9 +5244,9 @@ { oid => '3317', descr => 'statistics: information about WAL receiver', proname => 'pg_stat_get_wal_receiver', proisstrict => 'f', provolatile => 's', proparallel => 'r', prorettype => 'record', proargtypes => '', - proallargtypes => '{int4,text,pg_lsn,int4,pg_lsn,int4,timestamptz,timestamptz,pg_lsn,timestamptz,text,text,int4,text}', - proargmodes => '{o,o,o,o,o,o,o,o,o,o,o,o,o,o}', - proargnames => '{pid,status,receive_start_lsn,receive_start_tli,received_lsn,received_tli,last_msg_send_time,last_msg_receipt_time,latest_end_lsn,latest_end_time,slot_name,sender_host,sender_port,conninfo}', + proallargtypes => '{int4,text,pg_lsn,int4,pg_lsn,int4,timestamptz,timestamptz,pg_lsn,timestamptz,text,text,int4,text,pg_lsn}', + proargmodes => '{o,o,o,o,o,o,o,o,o,o,o,o,o,o,o}', + proargnames => '{pid,status,receive_start_lsn,receive_start_tli,flushed_lsn,received_tli,last_msg_send_time,last_msg_receipt_time,latest_end_lsn,latest_end_time,slot_name,sender_host,sender_port,conninfo,written_lsn}', prosrc => 'pg_stat_get_wal_receiver' }, { oid => '6118', descr => 'statistics: information about subscription', proname => 'pg_stat_get_subscription', proisstrict => 'f', provolatile => 's', diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index 2bd5f5ea14..20669da784 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -812,7 +812,7 @@ CREATE VIEW pg_stat_wal_receiver AS s.status, s.receive_start_lsn, s.receive_start_tli, - s.received_lsn, + s.flushed_lsn, s.received_tli, s.last_msg_send_time, s.last_msg_receipt_time, @@ -821,7 +821,8 @@ CREATE VIEW pg_stat_wal_receiver AS s.slot_name, s.sender_host, s.sender_port, - s.conninfo + s.conninfo, + s.written_lsn FROM pg_stat_get_wal_receiver() s WHERE s.pid IS NOT NULL; diff --git a/src/backend/replication/walreceiver.c b/src/backend/replication/walreceiver.c index d69fb90132..e26394c7ef 100644 --- a/src/backend/replication/walreceiver.c +++ b/src/backend/replication/walreceiver.c @@ -1348,7 +1348,8 @@ pg_stat_get_wal_receiver(PG_FUNCTION_ARGS) WalRcvState state; XLogRecPtr receive_start_lsn; TimeLineID receive_start_tli; - XLogRecPtr received_lsn; + XLogRecPtr flushed_lsn; + XLogRecPtr written_lsn; TimeLineID received_tli; TimestampTz last_send_time; TimestampTz last_receipt_time; @@ -1366,7 +1367,8 @@ pg_stat_get_wal_receiver(PG_FUNCTION_ARGS) state = WalRcv->walRcvState; receive_start_lsn = WalRcv->receiveStart; receive_start_tli = WalRcv->receiveStartTLI; - received_lsn = WalRcv->flushedUpto; + flushed_lsn = WalRcv->flushedUpto; + written_lsn = pg_atomic_read_u64(&WalRcv->writtenUpto); received_tli = WalRcv->receivedTLI; last_send_time = WalRcv->lastMsgSendTime; last_receipt_time = WalRcv->lastMsgReceiptTime; @@ -1413,10 +1415,10 @@ pg_stat_get_wal_receiver(PG_FUNCTION_ARGS) else values[2] = LSNGetDatum(receive_start_lsn); values[3] = Int32GetDatum(receive_start_tli); - if (XLogRecPtrIsInvalid(received_lsn)) + if (XLogRecPtrIsInvalid(flushed_lsn)) nulls[4] = true; else - values[4] = LSNGetDatum(received_lsn); + values[4] = LSNGetDatum(flushed_lsn); values[5] = Int32GetDatum(received_tli); if (last_send_time == 0) nulls[6] = true; @@ -1450,6 +1452,10 @@ pg_stat_get_wal_receiver(PG_FUNCTION_ARGS) nulls[13] = true; else values[13] = CStringGetTextDatum(conninfo); + if (XLogRecPtrIsInvalid(written_lsn)) + nulls[14] = true; + else + values[14] = LSNGetDatum(written_lsn); } /* Returns the record as Datum */ diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index 8876025aaa..db29058f47 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -2124,7 +2124,7 @@ pg_stat_wal_receiver| SELECT s.pid, s.status, s.receive_start_lsn, s.receive_start_tli, - s.received_lsn, + s.flushed_lsn, s.received_tli, s.last_msg_send_time, s.last_msg_receipt_time, @@ -2133,8 +2133,9 @@ pg_stat_wal_receiver| SELECT s.pid, s.slot_name, s.sender_host, s.sender_port, - s.conninfo - FROM pg_stat_get_wal_receiver() s(pid, status, receive_start_lsn, receive_start_tli, received_lsn, received_tli, last_msg_send_time, last_msg_receipt_time, latest_end_lsn, latest_end_time, slot_name, sender_host, sender_port, conninfo) + s.conninfo, + s.written_lsn + FROM pg_stat_get_wal_receiver() s(pid, status, receive_start_lsn, receive_start_tli, flushed_lsn, received_tli, last_msg_send_time, last_msg_receipt_time, latest_end_lsn, latest_end_time, slot_name, sender_host, sender_port, conninfo, written_lsn) WHERE (s.pid IS NOT NULL); pg_stat_xact_all_tables| SELECT c.oid AS relid, n.nspname AS schemaname, diff --git a/doc/src/sgml/monitoring.sgml b/doc/src/sgml/monitoring.sgml index 87502a49b6..7ee1abb0e3 100644 --- a/doc/src/sgml/monitoring.sgml +++ b/doc/src/sgml/monitoring.sgml @@ -2508,7 +2508,7 @@ SELECT pid, wait_event_type, wait_event FROM pg_stat_activity WHERE wait_event i <row> <entry role="catalog_table_entry"><para role="column_definition"> - <structfield>received_lsn</structfield> <type>pg_lsn</type> + <structfield>flushed_lsn</structfield> <type>pg_lsn</type> </para> <para> Last write-ahead log location already received and flushed to @@ -2605,6 +2605,17 @@ SELECT pid, wait_event_type, wait_event FROM pg_stat_activity WHERE wait_event i with security-sensitive fields obfuscated. </para></entry> </row> + + <row> + <entry role="catalog_table_entry"><para role="column_definition"> + <structfield>written_lsn</structfield> <type>pg_lsn</type> + </para> + <para> + Last write-ahead log location already received and written to + disk. This is similar to <literal>flushed_lsn</literal>, but it + cannot be used for data integrity checks. + </para></entry> + </row> </tbody> </tgroup> </table>
signature.asc
Description: PGP signature