File tree Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -670,6 +670,28 @@ def reload(self, params=[]):
670670
671671 return self
672672
673+ def promote (self ):
674+ """
675+ Promote standby instance to master using pg_ctl.
676+
677+ Returns:
678+ This instance of :class:`.PostgresNode`.
679+ """
680+
681+ _params = [
682+ get_bin_path ("pg_ctl" ),
683+ "-D" , self .data_dir ,
684+ "-w" , # wait
685+ "promote"
686+ ] # yapf: disable
687+
688+ execute_utility (_params , self .utils_log_file )
689+
690+ # Node becomes master itself
691+ self ._master = None
692+
693+ return self
694+
673695 def pg_ctl (self , params ):
674696 """
675697 Invoke pg_ctl with params.
Original file line number Diff line number Diff line change @@ -407,6 +407,20 @@ def test_incorrect_catchup(self):
407407 with self .assertRaises (TestgresException ):
408408 node .catchup ()
409409
410+ def test_promotion (self ):
411+ with get_new_node () as master :
412+ master .init ().start ()
413+ master .safe_psql ('create table abc(id serial)' )
414+
415+ with master .replicate ().start () as replica :
416+ master .stop ()
417+ replica .promote ()
418+
419+ # make standby becomes writable master
420+ replica .safe_psql ('insert into abc values (1)' )
421+ res = replica .safe_psql ('select * from abc' )
422+ self .assertEqual (res , b'1\n ' )
423+
410424 def test_dump (self ):
411425 query_create = 'create table test as select generate_series(1, 2) as val'
412426 query_select = 'select * from test order by val asc'
You can’t perform that action at this time.
0 commit comments