Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5ea4bd8

Browse files
committed
Add PostgresNode.promote() method which promotes standby node to master
1 parent72d0373 commit5ea4bd8

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
returnself
693693

694+
defpromote(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+
returnself
715+
694716
defpg_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
withself.assertRaises(TestgresException):
530530
node.catchup()
531531

532+
deftest_promotion(self):
533+
withget_new_node()asmaster:
534+
master.init().start()
535+
master.safe_psql('create table abc(id serial)')
536+
537+
withmaster.replicate().start()asreplica:
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
deftest_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)

[8]ページ先頭

©2009-2025 Movatter.jp