1
0
mirror of https://github.com/postgres/postgres.git synced 2025-09-02 04:21:28 +03:00

Logical replication support for initial data copy

Add functionality for a new subscription to copy the initial data in the
tables and then sync with the ongoing apply process.

For the copying, add a new internal COPY option to have the COPY source
data provided by a callback function.  The initial data copy works on
the subscriber by receiving COPY data from the publisher and then
providing it locally into a COPY that writes to the destination table.

A WAL receiver can now execute full SQL commands.  This is used here to
obtain information about tables and publications.

Several new options were added to CREATE and ALTER SUBSCRIPTION to
control whether and when initial table syncing happens.

Change pg_dump option --no-create-subscription-slots to
--no-subscription-connect and use the new CREATE SUBSCRIPTION
... NOCONNECT option for that.

Author: Petr Jelinek <petr.jelinek@2ndquadrant.com>
Tested-by: Erik Rijkers <er@xs4all.nl>
This commit is contained in:
Peter Eisentraut
2017-03-23 08:36:36 -04:00
parent 707576b571
commit 7c4f52409a
62 changed files with 2969 additions and 344 deletions

View File

@@ -25,6 +25,8 @@
/* Result of the parsing is returned here */
Node *replication_parse_result;
static SQLCmd *make_sqlcmd(void);
/*
* Bison doesn't allocate anything that needs to live across parser calls,
@@ -57,6 +59,7 @@ Node *replication_parse_result;
%token <str> SCONST IDENT
%token <uintval> UCONST
%token <recptr> RECPTR
%token T_WORD
/* Keyword tokens. */
%token K_BASE_BACKUP
@@ -81,11 +84,12 @@ Node *replication_parse_result;
%token K_TEMPORARY
%token K_EXPORT_SNAPSHOT
%token K_NOEXPORT_SNAPSHOT
%token K_USE_SNAPSHOT
%type <node> command
%type <node> base_backup start_replication start_logical_replication
create_replication_slot drop_replication_slot identify_system
timeline_history show
timeline_history show sql_cmd
%type <list> base_backup_opt_list
%type <defelt> base_backup_opt
%type <uintval> opt_timeline
@@ -118,6 +122,7 @@ command:
| drop_replication_slot
| timeline_history
| show
| sql_cmd
;
/*
@@ -248,6 +253,11 @@ create_slot_opt:
$$ = makeDefElem("export_snapshot",
(Node *)makeInteger(FALSE), -1);
}
| K_USE_SNAPSHOT
{
$$ = makeDefElem("use_snapshot",
(Node *)makeInteger(TRUE), -1);
}
| K_RESERVE_WAL
{
$$ = makeDefElem("reserve_wal",
@@ -373,6 +383,26 @@ plugin_opt_arg:
SCONST { $$ = (Node *) makeString($1); }
| /* EMPTY */ { $$ = NULL; }
;
sql_cmd:
IDENT { $$ = (Node *) make_sqlcmd(); }
;
%%
static SQLCmd *
make_sqlcmd(void)
{
SQLCmd *cmd = makeNode(SQLCmd);
int tok;
/* Just move lexer to the end of command. */
for (;;)
{
tok = yylex();
if (tok == ';' || tok == 0)
break;
}
return cmd;
}
#include "repl_scanner.c"