Skip to content

Commit 7ba6e4f

Browse files
committed
Add monitoring function pg_last_xact_replay_timestamp.
Fujii Masao, with a little wordsmithing by me.
1 parent 844ed5d commit 7ba6e4f

File tree

5 files changed

+41
-1
lines changed

5 files changed

+41
-1
lines changed

doc/src/sgml/func.sgml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13551,6 +13551,9 @@ postgres=# SELECT * FROM pg_xlogfile_name_offset(pg_stop_backup());
1355113551
<indexterm>
1355213552
<primary>pg_last_xlog_replay_location</primary>
1355313553
</indexterm>
13554+
<indexterm>
13555+
<primary>pg_last_xact_replay_timestamp</primary>
13556+
</indexterm>
1355413557

1355513558
<para>
1355613559
The functions shown in <xref
@@ -13605,6 +13608,22 @@ postgres=# SELECT * FROM pg_xlogfile_name_offset(pg_stop_backup());
1360513608
the function returns NULL.
1360613609
</entry>
1360713610
</row>
13611+
<row>
13612+
<entry>
13613+
<literal><function>pg_last_xact_replay_timestamp()</function></literal>
13614+
</entry>
13615+
<entry><type>timestamp with time zone</type></entry>
13616+
<entry>Get timestamp of last transaction replayed during recovery.
13617+
This is the time at which the commit or abort WAL record for that
13618+
transaction was generated.
13619+
If no transactions have been replayed during recovery, this function
13620+
returns NULL. Otherwise, if recovery is still in progress this will
13621+
increase monotonically. If recovery has completed then this value will
13622+
remain static at the value of the last transaction applied during that
13623+
recovery. When the server has been started normally without recovery
13624+
the function returns NULL.
13625+
</entry>
13626+
</row>
1360813627
</tbody>
1360913628
</tgroup>
1361013629
</table>

src/backend/access/transam/xlog.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5604,6 +5604,24 @@ GetLatestXTime(void)
56045604
return xtime;
56055605
}
56065606

5607+
/*
5608+
* Returns timestamp of latest processed commit/abort record.
5609+
*
5610+
* When the server has been started normally without recovery the function
5611+
* returns NULL.
5612+
*/
5613+
Datum
5614+
pg_last_xact_replay_timestamp(PG_FUNCTION_ARGS)
5615+
{
5616+
TimestampTz xtime;
5617+
5618+
xtime = GetLatestXTime();
5619+
if (xtime == 0)
5620+
PG_RETURN_NULL();
5621+
5622+
PG_RETURN_TIMESTAMPTZ(xtime);
5623+
}
5624+
56075625
/*
56085626
* Returns bool with current recovery mode, a global state.
56095627
*/

src/include/access/xlog_internal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,7 @@ extern Datum pg_current_xlog_location(PG_FUNCTION_ARGS);
271271
extern Datum pg_current_xlog_insert_location(PG_FUNCTION_ARGS);
272272
extern Datum pg_last_xlog_receive_location(PG_FUNCTION_ARGS);
273273
extern Datum pg_last_xlog_replay_location(PG_FUNCTION_ARGS);
274+
extern Datum pg_last_xact_replay_timestamp(PG_FUNCTION_ARGS);
274275
extern Datum pg_xlogfile_name_offset(PG_FUNCTION_ARGS);
275276
extern Datum pg_xlogfile_name(PG_FUNCTION_ARGS);
276277
extern Datum pg_is_in_recovery(PG_FUNCTION_ARGS);

src/include/catalog/catversion.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,6 @@
5353
*/
5454

5555
/* yyyymmddN */
56-
#define CATALOG_VERSION_NO 201010301
56+
#define CATALOG_VERSION_NO 201011091
5757

5858
#endif

src/include/catalog/pg_proc.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3383,6 +3383,8 @@ DATA(insert OID = 3820 ( pg_last_xlog_receive_location PGNSP PGUID 12 1 0 0 f f
33833383
DESCR("current xlog flush location");
33843384
DATA(insert OID = 3821 ( pg_last_xlog_replay_location PGNSP PGUID 12 1 0 0 f f f t f v 0 0 25 "" _null_ _null_ _null_ _null_ pg_last_xlog_replay_location _null_ _null_ _null_ ));
33853385
DESCR("last xlog replay location");
3386+
DATA(insert OID = 3830 ( pg_last_xact_replay_timestamp PGNSP PGUID 12 1 0 0 f f f t f v 0 0 1184 "" _null_ _null_ _null_ _null_ pg_last_xact_replay_timestamp _null_ _null_ _null_ ));
3387+
DESCR("timestamp of last replay xact");
33863388

33873389
DATA(insert OID = 2621 ( pg_reload_conf PGNSP PGUID 12 1 0 0 f f f t f v 0 0 16 "" _null_ _null_ _null_ _null_ pg_reload_conf _null_ _null_ _null_ ));
33883390
DESCR("reload configuration files");

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