2 /*-------------------------------------------------------------------------
4 * repl_gram.y - Parser for the replication commands
6 * Portions Copyright (c) 1996-2024, 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"
25 #include "repl_gram.h"
27 /* silence -Wmissing-variable-declarations */
28 extern
int replication_yychar
;
29 extern
int replication_yynerrs
;
32 /* Result of the parsing is returned here */
33 Node
*replication_parse_result
;
37 * Bison doesn't allocate anything that needs to live across parser calls,
38 * so we can easily have it use palloc instead of malloc. This prevents
39 * memory leaks if we error out during parsing.
41 #define YYMALLOC palloc
47 %name
-prefix
="replication_yy"
60 /* Non-keyword tokens */
61 %token
<str
> SCONST IDENT
62 %token
<uintval
> UCONST
63 %token
<recptr
> RECPTR
67 %token K_IDENTIFY_SYSTEM
68 %token K_READ_REPLICATION_SLOT
70 %token K_START_REPLICATION
71 %token K_CREATE_REPLICATION_SLOT
72 %token K_DROP_REPLICATION_SLOT
73 %token K_ALTER_REPLICATION_SLOT
74 %token K_TIMELINE_HISTORY
83 %token K_EXPORT_SNAPSHOT
84 %token K_NOEXPORT_SNAPSHOT
86 %token K_UPLOAD_MANIFEST
89 %type
<node
> base_backup start_replication start_logical_replication
90 create_replication_slot drop_replication_slot
91 alter_replication_slot identify_system read_replication_slot
92 timeline_history show upload_manifest
93 %type
<list
> generic_option_list
94 %type
<defelt
> generic_option
95 %type
<uintval
> opt_timeline
96 %type
<list
> plugin_options plugin_opt_list
97 %type
<defelt
> plugin_opt_elem
98 %type
<node
> plugin_opt_arg
99 %type
<str
> opt_slot var_name ident_or_keyword
100 %type
<boolval
> opt_temporary
101 %type
<list
> create_slot_options create_slot_legacy_opt_list
102 %type
<defelt
> create_slot_legacy_opt
106 firstcmd: command opt_semicolon
108 replication_parse_result
= $1;
120 | start_logical_replication
121 | create_replication_slot
122 | drop_replication_slot
123 | alter_replication_slot
124 | read_replication_slot
136 $$
= (Node
*) makeNode
(IdentifySystemCmd
);
141 * READ_REPLICATION_SLOT %s
143 read_replication_slot:
144 K_READ_REPLICATION_SLOT var_name
146 ReadReplicationSlotCmd
*n
= makeNode
(ReadReplicationSlotCmd
);
158 VariableShowStmt
*n
= makeNode
(VariableShowStmt
);
163 var_name: IDENT
{ $$
= $1; }
165 { $$
= psprintf
("%s.%s", $1, $3); }
169 * BASE_BACKUP [ ( option [ 'value' ] [, ...] ) ]
172 K_BASE_BACKUP
'(' generic_option_list
')'
174 BaseBackupCmd
*cmd
= makeNode
(BaseBackupCmd
);
180 BaseBackupCmd
*cmd
= makeNode
(BaseBackupCmd
);
185 create_replication_slot:
186 /* CREATE_REPLICATION_SLOT slot [TEMPORARY] PHYSICAL [options] */
187 K_CREATE_REPLICATION_SLOT IDENT opt_temporary K_PHYSICAL create_slot_options
189 CreateReplicationSlotCmd
*cmd
;
190 cmd
= makeNode
(CreateReplicationSlotCmd
);
191 cmd
->kind
= REPLICATION_KIND_PHYSICAL
;
197 /* CREATE_REPLICATION_SLOT slot [TEMPORARY] LOGICAL plugin [options] */
198 | K_CREATE_REPLICATION_SLOT IDENT opt_temporary K_LOGICAL IDENT create_slot_options
200 CreateReplicationSlotCmd
*cmd
;
201 cmd
= makeNode
(CreateReplicationSlotCmd
);
202 cmd
->kind
= REPLICATION_KIND_LOGICAL
;
212 '(' generic_option_list
')' { $$
= $2; }
213 | create_slot_legacy_opt_list
{ $$
= $1; }
216 create_slot_legacy_opt_list:
217 create_slot_legacy_opt_list create_slot_legacy_opt
218 { $$
= lappend
($1, $2); }
223 create_slot_legacy_opt:
226 $$
= makeDefElem
("snapshot",
227 (Node
*) makeString
("export"), -1);
229 | K_NOEXPORT_SNAPSHOT
231 $$
= makeDefElem
("snapshot",
232 (Node
*) makeString
("nothing"), -1);
236 $$
= makeDefElem
("snapshot",
237 (Node
*) makeString
("use"), -1);
241 $$
= makeDefElem
("reserve_wal",
242 (Node
*) makeBoolean
(true
), -1);
246 $$
= makeDefElem
("two_phase",
247 (Node
*) makeBoolean
(true
), -1);
251 /* DROP_REPLICATION_SLOT slot */
252 drop_replication_slot:
253 K_DROP_REPLICATION_SLOT IDENT
255 DropReplicationSlotCmd
*cmd
;
256 cmd
= makeNode
(DropReplicationSlotCmd
);
261 | K_DROP_REPLICATION_SLOT IDENT K_WAIT
263 DropReplicationSlotCmd
*cmd
;
264 cmd
= makeNode
(DropReplicationSlotCmd
);
271 /* ALTER_REPLICATION_SLOT slot (options) */
272 alter_replication_slot:
273 K_ALTER_REPLICATION_SLOT IDENT
'(' generic_option_list
')'
275 AlterReplicationSlotCmd
*cmd
;
276 cmd
= makeNode
(AlterReplicationSlotCmd
);
284 * START_REPLICATION [SLOT slot] [PHYSICAL] %X/%X [TIMELINE %u]
287 K_START_REPLICATION opt_slot opt_physical RECPTR opt_timeline
289 StartReplicationCmd
*cmd
;
291 cmd
= makeNode
(StartReplicationCmd
);
292 cmd
->kind
= REPLICATION_KIND_PHYSICAL
;
294 cmd
->startpoint
= $4;
300 /* START_REPLICATION SLOT slot LOGICAL %X/%X options */
301 start_logical_replication:
302 K_START_REPLICATION K_SLOT IDENT K_LOGICAL RECPTR plugin_options
304 StartReplicationCmd
*cmd
;
305 cmd
= makeNode
(StartReplicationCmd
);
306 cmd
->kind
= REPLICATION_KIND_LOGICAL
;
308 cmd
->startpoint
= $5;
314 * TIMELINE_HISTORY %u
317 K_TIMELINE_HISTORY UCONST
319 TimeLineHistoryCmd
*cmd
;
323 (errcode
(ERRCODE_SYNTAX_ERROR
),
324 errmsg
("invalid timeline %u", $2)));
326 cmd
= makeNode
(TimeLineHistoryCmd
);
333 /* UPLOAD_MANIFEST doesn't currently accept any arguments */
337 UploadManifestCmd
*cmd
= makeNode
(UploadManifestCmd
);
348 K_TEMPORARY
{ $$
= true
; }
349 |
/* EMPTY */ { $$
= false
; }
364 (errcode
(ERRCODE_SYNTAX_ERROR
),
365 errmsg
("invalid timeline %u", $2)));
368 |
/* EMPTY */ { $$
= 0; }
373 '(' plugin_opt_list
')' { $$
= $2; }
374 |
/* EMPTY */ { $$
= NIL
; }
382 | plugin_opt_list
',' plugin_opt_elem
384 $$
= lappend
($1, $3);
391 $$
= makeDefElem
($1, $2, -1);
396 SCONST
{ $$
= (Node
*) makeString
($1); }
397 |
/* EMPTY */ { $$
= NULL
; }
401 generic_option_list
',' generic_option
402 { $$
= lappend
($1, $3); }
404 { $$
= list_make1
($1); }
410 $$
= makeDefElem
($1, NULL
, -1);
412 | ident_or_keyword IDENT
414 $$
= makeDefElem
($1, (Node
*) makeString
($2), -1);
416 | ident_or_keyword SCONST
418 $$
= makeDefElem
($1, (Node
*) makeString
($2), -1);
420 | ident_or_keyword UCONST
422 $$
= makeDefElem
($1, (Node
*) makeInteger
($2), -1);
428 | K_BASE_BACKUP
{ $$
= "base_backup"; }
429 | K_IDENTIFY_SYSTEM
{ $$
= "identify_system"; }
430 | K_SHOW
{ $$
= "show"; }
431 | K_START_REPLICATION
{ $$
= "start_replication"; }
432 | K_CREATE_REPLICATION_SLOT
{ $$
= "create_replication_slot"; }
433 | K_DROP_REPLICATION_SLOT
{ $$
= "drop_replication_slot"; }
434 | K_ALTER_REPLICATION_SLOT
{ $$
= "alter_replication_slot"; }
435 | K_TIMELINE_HISTORY
{ $$
= "timeline_history"; }
436 | K_WAIT
{ $$
= "wait"; }
437 | K_TIMELINE
{ $$
= "timeline"; }
438 | K_PHYSICAL
{ $$
= "physical"; }
439 | K_LOGICAL
{ $$
= "logical"; }
440 | K_SLOT
{ $$
= "slot"; }
441 | K_RESERVE_WAL
{ $$
= "reserve_wal"; }
442 | K_TEMPORARY
{ $$
= "temporary"; }
443 | K_TWO_PHASE
{ $$
= "two_phase"; }
444 | K_EXPORT_SNAPSHOT
{ $$
= "export_snapshot"; }
445 | K_NOEXPORT_SNAPSHOT
{ $$
= "noexport_snapshot"; }
446 | K_USE_SNAPSHOT
{ $$
= "use_snapshot"; }
447 | K_UPLOAD_MANIFEST
{ $$
= "upload_manifest"; }