-
Notifications
You must be signed in to change notification settings - Fork 37
Replication slots #41
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
Changes from 3 commits
0dda2ff
3e5dbec
bc6c302
e2e5a8d
59dbe42
0b4ac3a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,7 +32,8 @@ | |
| RECOVERY_CONF_FILE, \ | ||
| PG_LOG_FILE, \ | ||
| UTILS_LOG_FILE, \ | ||
| PG_PID_FILE | ||
| PG_PID_FILE, \ | ||
| REPLICATION_SLOTS | ||
|
|
||
| from .decorators import \ | ||
| method_decorator, \ | ||
|
|
@@ -179,7 +180,7 @@ def _assign_master(self, master): | |
| # now this node has a master | ||
| self._master = master | ||
|
|
||
| def _create_recovery_conf(self, username): | ||
| def _create_recovery_conf(self, username, slot_name=None): | ||
| """NOTE: this is a private method!""" | ||
|
|
||
| # fetch master of this node | ||
|
|
@@ -207,6 +208,9 @@ def _create_recovery_conf(self, username): | |
| "standby_mode=on\n" | ||
| ).format(conninfo) | ||
|
|
||
| if slot_name: | ||
| line += "primary_slot_name={}\n".format(slot_name) | ||
|
|
||
| self.append_conf(RECOVERY_CONF_FILE, line) | ||
|
|
||
| def _maybe_start_logger(self): | ||
|
|
@@ -340,11 +344,14 @@ def get_auth_method(t): | |
| conf.write(u"fsync = off\n") | ||
|
|
||
| # yapf: disable | ||
| conf.write(u"log_statement = {}\n" | ||
| u"listen_addresses = '{}'\n" | ||
| u"port = {}\n".format(log_statement, | ||
| self.host, | ||
| self.port)) | ||
| conf.write( | ||
| u"log_statement = {}\n" | ||
| u"listen_addresses = '{}'\n" | ||
| u"port = {}\n" | ||
| u"max_replication_slots = {}\n".format(log_statement, | ||
| self.host, | ||
| self.port, | ||
| REPLICATION_SLOTS)) | ||
|
|
||
| # replication-related settings | ||
| if allow_streaming: | ||
|
|
@@ -856,7 +863,24 @@ def backup(self, **kwargs): | |
|
|
||
| return NodeBackup(node=self, **kwargs) | ||
|
|
||
| def replicate(self, name=None, **kwargs): | ||
| def create_replication_slot(self, slot_name, dbname=None, username=None): | ||
|
||
| """ | ||
| Create a physical replication slot. | ||
|
|
||
| Args: | ||
| slot_name: slot name | ||
| dbname: database name | ||
| username: database user name | ||
| """ | ||
| query = ( | ||
| "select pg_create_physical_replication_slot('{}')" | ||
| ).format(slot_name) | ||
|
|
||
| self.execute(query=query, | ||
| dbname=dbname or default_dbname(), | ||
|
||
| username=username or default_username()) | ||
|
|
||
| def replicate(self, name=None, slot_name=None, **kwargs): | ||
| """ | ||
| Create a binary replica of this node. | ||
|
|
||
|
|
@@ -870,7 +894,9 @@ def replicate(self, name=None, **kwargs): | |
| backup = self.backup(**kwargs) | ||
|
|
||
| # transform backup into a replica | ||
| return backup.spawn_replica(name=name, destroy=True) | ||
| return backup.spawn_replica(name=name, | ||
| destroy=True, | ||
| slot_name=slot_name) | ||
|
|
||
| def catchup(self, dbname=None, username=None): | ||
| """ | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMHO
max_replication_slotsshould be placed underallow_streaming=True, next tomax_wal_sendersetc.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree as well