Contents
pg_last_committed_xact()
A function returning the commit timestamp of the latest transaction
pg_last_committed_xact()
is a system function returning the commit timestamp of the latest committed transaction.
pg_last_committed_xact()
was added in PostgreSQL 9.5.
Usage
pg_last_committed_xact () → record (xid
xid
,timestamp
timestamp with time zone
)
track_commit_timestamp
must be enabled for pg_last_committed_xact()
to work.
Change history
- PostgreSQL 9.5
- added (commit 73c986ad)
Examples
Usage example for pg_last_committed_xact()
:
postgres=# SELECT xid, timestamp FROM pg_last_committed_xact(); xid | timestamp -----+------------------------------- 744 | 2021-07-07 09:07:37.811665+01 (1 row) postgres=# INSERT INTO xact_test VALUES (4, 'boo'); INSERT 0 1 postgres=# SELECT xid, timestamp FROM pg_last_committed_xact(); xid | timestamp -----+------------------------------- 745 | 2021-07-07 09:07:43.036451+01 (1 row)
On a freshly started system where no commits have yet taken place, NULL
values will be returned:
postgres=# SELECT xid, timestamp FROM pg_last_committed_xact(); xid | timestamp -----+----------- | (1 row)
If track_commit_timestamp
is set to off
, pg_last_committed_xact()
will fail with an ERROR
:
postgres=# SELECT xid, timestamp FROM pg_last_committed_xact(); ERROR: could not get commit timestamp data HINT: Make sure the configuration parameter "track_commit_timestamp" is set.
References
- PostgreSQL documentation: Committed Transaction Information Functions