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

Commitc6e61b9

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

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
@@ -670,6 +670,28 @@ def reload(self, params=[]):
670670

671671
returnself
672672

673+
defpromote(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+
returnself
694+
673695
defpg_ctl(self,params):
674696
"""
675697
Invoke pg_ctl with params.

‎tests/test_simple.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,20 @@ def test_incorrect_catchup(self):
407407
withself.assertRaises(TestgresException):
408408
node.catchup()
409409

410+
deftest_promotion(self):
411+
withget_new_node()asmaster:
412+
master.init().start()
413+
master.safe_psql('create table abc(id serial)')
414+
415+
withmaster.replicate().start()asreplica:
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
deftest_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'

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp