From d0abe78d84274cc203f3d117b8006dc2164ca31a Mon Sep 17 00:00:00 2001 From: Alvaro Herrera Date: Tue, 28 Apr 2020 20:39:04 -0400 Subject: Check slot->restart_lsn validity in a few more places MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Lack of these checks could cause visible misbehavior, including assertion failures. This was missed in commit c6550776394e, whereby restart_lsn becomes invalid when the size limit is exceeded. Also reword some existing error messages, and add errdetail(), so that the reported errors all match in spirit. Author: Kyotaro Horiguchi Reviewed-by: Álvaro Herrera Discussion: https://postgr.es/m/20200408.093710.447591748588426656.horikyota.ntt@gmail.com --- src/backend/replication/logical/logicalfuncs.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/backend/replication/logical/logicalfuncs.c') diff --git a/src/backend/replication/logical/logicalfuncs.c b/src/backend/replication/logical/logicalfuncs.c index f5384f1df8c..fded8e82908 100644 --- a/src/backend/replication/logical/logicalfuncs.c +++ b/src/backend/replication/logical/logicalfuncs.c @@ -237,6 +237,19 @@ pg_logical_slot_get_changes_guts(FunctionCallInfo fcinfo, bool confirm, bool bin LogicalOutputPrepareWrite, LogicalOutputWrite, NULL); + /* + * After the sanity checks in CreateDecodingContext, make sure the + * restart_lsn is valid. Avoid "cannot get changes" wording in this + * errmsg because that'd be confusingly ambiguous about no changes + * being available. + */ + if (XLogRecPtrIsInvalid(MyReplicationSlot->data.restart_lsn)) + ereport(ERROR, + (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), + errmsg("can no longer get changes from replication slot \"%s\"", + NameStr(*name)), + errdetail("This slot has never previously reserved WAL, or has been invalidated."))); + MemoryContextSwitchTo(oldcontext); /* -- cgit v1.2.3