Fix indentation in twophase.c
[pgsql.git] / src / backend / replication / repl_gram.y
blob0c874e33cf6ab00fef55ade3b3750cd13166fe8f
1 %{
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
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"
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
36 #define YYFREE pfree
40 %expect 0
41 %name-prefix="replication_yy"
43 %union
45 char *str;
46 bool boolval;
47 uint32 uintval;
48 XLogRecPtr recptr;
49 Node *node;
50 List *list;
51 DefElem *defelt;
54 /* Non-keyword tokens */
55 %token <str> SCONST IDENT
56 %token <uintval> UCONST
57 %token <recptr> RECPTR
59 /* Keyword tokens. */
60 %token K_BASE_BACKUP
61 %token K_IDENTIFY_SYSTEM
62 %token K_READ_REPLICATION_SLOT
63 %token K_SHOW
64 %token K_START_REPLICATION
65 %token K_CREATE_REPLICATION_SLOT
66 %token K_DROP_REPLICATION_SLOT
67 %token K_TIMELINE_HISTORY
68 %token K_WAIT
69 %token K_TIMELINE
70 %token K_PHYSICAL
71 %token K_LOGICAL
72 %token K_SLOT
73 %token K_RESERVE_WAL
74 %token K_TEMPORARY
75 %token K_TWO_PHASE
76 %token K_EXPORT_SNAPSHOT
77 %token K_NOEXPORT_SNAPSHOT
78 %token K_USE_SNAPSHOT
80 %type <node> command
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;
103 opt_semicolon: ';'
104 | /* EMPTY */
107 command:
108 identify_system
109 | base_backup
110 | start_replication
111 | start_logical_replication
112 | create_replication_slot
113 | drop_replication_slot
114 | read_replication_slot
115 | timeline_history
116 | show
120 * IDENTIFY_SYSTEM
122 identify_system:
123 K_IDENTIFY_SYSTEM
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);
136 n->slotname = $2;
137 $$ = (Node *) n;
142 * SHOW setting
144 show:
145 K_SHOW var_name
147 VariableShowStmt *n = makeNode(VariableShowStmt);
148 n->name = $2;
149 $$ = (Node *) n;
152 var_name: IDENT { $$ = $1; }
153 | var_name '.' IDENT
154 { $$ = psprintf("%s.%s", $1, $3); }
158 * BASE_BACKUP [ ( option [ 'value' ] [, ...] ) ]
160 base_backup:
161 K_BASE_BACKUP '(' generic_option_list ')'
163 BaseBackupCmd *cmd = makeNode(BaseBackupCmd);
164 cmd->options = $3;
165 $$ = (Node *) cmd;
167 | K_BASE_BACKUP
169 BaseBackupCmd *cmd = makeNode(BaseBackupCmd);
170 $$ = (Node *) cmd;
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;
181 cmd->slotname = $2;
182 cmd->temporary = $3;
183 cmd->options = $5;
184 $$ = (Node *) cmd;
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;
192 cmd->slotname = $2;
193 cmd->temporary = $3;
194 cmd->plugin = $5;
195 cmd->options = $6;
196 $$ = (Node *) cmd;
200 create_slot_options:
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); }
208 | /* EMPTY */
209 { $$ = NIL; }
212 create_slot_legacy_opt:
213 K_EXPORT_SNAPSHOT
215 $$ = makeDefElem("snapshot",
216 (Node *) makeString("export"), -1);
218 | K_NOEXPORT_SNAPSHOT
220 $$ = makeDefElem("snapshot",
221 (Node *) makeString("nothing"), -1);
223 | K_USE_SNAPSHOT
225 $$ = makeDefElem("snapshot",
226 (Node *) makeString("use"), -1);
228 | K_RESERVE_WAL
230 $$ = makeDefElem("reserve_wal",
231 (Node *) makeBoolean(true), -1);
233 | K_TWO_PHASE
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);
246 cmd->slotname = $2;
247 cmd->wait = false;
248 $$ = (Node *) cmd;
250 | K_DROP_REPLICATION_SLOT IDENT K_WAIT
252 DropReplicationSlotCmd *cmd;
253 cmd = makeNode(DropReplicationSlotCmd);
254 cmd->slotname = $2;
255 cmd->wait = true;
256 $$ = (Node *) cmd;
261 * START_REPLICATION [SLOT slot] [PHYSICAL] %X/%X [TIMELINE %d]
263 start_replication:
264 K_START_REPLICATION opt_slot opt_physical RECPTR opt_timeline
266 StartReplicationCmd *cmd;
268 cmd = makeNode(StartReplicationCmd);
269 cmd->kind = REPLICATION_KIND_PHYSICAL;
270 cmd->slotname = $2;
271 cmd->startpoint = $4;
272 cmd->timeline = $5;
273 $$ = (Node *) cmd;
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;
284 cmd->slotname = $3;
285 cmd->startpoint = $5;
286 cmd->options = $6;
287 $$ = (Node *) cmd;
291 * TIMELINE_HISTORY %d
293 timeline_history:
294 K_TIMELINE_HISTORY UCONST
296 TimeLineHistoryCmd *cmd;
298 if ($2 <= 0)
299 ereport(ERROR,
300 (errcode(ERRCODE_SYNTAX_ERROR),
301 errmsg("invalid timeline %u", $2)));
303 cmd = makeNode(TimeLineHistoryCmd);
304 cmd->timeline = $2;
306 $$ = (Node *) cmd;
310 opt_physical:
311 K_PHYSICAL
312 | /* EMPTY */
315 opt_temporary:
316 K_TEMPORARY { $$ = true; }
317 | /* EMPTY */ { $$ = false; }
320 opt_slot:
321 K_SLOT IDENT
322 { $$ = $2; }
323 | /* EMPTY */
324 { $$ = NULL; }
327 opt_timeline:
328 K_TIMELINE UCONST
330 if ($2 <= 0)
331 ereport(ERROR,
332 (errcode(ERRCODE_SYNTAX_ERROR),
333 errmsg("invalid timeline %u", $2)));
334 $$ = $2;
336 | /* EMPTY */ { $$ = 0; }
340 plugin_options:
341 '(' plugin_opt_list ')' { $$ = $2; }
342 | /* EMPTY */ { $$ = NIL; }
345 plugin_opt_list:
346 plugin_opt_elem
348 $$ = list_make1($1);
350 | plugin_opt_list ',' plugin_opt_elem
352 $$ = lappend($1, $3);
356 plugin_opt_elem:
357 IDENT plugin_opt_arg
359 $$ = makeDefElem($1, $2, -1);
363 plugin_opt_arg:
364 SCONST { $$ = (Node *) makeString($1); }
365 | /* EMPTY */ { $$ = NULL; }
368 generic_option_list:
369 generic_option_list ',' generic_option
370 { $$ = lappend($1, $3); }
371 | generic_option
372 { $$ = list_make1($1); }
375 generic_option:
376 ident_or_keyword
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);
394 ident_or_keyword:
395 IDENT { $$ = $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"; }