Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 5ea4bd8

Browse files
committed
Add PostgresNode.promote() method which promotes standby node to master
1 parent 72d0373 commit 5ea4bd8

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

testgres/node.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff 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.

tests/test_simple.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff 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'

0 commit comments

Comments
 (0)