Skip to content

Commit c68100a

Browse files
committed
Allow pg_recvlogical --drop-slot to work without --dbname.
When pg_recvlogical was introduced in 9.4, the --dbname option was not required for --drop-slot. Without it, pg_recvlogical --drop-slot connected using a replication connection (not tied to a specific database) and was able to drop both physical and logical replication slots, similar to pg_receivewal --drop-slot. However, commit 0c013e0 unintentionally changed this behavior in 9.5, making pg_recvlogical always check whether it's connected to a specific database and fail if it's not. This change was expected for --create-slot and --start, which handle logical replication slots and require a database connection, but it was unnecessary for --drop-slot, which should work with any replication connection. As a result, --dbname became a required option for --drop-slot. This commit removes that restriction, restoring the original behavior and allowing pg_recvlogical --drop-slot to work without specifying --dbname. Although this issue originated from an unintended change, it has existed for a long time without complaints or bug reports, and the documentation never explicitly stated that --drop-slot should work without --dbname. Therefore, the change is not treated as a bug fix and is applied only to master. Author: Hayato Kuroda <kuroda.hayato@fujitsu.com> Reviewed-by: Fujii Masao <masao.fujii@gmail.com> Discussion: https://postgr.es/m/b15ecf4f-e5af-4fbb-82c2-a425f453e0b2@oss.nttdata.com
1 parent dfc1342 commit c68100a

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

src/bin/pg_basebackup/pg_recvlogical.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -944,13 +944,16 @@ main(int argc, char **argv)
944944
#endif
945945

946946
/*
947-
* Run IDENTIFY_SYSTEM to make sure we connected using a database specific
948-
* replication connection.
947+
* Run IDENTIFY_SYSTEM to check the connection type for each action.
948+
* --create-slot and --start actions require a database-specific
949+
* replication connection because they handle logical replication slots.
950+
* --drop-slot can remove replication slots from any replication
951+
* connection without this restriction.
949952
*/
950953
if (!RunIdentifySystem(conn, NULL, NULL, NULL, &db_name))
951954
exit(1);
952955

953-
if (db_name == NULL)
956+
if (!do_drop_slot && db_name == NULL)
954957
pg_fatal("could not establish database-specific replication connection");
955958

956959
/*

src/bin/pg_basebackup/t/030_pg_recvlogical.pl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,4 +127,12 @@
127127
],
128128
'replayed a two-phase transaction');
129129

130+
$node->command_ok(
131+
[
132+
'pg_recvlogical',
133+
'--slot' => 'test',
134+
'--drop-slot'
135+
],
136+
'drop could work without dbname');
137+
130138
done_testing();

0 commit comments

Comments
 (0)