doc Makefile: issue warning about chars that cannot be output
[pgsql.git] / src / backend / replication / repl_gram.y
blob06daa9548132d565d1799041fd44017971c069a8
1 %{
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
10 * IDENTIFICATION
11 * src/backend/replication/repl_gram.y
13 *-------------------------------------------------------------------------
16 #include "postgres.h"
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
42 #define YYFREE pfree
46 %expect 0
47 %name-prefix="replication_yy"
49 %union
51 char *str;
52 bool boolval;
53 uint32 uintval;
54 XLogRecPtr recptr;
55 Node *node;
56 List *list;
57 DefElem *defelt;
60 /* Non-keyword tokens */
61 %token <str> SCONST IDENT
62 %token <uintval> UCONST
63 %token <recptr> RECPTR
65 /* Keyword tokens. */
66 %token K_BASE_BACKUP
67 %token K_IDENTIFY_SYSTEM
68 %token K_READ_REPLICATION_SLOT
69 %token K_SHOW
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
75 %token K_WAIT
76 %token K_TIMELINE
77 %token K_PHYSICAL
78 %token K_LOGICAL
79 %token K_SLOT
80 %token K_RESERVE_WAL
81 %token K_TEMPORARY
82 %token K_TWO_PHASE
83 %token K_EXPORT_SNAPSHOT
84 %token K_NOEXPORT_SNAPSHOT
85 %token K_USE_SNAPSHOT
86 %token K_UPLOAD_MANIFEST
88 %type <node> command
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;
112 opt_semicolon: ';'
113 | /* EMPTY */
116 command:
117 identify_system
118 | base_backup
119 | start_replication
120 | start_logical_replication
121 | create_replication_slot
122 | drop_replication_slot
123 | alter_replication_slot
124 | read_replication_slot
125 | timeline_history
126 | show
127 | upload_manifest
131 * IDENTIFY_SYSTEM
133 identify_system:
134 K_IDENTIFY_SYSTEM
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);
147 n->slotname = $2;
148 $$ = (Node *) n;
153 * SHOW setting
155 show:
156 K_SHOW var_name
158 VariableShowStmt *n = makeNode(VariableShowStmt);
159 n->name = $2;
160 $$ = (Node *) n;
163 var_name: IDENT { $$ = $1; }
164 | var_name '.' IDENT
165 { $$ = psprintf("%s.%s", $1, $3); }
169 * BASE_BACKUP [ ( option [ 'value' ] [, ...] ) ]
171 base_backup:
172 K_BASE_BACKUP '(' generic_option_list ')'
174 BaseBackupCmd *cmd = makeNode(BaseBackupCmd);
175 cmd->options = $3;
176 $$ = (Node *) cmd;
178 | K_BASE_BACKUP
180 BaseBackupCmd *cmd = makeNode(BaseBackupCmd);
181 $$ = (Node *) cmd;
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;
192 cmd->slotname = $2;
193 cmd->temporary = $3;
194 cmd->options = $5;
195 $$ = (Node *) cmd;
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;
203 cmd->slotname = $2;
204 cmd->temporary = $3;
205 cmd->plugin = $5;
206 cmd->options = $6;
207 $$ = (Node *) cmd;
211 create_slot_options:
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); }
219 | /* EMPTY */
220 { $$ = NIL; }
223 create_slot_legacy_opt:
224 K_EXPORT_SNAPSHOT
226 $$ = makeDefElem("snapshot",
227 (Node *) makeString("export"), -1);
229 | K_NOEXPORT_SNAPSHOT
231 $$ = makeDefElem("snapshot",
232 (Node *) makeString("nothing"), -1);
234 | K_USE_SNAPSHOT
236 $$ = makeDefElem("snapshot",
237 (Node *) makeString("use"), -1);
239 | K_RESERVE_WAL
241 $$ = makeDefElem("reserve_wal",
242 (Node *) makeBoolean(true), -1);
244 | K_TWO_PHASE
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);
257 cmd->slotname = $2;
258 cmd->wait = false;
259 $$ = (Node *) cmd;
261 | K_DROP_REPLICATION_SLOT IDENT K_WAIT
263 DropReplicationSlotCmd *cmd;
264 cmd = makeNode(DropReplicationSlotCmd);
265 cmd->slotname = $2;
266 cmd->wait = true;
267 $$ = (Node *) cmd;
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);
277 cmd->slotname = $2;
278 cmd->options = $4;
279 $$ = (Node *) cmd;
284 * START_REPLICATION [SLOT slot] [PHYSICAL] %X/%X [TIMELINE %u]
286 start_replication:
287 K_START_REPLICATION opt_slot opt_physical RECPTR opt_timeline
289 StartReplicationCmd *cmd;
291 cmd = makeNode(StartReplicationCmd);
292 cmd->kind = REPLICATION_KIND_PHYSICAL;
293 cmd->slotname = $2;
294 cmd->startpoint = $4;
295 cmd->timeline = $5;
296 $$ = (Node *) cmd;
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;
307 cmd->slotname = $3;
308 cmd->startpoint = $5;
309 cmd->options = $6;
310 $$ = (Node *) cmd;
314 * TIMELINE_HISTORY %u
316 timeline_history:
317 K_TIMELINE_HISTORY UCONST
319 TimeLineHistoryCmd *cmd;
321 if ($2 <= 0)
322 ereport(ERROR,
323 (errcode(ERRCODE_SYNTAX_ERROR),
324 errmsg("invalid timeline %u", $2)));
326 cmd = makeNode(TimeLineHistoryCmd);
327 cmd->timeline = $2;
329 $$ = (Node *) cmd;
333 /* UPLOAD_MANIFEST doesn't currently accept any arguments */
334 upload_manifest:
335 K_UPLOAD_MANIFEST
337 UploadManifestCmd *cmd = makeNode(UploadManifestCmd);
339 $$ = (Node *) cmd;
342 opt_physical:
343 K_PHYSICAL
344 | /* EMPTY */
347 opt_temporary:
348 K_TEMPORARY { $$ = true; }
349 | /* EMPTY */ { $$ = false; }
352 opt_slot:
353 K_SLOT IDENT
354 { $$ = $2; }
355 | /* EMPTY */
356 { $$ = NULL; }
359 opt_timeline:
360 K_TIMELINE UCONST
362 if ($2 <= 0)
363 ereport(ERROR,
364 (errcode(ERRCODE_SYNTAX_ERROR),
365 errmsg("invalid timeline %u", $2)));
366 $$ = $2;
368 | /* EMPTY */ { $$ = 0; }
372 plugin_options:
373 '(' plugin_opt_list ')' { $$ = $2; }
374 | /* EMPTY */ { $$ = NIL; }
377 plugin_opt_list:
378 plugin_opt_elem
380 $$ = list_make1($1);
382 | plugin_opt_list ',' plugin_opt_elem
384 $$ = lappend($1, $3);
388 plugin_opt_elem:
389 IDENT plugin_opt_arg
391 $$ = makeDefElem($1, $2, -1);
395 plugin_opt_arg:
396 SCONST { $$ = (Node *) makeString($1); }
397 | /* EMPTY */ { $$ = NULL; }
400 generic_option_list:
401 generic_option_list ',' generic_option
402 { $$ = lappend($1, $3); }
403 | generic_option
404 { $$ = list_make1($1); }
407 generic_option:
408 ident_or_keyword
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);
426 ident_or_keyword:
427 IDENT { $$ = $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"; }