public inbox for [email protected]  
help / color / mirror / Atom feed
From: Hayato Kuroda (Fujitsu) <[email protected]>
To: Hayato Kuroda (Fujitsu) <[email protected]>
Cc: '[email protected]' <[email protected]>
Cc: 'Michael Paquier' <[email protected]>
Subject: RE: ReplicationSlotRelease() crashes when the instance is in the single user mode
Date: Wed, 19 Feb 2025 02:57:34 +0000
Message-ID: <OSCPR01MB14966F234CD3121F51810D5CCF5C52@OSCPR01MB14966.jpnprd01.prod.outlook.com> (raw)
In-Reply-To: <OSCPR01MB14966559522B9699E1F769128F5FA2@OSCPR01MB14966.jpnprd01.prod.outlook.com>
References: <OSCPR01MB14966ED588A0328DAEBE8CB25F5FA2@OSCPR01MB14966.jpnprd01.prod.outlook.com>
	<[email protected]>
	<OSCPR01MB149669EF7D087A588773B7E04F5FA2@OSCPR01MB14966.jpnprd01.prod.outlook.com>
	<[email protected]>
	<OSCPR01MB14966559522B9699E1F769128F5FA2@OSCPR01MB14966.jpnprd01.prod.outlook.com>

Dear hackers,

Based on the discussion, I feel it is enough to add quick error out for SQL functions. PSA attached.

Best regards,
Hayato Kuroda
FUJITSU LIMITED

> -----Original Message-----
> From: Hayato Kuroda (Fujitsu) <[email protected]>
> Sent: Tuesday, February 18, 2025 5:24 PM
> To: 'Michael Paquier' <[email protected]>
> Cc: '[email protected]' <[email protected]>
> Subject: RE: ReplicationSlotRelease() crashes when the instance is in the single
> user mode
> 
> Dear Michael,
> 
> > Ah, good point for the slot drop.  So 0ce5cf2ef24f is claiming that
> > some of these manipulations are OK.  I didn't suspect this one.
> 
> Yeah, I think so.
> 
> > Slot advancing is a very different beast, unfortunately, that may
> > depend on many other subsystems.  For example with logical slots we
> > would finish by calling rm_decode, which could be outside of core.
> > Justifying that this operation is supported in single-user mode is
> > larger than what you are suggesting here..
> 
> OK. Actually, I do not have any use-cases in my mind. I played because
> I found a special path for single user mode in ReplicationSlotAcquire()
> so that I wanted to see the behavior.
> 
> Best regards,
> Hayato Kuroda
> FUJITSU LIMITED
> 
> 



Attachments:

  [application/octet-stream] 0001-Prohibit-slot-operations-while-in-the-single-user-mo.patch (2.3K, ../OSCPR01MB14966F234CD3121F51810D5CCF5C52@OSCPR01MB14966.jpnprd01.prod.outlook.com/2-0001-Prohibit-slot-operations-while-in-the-single-user-mo.patch)
  download | inline diff:
From eb72e5e921388fcdacc4d54f89c8d308180acc74 Mon Sep 17 00:00:00 2001
From: Hayato Kuroda <[email protected]>
Date: Wed, 19 Feb 2025 11:37:26 +0900
Subject: [PATCH] Prohibit slot operations while in the single user mode

---
 src/backend/replication/slotfuncs.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/src/backend/replication/slotfuncs.c b/src/backend/replication/slotfuncs.c
index 8be4b8c65b..cbfadfa428 100644
--- a/src/backend/replication/slotfuncs.c
+++ b/src/backend/replication/slotfuncs.c
@@ -17,6 +17,7 @@
 #include "access/xlogrecovery.h"
 #include "access/xlogutils.h"
 #include "funcapi.h"
+#include "miscadmin.h"
 #include "replication/logical.h"
 #include "replication/slot.h"
 #include "replication/slotsync.h"
@@ -73,6 +74,10 @@ pg_create_physical_replication_slot(PG_FUNCTION_ARGS)
 	HeapTuple	tuple;
 	Datum		result;
 
+	if (!IsUnderPostmaster)
+		elog(ERROR,
+			 "slot operation is prohibited in the single user mode");
+	
 	if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
 		elog(ERROR, "return type must be a row type");
 
@@ -179,6 +184,11 @@ pg_create_logical_replication_slot(PG_FUNCTION_ARGS)
 	Datum		values[2];
 	bool		nulls[2];
 
+	if (!IsUnderPostmaster)
+		elog(ERROR,
+			 "slot operation is prohibited in the single user mode");
+
+
 	if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
 		elog(ERROR, "return type must be a row type");
 
@@ -515,6 +525,10 @@ pg_replication_slot_advance(PG_FUNCTION_ARGS)
 
 	Assert(!MyReplicationSlot);
 
+	if (!IsUnderPostmaster)
+		elog(ERROR,
+			 "slot operation is prohibited in the single user mode");
+
 	CheckSlotPermissions();
 
 	if (XLogRecPtrIsInvalid(moveto))
@@ -612,6 +626,11 @@ copy_replication_slot(FunctionCallInfo fcinfo, bool logical_slot)
 	TupleDesc	tupdesc;
 	HeapTuple	tuple;
 
+	if (!IsUnderPostmaster)
+		elog(ERROR,
+			 "slot operation is prohibited in the single user mode");
+
+
 	if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
 		elog(ERROR, "return type must be a row type");
 
@@ -866,6 +885,10 @@ pg_sync_replication_slots(PG_FUNCTION_ARGS)
 	char	   *err;
 	StringInfoData app_name;
 
+	if (!IsUnderPostmaster)
+		elog(ERROR,
+			 "slot operation is prohibited in the single user mode");
+	
 	CheckSlotPermissions();
 
 	if (!RecoveryInProgress())
-- 
2.43.5



view thread (31+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected], [email protected]
  Subject: RE: ReplicationSlotRelease() crashes when the instance is in the single user mode
  In-Reply-To: <OSCPR01MB14966F234CD3121F51810D5CCF5C52@OSCPR01MB14966.jpnprd01.prod.outlook.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox