- Notifications
You must be signed in to change notification settings - Fork35
Logical replication support#42
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes from1 commit
ca5b546
bb01c7d
782484b
f8b95c6
b1cba73
954879a
0741c70
f4e0bd0
f48623b
138c6cc
f652bf4
bc1002f
08ed6ef
4b279ef
d60cdcb
50e02ff
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
… the Sphinx templates and module header was added as well.
- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -28,7 +28,7 @@ | ||
... replica.catchup() # wait until changes are visible | ||
... print(replica.execute('postgres', 'select count(*) from test')) | ||
PostgresNode(name='...', port=..., base_dir='...') | ||
[(3L,)] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. is this necessary? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. I think it was when I tested with doctest. But now when I ran doctest it showed | ||
""" | ||
from .node import PostgresNode | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,46 @@ | ||
# coding: utf-8 | ||
""" | ||
Unlike physical replication the logical replication allows users replicate only | ||
specified databases and tables. It uses publish-subscribe model with possibly | ||
multiple publishers and multiple subscribers. When initializing publisher's | ||
node ``allow_logical=True`` should be passed to the :meth:`.PostgresNode.init()` | ||
method to enable PostgreSQL to write extra information to the WAL needed by | ||
logical replication. | ||
To replicate table ``X`` from node A to node B the same table structure should | ||
be defined on the subscriber's node as logical replication don't replicate DDL. | ||
After that :meth:`~.PostgresNode.publish()` and :meth:`~.PostgresNode.subscribe()` | ||
methods may be used to setup replication. Example: | ||
>>> from .api import get_new_node | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. This should be changed to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Agree | ||
>>> with get_new_node() as nodeA, get_new_node() as nodeB: | ||
... nodeA.init(allow_logical=True).start() | ||
... nodeB.init().start() | ||
... | ||
... # create same table both on publisher and subscriber | ||
... create_table = 'create table test (a int, b int)' | ||
... nodeA.safe_psql(create_table) | ||
... nodeB.safe_psql(create_table) | ||
... | ||
... # create publication | ||
... pub = nodeA.publish('mypub') | ||
... # create subscription | ||
... sub = nodeB.subscribe(pub, 'mysub') | ||
... | ||
... # insert some data to the publisher's node | ||
... nodeA.execute('insert into test values (1, 1), (2, 2)') | ||
... | ||
... # wait until changes apply on subscriber and check them | ||
... sub.catchup() | ||
... | ||
... # read the data from subscriber's node | ||
... nodeB.execute('select * from test') | ||
PostgresNode(name='...', port=..., base_dir='...') | ||
PostgresNode(name='...', port=..., base_dir='...') | ||
'' | ||
'' | ||
[(1, 1), (2, 2)] | ||
""" | ||
from six import raise_from | ||
@@ -10,7 +52,8 @@ | ||
class Publication(object): | ||
def __init__(self, name, node, tables=None, dbname=None, username=None): | ||
""" | ||
Constructor. Use :meth:`.PostgresNode.publish()` instead of direct | ||
constructing publication objects. | ||
Args: | ||
name: publication name | ||
@@ -40,10 +83,11 @@ def drop(self, dbname=None, username=None): | ||
def add_tables(self, tables, dbname=None, username=None): | ||
""" | ||
Add tables to the publication. Cannot be used if publication was | ||
created with empty tables list. | ||
Args: | ||
tables: a list of tables tobe added to the publication | ||
""" | ||
if not tables: | ||
raise ValueError("Tables list is empty") | ||
@@ -64,15 +108,17 @@ def __init__(self, | ||
username=None, | ||
**kwargs): | ||
""" | ||
Constructor. Use :meth:`.PostgresNode.subscribe()` instead of direct | ||
constructing subscription objects. | ||
Args: | ||
name: subscription name | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. I've also noticed that some doc strings end with commas while others don't. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Fixed | ||
node: subscriber's node | ||
publication: :class:`.Publication` object we are subscribing to | ||
(see :meth:`.PostgresNode.publish()`) | ||
dbname: database name used to connect and perform subscription | ||
username: username used to connect to the database | ||
**kwargs: subscription parameters (see``CREATE SUBSCRIPTION`` | ||
in PostgreSQL documentation for more information) | ||
""" | ||
self.name = name | ||