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 @@ -691,6 +691,28 @@ def reload(self, params=[]):
691691
692692 return self
693693
694+ def promote (self ):
695+ """
696+ Promote standby instance to master using pg_ctl.
697+
698+ Returns:
699+ This instance of :class:`.PostgresNode`.
700+ """
701+
702+ _params = [
703+ get_bin_path ("pg_ctl" ),
704+ "-D" , self .data_dir ,
705+ "-w" , # wait
706+ "promote"
707+ ] # yapf: disable
708+
709+ execute_utility (_params , self .utils_log_file )
710+
711+ # Node becomes master itself
712+ self ._master = None
713+
714+ return self
715+
694716 def pg_ctl (self , params ):
695717 """
696718 Invoke pg_ctl with params.
Original file line number Diff line number Diff line change @@ -529,6 +529,20 @@ def test_incorrect_catchup(self):
529529 with self .assertRaises (TestgresException ):
530530 node .catchup ()
531531
532+ def test_promotion (self ):
533+ with get_new_node () as master :
534+ master .init ().start ()
535+ master .safe_psql ('create table abc(id serial)' )
536+
537+ with master .replicate ().start () as replica :
538+ master .stop ()
539+ replica .promote ()
540+
541+ # make standby becomes writable master
542+ replica .safe_psql ('insert into abc values (1)' )
543+ res = replica .safe_psql ('select * from abc' )
544+ self .assertEqual (res , b'1\n ' )
545+
532546 def test_dump (self ):
533547 query_create = 'create table test as select generate_series(1, 2) as val'
534548 query_select = 'select * from test order by val asc'
You can’t perform that action at this time.
0 commit comments