Hi all,

When attempting to use multiple times pg_replication_slot_advance on a
slot, then the caller gets back directly InvalidXLogRecPtr as result,
for example:
=# select * from pg_replication_slot_advance('popo', 'FF/0');
 slot_name |  end_lsn
-----------+-----------
 popo      | 0/60021E0
(1 row)
=# select * from pg_replication_slot_advance('popo', 'FF/0');
 slot_name | end_lsn
-----------+---------
 popo      | 0/0
(1 row)

Wouldn't it be more simple to return NULL to mean that the slot could
not be moved forward?  That would be easier to parse for clients.
Please see the attached.

Thanks,
--
Michael
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
         <parameter>slot_name</parameter>. 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
+        <literal>NULL</literal> if the slot could not be advanced.
        </entry>
       </row>
 
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);

Attachment: signature.asc
Description: PGP signature

Reply via email to