File tree Expand file tree Collapse file tree 3 files changed +20
-3
lines changed Expand file tree Collapse file tree 3 files changed +20
-3
lines changed Original file line number Diff line number Diff line change @@ -1683,6 +1683,11 @@ def archive_wal(args):
1683
1683
help = "create the replication slot, if it does not exist" ,
1684
1684
action = "store_true" ,
1685
1685
),
1686
+ argument (
1687
+ "--if-not-exists" ,
1688
+ help = "Do not error out when --create-slot is specified and a slot with the specified name already exists." ,
1689
+ action = "store_true" ,
1690
+ ),
1686
1691
argument (
1687
1692
"--drop-slot" ,
1688
1693
help = "drop the replication slot, if it exists" ,
@@ -1714,7 +1719,7 @@ def receive_wal(args):
1714
1719
server .kill ("receive-wal" )
1715
1720
elif args .create_slot :
1716
1721
with closing (server ):
1717
- server .create_physical_repslot ()
1722
+ server .create_physical_repslot (ignore_duplicate = args . if_not_exists )
1718
1723
elif args .drop_slot :
1719
1724
with closing (server ):
1720
1725
server .drop_repslot ()
Original file line number Diff line number Diff line change @@ -2809,7 +2809,7 @@ def archive_wal(self, verbose=True):
2809
2809
"on server %s. Skipping to the next server" % self .config .name
2810
2810
)
2811
2811
2812
- def create_physical_repslot (self ):
2812
+ def create_physical_repslot (self , ignore_duplicate = False ):
2813
2813
"""
2814
2814
Create a physical replication slot using the streaming connection
2815
2815
"""
@@ -2852,7 +2852,11 @@ def create_physical_repslot(self):
2852
2852
self .streaming .create_physical_repslot (self .config .slot_name )
2853
2853
output .info ("Replication slot '%s' created" , self .config .slot_name )
2854
2854
except PostgresDuplicateReplicationSlot :
2855
- output .error ("Replication slot '%s' already exists" , self .config .slot_name )
2855
+ args = "Replication slot '%s' already exists" , self .config .slot_name
2856
+ if ignore_duplicate :
2857
+ output .info (* args )
2858
+ else :
2859
+ output .error (* args )
2856
2860
except PostgresReplicationSlotsFull :
2857
2861
output .error (
2858
2862
"All replication slots for server '%s' are in use\n "
Original file line number Diff line number Diff line change @@ -1953,6 +1953,14 @@ def test_create_physical_repslot(self, capsys):
1953
1953
out , err = capsys .readouterr ()
1954
1954
assert "Replication slot 'test_repslot' already exists" in err
1955
1955
1956
+ # If the replication slot was already created but duplicates are ignored
1957
+ # check that no error is reported
1958
+ create_physical_repslot .side_effect = PostgresDuplicateReplicationSlot
1959
+ server .create_physical_repslot (ignore_duplicate = True )
1960
+ create_physical_repslot .assert_called_with ("test_repslot" )
1961
+ out , err = capsys .readouterr ()
1962
+ assert not err
1963
+
1956
1964
# Test the method failure if the replication slots
1957
1965
# on the server are all taken
1958
1966
create_physical_repslot .side_effect = PostgresReplicationSlotsFull
You can’t perform that action at this time.
0 commit comments