From 4750542d598361b021801c4d56ecdc7603912ef7 Mon Sep 17 00:00:00 2001 From: Amul Sul Date: Fri, 27 Mar 2020 05:05:38 -0400 Subject: [PATCH v12 3/6] Add alter system read only/write syntax Note that syntax doesn't have any implementation. --- src/backend/nodes/copyfuncs.c | 12 ++++++++++++ src/backend/nodes/equalfuncs.c | 9 +++++++++ src/backend/nodes/outfuncs.c | 12 ++++++++++++ src/backend/nodes/readfuncs.c | 15 +++++++++++++++ src/backend/parser/gram.y | 13 +++++++++++++ src/backend/tcop/utility.c | 21 +++++++++++++++++++++ src/bin/psql/tab-complete.c | 6 ++++-- src/include/nodes/nodes.h | 1 + src/include/nodes/parsenodes.h | 10 ++++++++++ src/tools/pgindent/typedefs.list | 1 + 10 files changed, 98 insertions(+), 2 deletions(-) diff --git a/src/backend/nodes/copyfuncs.c b/src/backend/nodes/copyfuncs.c index ba3ccc712c8..7ce1a3146bf 100644 --- a/src/backend/nodes/copyfuncs.c +++ b/src/backend/nodes/copyfuncs.c @@ -4028,6 +4028,15 @@ _copyAlterSystemStmt(const AlterSystemStmt *from) return newnode; } +static AlterSystemWALProhibitState * +_copyAlterSystemWALProhibitState(const AlterSystemWALProhibitState *from) +{ + AlterSystemWALProhibitState *newnode = makeNode(AlterSystemWALProhibitState); + + COPY_SCALAR_FIELD(walprohibited); + return newnode; +} + static CreateSeqStmt * _copyCreateSeqStmt(const CreateSeqStmt *from) { @@ -5414,6 +5423,9 @@ copyObjectImpl(const void *from) case T_AlterSystemStmt: retval = _copyAlterSystemStmt(from); break; + case T_AlterSystemWALProhibitState: + retval = _copyAlterSystemWALProhibitState(from); + break; case T_CreateSeqStmt: retval = _copyCreateSeqStmt(from); break; diff --git a/src/backend/nodes/equalfuncs.c b/src/backend/nodes/equalfuncs.c index a2ef853dc2a..fd54fe3088a 100644 --- a/src/backend/nodes/equalfuncs.c +++ b/src/backend/nodes/equalfuncs.c @@ -1777,6 +1777,12 @@ _equalAlterSystemStmt(const AlterSystemStmt *a, const AlterSystemStmt *b) return true; } +static bool +_equalAlterSystemWALProhibitState(const AlterSystemWALProhibitState *a, const AlterSystemWALProhibitState *b) +{ + COMPARE_SCALAR_FIELD(walprohibited); + return true; +} static bool _equalCreateSeqStmt(const CreateSeqStmt *a, const CreateSeqStmt *b) @@ -3467,6 +3473,9 @@ equal(const void *a, const void *b) case T_AlterSystemStmt: retval = _equalAlterSystemStmt(a, b); break; + case T_AlterSystemWALProhibitState: + retval = _equalAlterSystemWALProhibitState(a, b); + break; case T_CreateSeqStmt: retval = _equalCreateSeqStmt(a, b); break; diff --git a/src/backend/nodes/outfuncs.c b/src/backend/nodes/outfuncs.c index 8392be6d44a..47230ad346a 100644 --- a/src/backend/nodes/outfuncs.c +++ b/src/backend/nodes/outfuncs.c @@ -1359,6 +1359,15 @@ _outAlternativeSubPlan(StringInfo str, const AlternativeSubPlan *node) WRITE_NODE_FIELD(subplans); } +static void +_outAlterSystemWALProhibitState(StringInfo str, + const AlterSystemWALProhibitState *node) +{ + WRITE_NODE_TYPE("ALTERSYSTEMWALPROHIBITSTATE"); + + WRITE_BOOL_FIELD(walprohibited); +} + static void _outFieldSelect(StringInfo str, const FieldSelect *node) { @@ -3938,6 +3947,9 @@ outNode(StringInfo str, const void *obj) case T_AlternativeSubPlan: _outAlternativeSubPlan(str, obj); break; + case T_AlterSystemWALProhibitState: + _outAlterSystemWALProhibitState(str, obj); + break; case T_FieldSelect: _outFieldSelect(str, obj); break; diff --git a/src/backend/nodes/readfuncs.c b/src/backend/nodes/readfuncs.c index d2c8d58070b..f5f3c8cff89 100644 --- a/src/backend/nodes/readfuncs.c +++ b/src/backend/nodes/readfuncs.c @@ -2553,6 +2553,19 @@ _readAlternativeSubPlan(void) READ_DONE(); } +/* + * _readAlterSystemWALProhibitState + */ +static AlterSystemWALProhibitState * +_readAlterSystemWALProhibitState(void) +{ + READ_LOCALS(AlterSystemWALProhibitState); + + READ_BOOL_FIELD(walprohibited); + + READ_DONE(); +} + /* * _readExtensibleNode */ @@ -2875,6 +2888,8 @@ parseNodeString(void) return_value = _readSubPlan(); else if (MATCH("ALTERNATIVESUBPLAN", 18)) return_value = _readAlternativeSubPlan(); + else if (MATCH("ALTERSYSTEMWALPROHIBITSTATE", 27)) + return_value = _readAlterSystemWALProhibitState(); else if (MATCH("EXTENSIBLENODE", 14)) return_value = _readExtensibleNode(); else if (MATCH("PARTITIONBOUNDSPEC", 18)) diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y index 31c95443a5b..db39f7caa91 100644 --- a/src/backend/parser/gram.y +++ b/src/backend/parser/gram.y @@ -477,6 +477,7 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query); %type generic_set set_rest set_rest_more generic_reset reset_rest SetResetClause FunctionSetResetClause +%type system_readonly_state %type TableElement TypedTableElement ConstraintElem TableFuncElement %type columnDef columnOptions @@ -10227,8 +10228,20 @@ AlterSystemStmt: n->setstmt = $4; $$ = (Node *)n; } + | ALTER SYSTEM_P system_readonly_state + { + AlterSystemWALProhibitState *n = makeNode(AlterSystemWALProhibitState); + n->walprohibited = $3; + $$ = (Node *)n; + } ; +system_readonly_state: + READ ONLY + { $$ = true; } + | READ WRITE + { $$ = false; } + ; /***************************************************************************** * diff --git a/src/backend/tcop/utility.c b/src/backend/tcop/utility.c index 53a511f1da8..e9cc4a22324 100644 --- a/src/backend/tcop/utility.c +++ b/src/backend/tcop/utility.c @@ -86,6 +86,7 @@ static void ProcessUtilitySlow(ParseState *pstate, DestReceiver *dest, QueryCompletion *qc); static void ExecDropStmt(DropStmt *stmt, bool isTopLevel); +static void AlterSystemSetWALProhibitState(AlterSystemWALProhibitState *stmt); /* * CommandIsReadOnly: is an executable query read-only? @@ -220,6 +221,7 @@ ClassifyUtilityCommandAsReadOnly(Node *parsetree) return COMMAND_IS_NOT_READ_ONLY; } + case T_AlterSystemWALProhibitState: case T_AlterSystemStmt: { /* @@ -835,6 +837,11 @@ standard_ProcessUtility(PlannedStmt *pstmt, AlterSystemSetConfigFile((AlterSystemStmt *) parsetree); break; + case T_AlterSystemWALProhibitState: + PreventInTransactionBlock(isTopLevel, "ALTER SYSTEM"); + AlterSystemSetWALProhibitState((AlterSystemWALProhibitState *) parsetree); + break; + case T_VariableSetStmt: ExecSetVariableStmt((VariableSetStmt *) parsetree, isTopLevel); break; @@ -2818,6 +2825,7 @@ CreateCommandTag(Node *parsetree) tag = CMDTAG_REFRESH_MATERIALIZED_VIEW; break; + case T_AlterSystemWALProhibitState: case T_AlterSystemStmt: tag = CMDTAG_ALTER_SYSTEM; break; @@ -3678,3 +3686,16 @@ GetCommandLogLevel(Node *parsetree) return lev; } + +/* + * AlterSystemSetWALProhibitState + * + * Execute ALTER SYSTEM READ { ONLY | WRITE } statement. + */ +static void +AlterSystemSetWALProhibitState(AlterSystemWALProhibitState *stmt) +{ + ereport(ERROR, + (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), + errmsg("ALTER SYSTEM READ { ONLY | WRITE } not implemented"))); +} diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c index 6abcbea9634..cfa492c8d81 100644 --- a/src/bin/psql/tab-complete.c +++ b/src/bin/psql/tab-complete.c @@ -1894,9 +1894,11 @@ psql_completion(const char *text, int start, int end) /* ALTER SERVER VERSION */ else if (Matches("ALTER", "SERVER", MatchAny, "VERSION", MatchAny)) COMPLETE_WITH("OPTIONS"); - /* ALTER SYSTEM SET, RESET, RESET ALL */ + /* ALTER SYSTEM READ, SET, RESET, RESET ALL */ else if (Matches("ALTER", "SYSTEM")) - COMPLETE_WITH("SET", "RESET"); + COMPLETE_WITH("SET", "RESET", "READ"); + else if (Matches("ALTER", "SYSTEM", "READ")) + COMPLETE_WITH("ONLY", "WRITE"); else if (Matches("ALTER", "SYSTEM", "SET|RESET")) COMPLETE_WITH_QUERY(Query_for_list_of_alter_system_set_vars); else if (Matches("ALTER", "SYSTEM", "SET", MatchAny)) diff --git a/src/include/nodes/nodes.h b/src/include/nodes/nodes.h index caed683ba92..5972800479f 100644 --- a/src/include/nodes/nodes.h +++ b/src/include/nodes/nodes.h @@ -411,6 +411,7 @@ typedef enum NodeTag T_RefreshMatViewStmt, T_ReplicaIdentityStmt, T_AlterSystemStmt, + T_AlterSystemWALProhibitState, T_CreatePolicyStmt, T_AlterPolicyStmt, T_CreateTransformStmt, diff --git a/src/include/nodes/parsenodes.h b/src/include/nodes/parsenodes.h index dc2bb40926a..6677f8ac470 100644 --- a/src/include/nodes/parsenodes.h +++ b/src/include/nodes/parsenodes.h @@ -3211,6 +3211,16 @@ typedef struct AlterSystemStmt VariableSetStmt *setstmt; /* SET subcommand */ } AlterSystemStmt; +/* ---------------------- + * Alter System Read Statement + * ---------------------- + */ +typedef struct AlterSystemWALProhibitState +{ + NodeTag type; + bool walprohibited; +} AlterSystemWALProhibitState; + /* ---------------------- * Cluster Statement (support pbrown's cluster index implementation) * ---------------------- diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list index fb57b8393f1..4ba4ec1cbdc 100644 --- a/src/tools/pgindent/typedefs.list +++ b/src/tools/pgindent/typedefs.list @@ -86,6 +86,7 @@ AlterStatsStmt AlterSubscriptionStmt AlterSubscriptionType AlterSystemStmt +AlterSystemWALProhibitState AlterTSConfigType AlterTSConfigurationStmt AlterTSDictionaryStmt -- 2.18.0