8000 Add promote() method by zilder · Pull Request #47 · postgrespro/testgres · GitHub
[go: up one dir, main page]

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
Prev Previous commit
Next Next commit
Add synchronous promotion support on pg of version < 10
  • Loading branch information
zilder committed Jun 4, 2018
commit 7c48faebc13e4a8ac5c363f60c1da8ca67b82928
22 changes: 18 additions & 4 deletions testgres/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -683,17 +683,19 @@ def reload(self, params=[]):
_params = [
get_bin_path("pg_ctl"),
"-D", self.data_dir,
"-w", # wait
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch!

"reload"
] + params # yapf: disable

execute_utility(_params, self.utils_log_file)

return self

def promote(self):
def promote(self, dbname=None, username=None):
"""
Promote standby instance to master using pg_ctl.
Promote standby instance to master using pg_ctl. For PostgreSQL versions
below 10 some additional actions required to ensure that instance
became writable and hence `dbname` and `username` parameters may be
needed.

Returns:
This instance of :class:`.PostgresNode`.
Expand All @@ -708,7 +710,19 @@ def promote(self):

execute_utility(_params, self.utils_log_file)

# Node becomes master itself
# for versions below 10 `promote` is asynchronous so we need to wait
# until it actually becomes writable
if not pg_version_ge("10"):
check_query = "SHOW transaction_read_only"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not safe since transactions might be read-only by default.


self.poll_query_until(
query=check_query,
expected="on",
dbname=dbname,
username=username,
max_attempts=0) # infinite

# node becomes master itself
self._master = None

return self
Expand Down
0