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

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

Merged
funbringer merged 16 commits intopostgrespro:masterfromzilder:logical
Jun 1, 2018
Merged
Show file tree
Hide file tree
Changes from1 commit
Commits
Show all changes
16 commits
Select commitHold shift + click to select a range
ca5b546
Logical replication
zilderMar 16, 2018
bb01c7d
Skip logical replication test on PostgreSQL versions below 10
zilderMar 16, 2018
782484b
Fix logical replication for python3
zilderMar 16, 2018
f8b95c6
Merge branch 'master' into logical
zilderMar 19, 2018
b1cba73
Some minor refactoring of logical replication
zilderMar 22, 2018
954879a
Added options_string() func
zilderMar 22, 2018
0741c70
Merge branch 'master' into logical
zilderMar 22, 2018
f4e0bd0
Minor refactoring
zilderMar 22, 2018
f48623b
Add failing logical replication test for 9.6
zilderMar 22, 2018
138c6cc
Added test for Publication.add_tables()
zilderMar 22, 2018
f652bf4
Merge branch 'master' into logical. Also testgres.pubsub was added to…
zilderMar 26, 2018
bc1002f
Additional subscription catchup test
zilderMar 27, 2018
08ed6ef
Some refactoring of logical replication API and formatting
zilderMar 27, 2018
4b279ef
minor refactoring
zilderMay 31, 2018
d60cdcb
Merge branch 'master' into logical
zilderMay 31, 2018
50e02ff
change safe_psql() call to execute() in pubsub.py
zilderJun 1, 2018
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
PrevPrevious commit
NextNext commit
Merge branch 'master' into logical. Also testgres.pubsub was added to…
… the Sphinx templates and module header was added as well.
  • Loading branch information
@zilder
zilder committedMar 26, 2018
commitf652bf40850d5aa20a8c9f207a41fec8a570d639
17 changes: 16 additions & 1 deletiondocs/source/testgres.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -59,4 +59,19 @@ testgres.node
.. automethod:: __init__

.. autoclass:: testgres.node.ProcessProxy
:members:
:members:

testgres.pubsub
---------------

.. automodule:: testgres.pubsub

.. autoclass:: testgres.node.Publication
:members:

.. automethod:: __init__

.. autoclass:: testgres.node.Subscription
:members:

.. automethod:: __init__
2 changes: 1 addition & 1 deletiontestgres/api.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -28,7 +28,7 @@
... replica.catchup() # wait until changes are visible
... print(replica.execute('postgres', 'select count(*) from test'))
PostgresNode(name='...', port=..., base_dir='...')
[(3,)]
[(3L,)]
Copy link
Collaborator

Choose a reason for hiding this comment

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

is this necessary?

Copy link
CollaboratorAuthor

Choose a reason for hiding this comment

The 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[(3,)] so I am confused :) Will change it back then as it shouldn't be part of this pull request anyway.

"""
from .node import PostgresNode

Expand Down
5 changes: 2 additions & 3 deletionstestgres/node.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -300,12 +300,11 @@ def _create_recovery_conf(self, username, slot=None):
master = self.master
assert master is not None

# yapf: disable
conninfo = {
"application_name": self.name,
"port": master.port,
"user": username
}
} # yapf: disable

# host is tricky
try:
Expand All@@ -318,7 +317,7 @@ def _create_recovery_conf(self, username, slot=None):
line = (
"primary_conninfo='{}'\n"
"standby_mode=on\n"
).format(options_string(**conninfo))
).format(options_string(**conninfo)) # yapf: disable

if slot:
# Connect to master for some additional actions
Expand Down
58 changes: 52 additions & 6 deletionstestgres/pubsub.py
View file
Open in desktop
Original file line numberDiff line numberDiff 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
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should be changed tofrom testgres import get_new_node. Documentation should contain working code, even it would require remove doctest.

Copy link
CollaboratorAuthor

Choose a reason for hiding this comment

The 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

Expand All@@ -10,7 +52,8 @@
class Publication(object):
def __init__(self, name, node, tables=None, dbname=None, username=None):
"""
Constructor
Constructor. Use :meth:`.PostgresNode.publish()` instead of direct
constructing publication objects.

Args:
name: publication name
Expand DownExpand Up@@ -40,10 +83,11 @@ def drop(self, dbname=None, username=None):

def add_tables(self, tables, dbname=None, username=None):
"""
Add tables
Add tables to the publication. Cannot be used if publication was
created with empty tables list.

Args:
tables: a list of tables toadd to the publication
tables: a list of tables tobe added to the publication
"""
if not tables:
raise ValueError("Tables list is empty")
Expand All@@ -64,15 +108,17 @@ def __init__(self,
username=None,
**kwargs):
"""
Constructor
Constructor. Use :meth:`.PostgresNode.subscribe()` instead of direct
constructing subscription objects.

Args:
name: subscription name
Copy link
Collaborator

Choose a reason for hiding this comment

The 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.

Copy link
CollaboratorAuthor

Choose a reason for hiding this comment

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

Fixed

node: subscriber's node
publication: Publication object we are subscribing to
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
**kwargs: subscription parameters (see``CREATE SUBSCRIPTION``
in PostgreSQL documentation for more information)
"""
self.name = name
Expand Down
You are viewing a condensed version of this merge commit. You can view thefull changes here.

[8]ページ先頭

©2009-2025 Movatter.jp