2 /*-------------------------------------------------------------------------
4 * repl_gram.y - Parser for the replication commands
6 * Portions Copyright (c) 1996-2023, PostgreSQL Global Development Group
7 * Portions Copyright (c) 1994, Regents of the University of California
11 * src/backend/replication/repl_gram.y
13 *-------------------------------------------------------------------------
18 #include "access/xlogdefs.h"
19 #include "nodes/makefuncs.h"
20 #include "nodes/parsenodes.h"
21 #include "nodes/replnodes.h"
22 #include "replication/walsender.h"
23 #include "replication/walsender_private.h"
26 /* Result of the parsing is returned here */
27 Node
*replication_parse_result
;
31 * Bison doesn't allocate anything that needs to live across parser calls,
32 * so we can easily have it use palloc instead of malloc. This prevents
33 * memory leaks if we error out during parsing.
35 #define YYMALLOC palloc
41 %name
-prefix
="replication_yy"
54 /* Non-keyword tokens */
55 %token
<str
> SCONST IDENT
56 %token
<uintval
> UCONST
57 %token
<recptr
> RECPTR
61 %token K_IDENTIFY_SYSTEM
62 %token K_READ_REPLICATION_SLOT
64 %token K_START_REPLICATION
65 %token K_CREATE_REPLICATION_SLOT
66 %token K_DROP_REPLICATION_SLOT
67 %token K_TIMELINE_HISTORY
76 %token K_EXPORT_SNAPSHOT
77 %token K_NOEXPORT_SNAPSHOT
81 %type
<node
> base_backup start_replication start_logical_replication
82 create_replication_slot drop_replication_slot identify_system
83 read_replication_slot timeline_history show
84 %type
<list
> generic_option_list
85 %type
<defelt
> generic_option
86 %type
<uintval
> opt_timeline
87 %type
<list
> plugin_options plugin_opt_list
88 %type
<defelt
> plugin_opt_elem
89 %type
<node
> plugin_opt_arg
90 %type
<str
> opt_slot var_name ident_or_keyword
91 %type
<boolval
> opt_temporary
92 %type
<list
> create_slot_options create_slot_legacy_opt_list
93 %type
<defelt
> create_slot_legacy_opt
97 firstcmd: command opt_semicolon
99 replication_parse_result
= $1;
111 | start_logical_replication
112 | create_replication_slot
113 | drop_replication_slot
114 | read_replication_slot
125 $$
= (Node
*) makeNode
(IdentifySystemCmd
);
130 * READ_REPLICATION_SLOT %s
132 read_replication_slot:
133 K_READ_REPLICATION_SLOT var_name
135 ReadReplicationSlotCmd
*n
= makeNode
(ReadReplicationSlotCmd
);
147 VariableShowStmt
*n
= makeNode
(VariableShowStmt
);
152 var_name: IDENT
{ $$
= $1; }
154 { $$
= psprintf
("%s.%s", $1, $3); }
158 * BASE_BACKUP [ ( option [ 'value' ] [, ...] ) ]
161 K_BASE_BACKUP
'(' generic_option_list
')'
163 BaseBackupCmd
*cmd
= makeNode
(BaseBackupCmd
);
169 BaseBackupCmd
*cmd
= makeNode
(BaseBackupCmd
);
174 create_replication_slot:
175 /* CREATE_REPLICATION_SLOT slot [TEMPORARY] PHYSICAL [options] */
176 K_CREATE_REPLICATION_SLOT IDENT opt_temporary K_PHYSICAL create_slot_options
178 CreateReplicationSlotCmd
*cmd
;
179 cmd
= makeNode
(CreateReplicationSlotCmd
);
180 cmd
->kind
= REPLICATION_KIND_PHYSICAL
;
186 /* CREATE_REPLICATION_SLOT slot [TEMPORARY] LOGICAL plugin [options] */
187 | K_CREATE_REPLICATION_SLOT IDENT opt_temporary K_LOGICAL IDENT create_slot_options
189 CreateReplicationSlotCmd
*cmd
;
190 cmd
= makeNode
(CreateReplicationSlotCmd
);
191 cmd
->kind
= REPLICATION_KIND_LOGICAL
;
201 '(' generic_option_list
')' { $$
= $2; }
202 | create_slot_legacy_opt_list
{ $$
= $1; }
205 create_slot_legacy_opt_list:
206 create_slot_legacy_opt_list create_slot_legacy_opt
207 { $$
= lappend
($1, $2); }
212 create_slot_legacy_opt:
215 $$
= makeDefElem
("snapshot",
216 (Node
*) makeString
("export"), -1);
218 | K_NOEXPORT_SNAPSHOT
220 $$
= makeDefElem
("snapshot",
221 (Node
*) makeString
("nothing"), -1);
225 $$
= makeDefElem
("snapshot",
226 (Node
*) makeString
("use"), -1);
230 $$
= makeDefElem
("reserve_wal",
231 (Node
*) makeBoolean
(true
), -1);
235 $$
= makeDefElem
("two_phase",
236 (Node
*) makeBoolean
(true
), -1);
240 /* DROP_REPLICATION_SLOT slot */
241 drop_replication_slot:
242 K_DROP_REPLICATION_SLOT IDENT
244 DropReplicationSlotCmd
*cmd
;
245 cmd
= makeNode
(DropReplicationSlotCmd
);
250 | K_DROP_REPLICATION_SLOT IDENT K_WAIT
252 DropReplicationSlotCmd
*cmd
;
253 cmd
= makeNode
(DropReplicationSlotCmd
);
261 * START_REPLICATION [SLOT slot] [PHYSICAL] %X/%X [TIMELINE %d]
264 K_START_REPLICATION opt_slot opt_physical RECPTR opt_timeline
266 StartReplicationCmd
*cmd
;
268 cmd
= makeNode
(StartReplicationCmd
);
269 cmd
->kind
= REPLICATION_KIND_PHYSICAL
;
271 cmd
->startpoint
= $4;
277 /* START_REPLICATION SLOT slot LOGICAL %X/%X options */
278 start_logical_replication:
279 K_START_REPLICATION K_SLOT IDENT K_LOGICAL RECPTR plugin_options
281 StartReplicationCmd
*cmd
;
282 cmd
= makeNode
(StartReplicationCmd
);
283 cmd
->kind
= REPLICATION_KIND_LOGICAL
;
285 cmd
->startpoint
= $5;
291 * TIMELINE_HISTORY %d
294 K_TIMELINE_HISTORY UCONST
296 TimeLineHistoryCmd
*cmd
;
300 (errcode
(ERRCODE_SYNTAX_ERROR
),
301 errmsg
("invalid timeline %u", $2)));
303 cmd
= makeNode
(TimeLineHistoryCmd
);
316 K_TEMPORARY
{ $$
= true
; }
317 |
/* EMPTY */ { $$
= false
; }
332 (errcode
(ERRCODE_SYNTAX_ERROR
),
333 errmsg
("invalid timeline %u", $2)));
336 |
/* EMPTY */ { $$
= 0; }
341 '(' plugin_opt_list
')' { $$
= $2; }
342 |
/* EMPTY */ { $$
= NIL
; }
350 | plugin_opt_list
',' plugin_opt_elem
352 $$
= lappend
($1, $3);
359 $$
= makeDefElem
($1, $2, -1);
364 SCONST
{ $$
= (Node
*) makeString
($1); }
365 |
/* EMPTY */ { $$
= NULL
; }
369 generic_option_list
',' generic_option
370 { $$
= lappend
($1, $3); }
372 { $$
= list_make1
($1); }
378 $$
= makeDefElem
($1, NULL
, -1);
380 | ident_or_keyword IDENT
382 $$
= makeDefElem
($1, (Node
*) makeString
($2), -1);
384 | ident_or_keyword SCONST
386 $$
= makeDefElem
($1, (Node
*) makeString
($2), -1);
388 | ident_or_keyword UCONST
390 $$
= makeDefElem
($1, (Node
*) makeInteger
($2), -1);
396 | K_BASE_BACKUP
{ $$
= "base_backup"; }
397 | K_IDENTIFY_SYSTEM
{ $$
= "identify_system"; }
398 | K_SHOW
{ $$
= "show"; }
399 | K_START_REPLICATION
{ $$
= "start_replication"; }
400 | K_CREATE_REPLICATION_SLOT
{ $$
= "create_replication_slot"; }
401 | K_DROP_REPLICATION_SLOT
{ $$
= "drop_replication_slot"; }
402 | K_TIMELINE_HISTORY
{ $$
= "timeline_history"; }
403 | K_WAIT
{ $$
= "wait"; }
404 | K_TIMELINE
{ $$
= "timeline"; }
405 | K_PHYSICAL
{ $$
= "physical"; }
406 | K_LOGICAL
{ $$
= "logical"; }
407 | K_SLOT
{ $$
= "slot"; }
408 | K_RESERVE_WAL
{ $$
= "reserve_wal"; }
409 | K_TEMPORARY
{ $$
= "temporary"; }
410 | K_TWO_PHASE
{ $$
= "two_phase"; }
411 | K_EXPORT_SNAPSHOT
{ $$
= "export_snapshot"; }
412 | K_NOEXPORT_SNAPSHOT
{ $$
= "noexport_snapshot"; }
413 | K_USE_SNAPSHOT
{ $$
= "use_snapshot"; }