2011-01-14 16:30:33 +01:00
|
|
|
%{
|
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* repl_gram.y - Parser for the replication commands
|
|
|
|
*
|
|
|
|
* Portions Copyright (c) 1996-2011, PostgreSQL Global Development Group
|
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* IDENTIFICATION
|
|
|
|
* src/backend/replication/repl_gram.y
|
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "postgres.h"
|
|
|
|
|
2011-01-23 23:39:18 +01:00
|
|
|
#include "nodes/makefuncs.h"
|
|
|
|
#include "nodes/parsenodes.h"
|
2011-01-14 16:30:33 +01:00
|
|
|
#include "replication/replnodes.h"
|
|
|
|
#include "replication/walsender.h"
|
|
|
|
|
|
|
|
/* Result of the parsing is returned here */
|
|
|
|
Node *replication_parse_result;
|
|
|
|
|
|
|
|
/* Location tracking support --- simpler than bison's default */
|
|
|
|
#define YYLLOC_DEFAULT(Current, Rhs, N) \
|
|
|
|
do { \
|
|
|
|
if (N) \
|
|
|
|
(Current) = (Rhs)[1]; \
|
|
|
|
else \
|
|
|
|
(Current) = (Rhs)[0]; \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Bison doesn't allocate anything that needs to live across parser calls,
|
|
|
|
* so we can easily have it use palloc instead of malloc. This prevents
|
|
|
|
* memory leaks if we error out during parsing. Note this only works with
|
|
|
|
* bison >= 2.0. However, in bison 1.875 the default is to use alloca()
|
|
|
|
* if possible, so there's not really much problem anyhow, at least if
|
|
|
|
* you're building with gcc.
|
|
|
|
*/
|
|
|
|
#define YYMALLOC palloc
|
|
|
|
#define YYFREE pfree
|
|
|
|
|
|
|
|
#define parser_yyerror(msg) replication_yyerror(msg, yyscanner)
|
|
|
|
#define parser_errposition(pos) replication_scanner_errposition(pos)
|
|
|
|
|
|
|
|
%}
|
|
|
|
|
|
|
|
%expect 0
|
|
|
|
%name-prefix="replication_yy"
|
|
|
|
|
|
|
|
%union {
|
|
|
|
char *str;
|
|
|
|
bool boolval;
|
|
|
|
|
|
|
|
XLogRecPtr recptr;
|
|
|
|
Node *node;
|
2011-01-23 23:39:18 +01:00
|
|
|
List *list;
|
|
|
|
DefElem *defelt;
|
2011-01-14 16:30:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Non-keyword tokens */
|
|
|
|
%token <str> SCONST
|
|
|
|
%token <recptr> RECPTR
|
|
|
|
|
|
|
|
/* Keyword tokens. */
|
|
|
|
%token K_BASE_BACKUP
|
|
|
|
%token K_IDENTIFY_SYSTEM
|
|
|
|
%token K_LABEL
|
|
|
|
%token K_PROGRESS
|
2011-01-23 12:21:23 +01:00
|
|
|
%token K_FAST
|
2011-02-09 10:59:53 +01:00
|
|
|
%token K_NOWAIT
|
2011-01-30 21:30:09 +01:00
|
|
|
%token K_WAL
|
2011-01-14 16:30:33 +01:00
|
|
|
%token K_START_REPLICATION
|
|
|
|
|
|
|
|
%type <node> command
|
|
|
|
%type <node> base_backup start_replication identify_system
|
2011-01-23 23:39:18 +01:00
|
|
|
%type <list> base_backup_opt_list
|
|
|
|
%type <defelt> base_backup_opt
|
2011-01-14 16:30:33 +01:00
|
|
|
%%
|
|
|
|
|
|
|
|
firstcmd: command opt_semicolon
|
|
|
|
{
|
|
|
|
replication_parse_result = $1;
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
opt_semicolon: ';'
|
|
|
|
| /* EMPTY */
|
|
|
|
;
|
|
|
|
|
|
|
|
command:
|
|
|
|
identify_system
|
|
|
|
| base_backup
|
|
|
|
| start_replication
|
|
|
|
;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* IDENTIFY_SYSTEM
|
|
|
|
*/
|
|
|
|
identify_system:
|
|
|
|
K_IDENTIFY_SYSTEM
|
|
|
|
{
|
|
|
|
$$ = (Node *) makeNode(IdentifySystemCmd);
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
/*
|
2011-02-09 10:59:53 +01:00
|
|
|
* BASE_BACKUP [LABEL '<label>'] [PROGRESS] [FAST] [WAL] [NOWAIT]
|
2011-01-14 16:30:33 +01:00
|
|
|
*/
|
|
|
|
base_backup:
|
2011-01-23 23:39:18 +01:00
|
|
|
K_BASE_BACKUP base_backup_opt_list
|
2011-01-14 16:30:33 +01:00
|
|
|
{
|
|
|
|
BaseBackupCmd *cmd = (BaseBackupCmd *) makeNode(BaseBackupCmd);
|
2011-01-23 23:39:18 +01:00
|
|
|
cmd->options = $2;
|
2011-01-14 16:30:33 +01:00
|
|
|
$$ = (Node *) cmd;
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
2011-01-23 23:39:18 +01:00
|
|
|
base_backup_opt_list: base_backup_opt_list base_backup_opt { $$ = lappend($1, $2); }
|
|
|
|
| /* EMPTY */ { $$ = NIL; }
|
|
|
|
|
|
|
|
base_backup_opt:
|
|
|
|
K_LABEL SCONST
|
|
|
|
{
|
|
|
|
$$ = makeDefElem("label",
|
|
|
|
(Node *)makeString($2));
|
|
|
|
}
|
|
|
|
| K_PROGRESS
|
|
|
|
{
|
|
|
|
$$ = makeDefElem("progress",
|
|
|
|
(Node *)makeInteger(TRUE));
|
|
|
|
}
|
|
|
|
| K_FAST
|
|
|
|
{
|
|
|
|
$$ = makeDefElem("fast",
|
|
|
|
(Node *)makeInteger(TRUE));
|
|
|
|
}
|
2011-01-30 21:30:09 +01:00
|
|
|
| K_WAL
|
|
|
|
{
|
|
|
|
$$ = makeDefElem("wal",
|
|
|
|
(Node *)makeInteger(TRUE));
|
|
|
|
}
|
2011-02-09 10:59:53 +01:00
|
|
|
| K_NOWAIT
|
|
|
|
{
|
|
|
|
$$ = makeDefElem("nowait",
|
|
|
|
(Node *)makeInteger(TRUE));
|
|
|
|
}
|
2011-01-30 21:30:09 +01:00
|
|
|
;
|
2011-01-14 16:30:33 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* START_REPLICATION %X/%X
|
|
|
|
*/
|
|
|
|
start_replication:
|
|
|
|
K_START_REPLICATION RECPTR
|
|
|
|
{
|
|
|
|
StartReplicationCmd *cmd;
|
|
|
|
|
|
|
|
cmd = makeNode(StartReplicationCmd);
|
|
|
|
cmd->startpoint = $2;
|
|
|
|
|
|
|
|
$$ = (Node *) cmd;
|
|
|
|
}
|
|
|
|
;
|
|
|
|
%%
|
|
|
|
|
|
|
|
#include "repl_scanner.c"
|