Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add promote() method #47

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jun 4, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add PostgresNode.promote() method which promotes standby node to master
  • Loading branch information
zilder committed Apr 2, 2018
commit c6e61b952acdb0488ccac4b5535e02b5821f33cb
22 changes: 22 additions & 0 deletions testgres/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,28 @@ def reload(self, params=[]):

return self

def promote(self):
"""
Promote standby instance to master using pg_ctl.

Returns:
This instance of :class:`.PostgresNode`.
"""

_params = [
get_bin_path("pg_ctl"),
"-D", self.data_dir,
"-w", # wait
"promote"
] # yapf: disable

execute_utility(_params, self.utils_log_file)

# Node becomes master itself
self._master = None

return self

def pg_ctl(self, params):
"""
Invoke pg_ctl with params.
Expand Down
14 changes: 14 additions & 0 deletions tests/test_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,20 @@ def test_incorrect_catchup(self):
with self.assertRaises(TestgresException):
node.catchup()

def test_promotion(self):
with get_new_node() as master:
master.init().start()
master.safe_psql('create table abc(id serial)')

with master.replicate().start() as replica:
master.stop()
replica.promote()

# make standby becomes writable master
replica.safe_psql('insert into abc values (1)')
res = replica.safe_psql('select * from abc')
self.assertEqual(res, b'1\n')

def test_dump(self):
query_create = 'create table test as select generate_series(1, 2) as val'
query_select = 'select * from test order by val asc'
Expand Down