8000 Implement "live" streaming of changes from source to target. by dimitri · Pull Request #185 · dimitri/pgcopydb · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Implement "live" streaming of changes from source to target. #185

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 6 commits into from
Feb 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ jobs:
- cdc-wal2json
- follow-wal2json
- follow-9.6
- cdc-low-level
steps:
- name: Checkout repository
uses: actions/checkout@v3
Expand Down
44 changes: 43 additions & 1 deletion docs/ref/pgcopydb_stream.rst
8000
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ This command prefixes the following sub-commands:
cleanup cleanup source and target systems for logical decoding
prefetch Stream JSON changes from the source database and transform them to SQL
catchup Apply prefetched changes from SQL files to the target database
replay Replay changes from the source to the target database, live
+ create Create resources needed for pgcopydb
+ drop Drop resources needed for pgcopydb
+ sentinel Maintain a sentinel table on the source database
Expand Down Expand Up @@ -196,8 +197,42 @@ applies changes from the SQL files that have been prepared with the
--resume Allow resuming operations after a failure
--not-consistent Allow taking a new snapshot on the source database
--slot-name Stream changes recorded by this slot
--endpos LSN position where to stop receiving changes --origin Name of the Postgres replication origin
--endpos LSN position where to stop receiving changes
--origin Name of the Postgres replication origin

.. _pgcopydb_stream_replay:

pgcopydb stream replay
----------------------

pgcopydb stream replay - Replay changes from the source to the target database, live

The command ``pgcopydb stream replay`` connects to the source database and
streams changes using the logical decoding protocol, and internally streams
those changes to a transform process and then a replay process, which
connects to the target database and applies SQL changes.

::

pgcopydb stream replay: Replay changes from the source to the target database, live
usage: pgcopydb stream replay

--source Postgres URI to the source database
--target Postgres URI to the target database
--dir Work directory to use
--restart Allow restarting when temp files exist already
--resume Allow resuming operations after a failure
--not-consistent Allow taking a new snapshot on the source database
--slot-name Stream changes recorded by this slot
--endpos LSN position where to stop receiving changes
--origin Name of the Postgres replication origin


This command is equivalent to running the following script::

pgcopydb stream receive --to-stdout
| pgcopydb stream transform - -
| pgcopydb stream apply -

.. _pgcopydb_stream_create_slot:

Expand Down Expand Up @@ -411,6 +446,7 @@ as their origin WAL filename (with the ``.json`` extension).

--source Postgres URI to the source database
--dir Work directory to use
--to-stdout Stream logical decoding messages to stdout
--restart Allow restarting when temp files exist already
--resume Allow resuming operations after a failure
--not-consistent Allow taking a new snapshot on the source database
Expand Down Expand Up @@ -440,6 +476,10 @@ per line.
--resume Allow resuming operations after a failure
--not-consistent Allow taking a new snapshot on the source database

The command supports using ``-`` as the filename for either the JSON input
or the SQL output, or both. In that case reading from standard input and/or
writing to standard output is implemented, in a streaming fashion. A classic
use case is to use Unix Pipes, see :ref:`pgcopydb_stream_replay` too.

pgcopydb stream apply
---------------------
Expand All @@ -465,6 +505,8 @@ __ https://www.postgresql.org/docs/current/replication-origins.html
--not-consistent Allow taking a new snapshot on the source database
--origin Name of the Postgres replication origin

This command supports using ``-`` as the filename to read from, and in that
case reads from the standard input in a streaming fashion instead.

Options
-------
Expand Down
8 changes: 6 additions & 2 deletions src/bin/pgcopydb/cli_clone_follow.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,9 @@ cli_clone(int argc, char **argv)
copyDBoptions.slotName,
copyDBoptions.origin,
copyDBoptions.endpos,
STREAM_MODE_PREFETCH))
STREAM_MODE_PREFETCH,
copyDBoptions.stdin,
copyDBoptions.stdout))
{
/* errors have already been logged */
exit(EXIT_CODE_INTERNAL_ERROR);
Expand Down Expand Up @@ -362,7 +364,9 @@ cli_follow(int argc, char **argv)
copyDBoptions.slotName,
copyDBoptions.origin,
copyDBoptions.endpos,
STREAM_MODE_PREFETCH))
STREAM_MODE_PREFETCH,
copyDBoptions.stdin,
copyDBoptions.stdout))
{
/* errors have already been logged */
exit(EXIT_CODE_INTERNAL_ERROR);
Expand Down
3 changes: 3 additions & 0 deletions src/bin/pgcopydb/cli_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ typedef struct CopyDBOptions
char snapshot[BUFSIZE];
char origin[BUFSIZE];

bool stdin;
bool stdout;

bool follow;
bool createSlot;
bool currentpos;
Expand Down
Loading
0