diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml index b851fe023a..df63201eb3 100644 --- a/doc/src/sgml/func.sgml +++ b/doc/src/sgml/func.sgml @@ -19329,7 +19329,8 @@ postgres=# SELECT * FROM pg_walfile_name_offset(pg_stop_backup()); Advances the current confirmed position of a replication slot named slot_name. The slot will not be moved backwards, and it will not be moved beyond the current insert location. Returns - name of the slot and real position to which it was advanced to. + name of the slot and real position to which it was advanced to, or + NULL if the slot could not be advanced. diff --git a/src/backend/replication/slotfuncs.c b/src/backend/replication/slotfuncs.c index d9e10263bb..cd8fc1560a 100644 --- a/src/backend/replication/slotfuncs.c +++ b/src/backend/replication/slotfuncs.c @@ -502,9 +502,17 @@ pg_replication_slot_advance(PG_FUNCTION_ARGS) ReplicationSlotRelease(); - /* Return the reached position. */ - values[1] = LSNGetDatum(endlsn); - nulls[1] = false; + /* + * Return the reached position, or NULL if the slot has not been + * advanced. + */ + if (XLogRecPtrIsInvalid(endlsn)) + nulls[1] = true; + else + { + values[1] = LSNGetDatum(endlsn); + nulls[1] = false; + } tuple = heap_form_tuple(tupdesc, values, nulls); result = HeapTupleGetDatum(tuple);