@@ -6252,14 +6252,16 @@ flatten_set_variable_args(const char *name, List *args)
62526252 * SET command
62536253 */
62546254void
6255- ExecSetVariableStmt (VariableSetStmt * stmt )
6255+ ExecSetVariableStmt (VariableSetStmt * stmt , bool isTopLevel )
62566256{
62576257GucAction action = stmt -> is_local ?GUC_ACTION_LOCAL :GUC_ACTION_SET ;
62586258
62596259switch (stmt -> kind )
62606260{
62616261case VAR_SET_VALUE :
62626262case VAR_SET_CURRENT :
6263+ if (stmt -> is_local )
6264+ RequireTransactionChain (isTopLevel ,"SET LOCAL" );
62636265(void )set_config_option (stmt -> name ,
62646266ExtractSetVariableArgs (stmt ),
62656267 (superuser () ?PGC_SUSET :PGC_USERSET ),
@@ -6269,7 +6271,6 @@ ExecSetVariableStmt(VariableSetStmt *stmt)
626962710 );
62706272break ;
62716273case VAR_SET_MULTI :
6272-
62736274/*
62746275 * Special-case SQL syntaxes. The TRANSACTION and SESSION
62756276 * CHARACTERISTICS cases effectively set more than one variable
@@ -6281,6 +6282,8 @@ ExecSetVariableStmt(VariableSetStmt *stmt)
62816282{
62826283ListCell * head ;
62836284
6285+ RequireTransactionChain (isTopLevel ,"SET TRANSACTION" );
6286+
62846287foreach (head ,stmt -> args )
62856288{
62866289DefElem * item = (DefElem * )lfirst (head );
@@ -6329,6 +6332,8 @@ ExecSetVariableStmt(VariableSetStmt *stmt)
63296332ereport (ERROR ,
63306333(errcode (ERRCODE_FEATURE_NOT_SUPPORTED ),
63316334errmsg ("SET LOCAL TRANSACTION SNAPSHOT is not implemented" )));
6335+
6336+ RequireTransactionChain (isTopLevel ,"SET TRANSACTION" );
63326337Assert (IsA (con ,A_Const ));
63336338Assert (nodeTag (& con -> val )== T_String );
63346339ImportSnapshot (strVal (& con -> val ));
@@ -6338,7 +6343,13 @@ ExecSetVariableStmt(VariableSetStmt *stmt)
63386343stmt -> name );
63396344break ;
63406345case VAR_SET_DEFAULT :
6346+ if (stmt -> is_local )
6347+ RequireTransactionChain (isTopLevel ,"SET LOCAL" );
6348+ /* fall through */
63416349case VAR_RESET :
6350+ if (strcmp (stmt -> name ,"transaction_isolation" )== 0 )
6351+ RequireTransactionChain (isTopLevel ,"RESET TRANSACTION" );
6352+
63426353(void )set_config_option (stmt -> name ,
63436354NULL ,
63446355 (superuser () ?PGC_SUSET :PGC_USERSET ),