Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1uSkXM-00Cb0u-9y for pgsql-bugs@arkaria.postgresql.org; Fri, 20 Jun 2025 22:48:44 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1uSkXK-004iNY-7b for pgsql-bugs@arkaria.postgresql.org; Fri, 20 Jun 2025 22:48:42 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1uSkXJ-004iNO-Uv for pgsql-bugs@lists.postgresql.org; Fri, 20 Jun 2025 22:48:42 +0000 Received: from mail-il1-x136.google.com ([2607:f8b0:4864:20::136]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1uSkXI-00385x-31 for pgsql-bugs@lists.postgresql.org; Fri, 20 Jun 2025 22:48:41 +0000 Received: by mail-il1-x136.google.com with SMTP id e9e14a558f8ab-3d948ce7d9dso9368265ab.2 for ; Fri, 20 Jun 2025 15:48:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1750459720; x=1751064520; darn=lists.postgresql.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=E3sD52ssLn/Fq4u0KCaSLZLVQMEcGqSAqTA3x+xA1TQ=; b=CqoWXcsQAK9H5G5T0ZX5kv/eJGUHedlCbjDbDxYj+tQVTR+ZElGEtYzfJcQVJu4LO1 S4HxFPVkFila3JoMy52KNRCAsX1KPv1PQcbdQAdSXAB9MwqEychtwvUsY6CUBcfk8mBC M1re0I5JM5LgrUKBmRUUA/FqXM/A6m//yx0fCZKFs2YuehwKzgjLWsI3LEZr1rBFqeOl tLfyg53skYclgVbQcbtKI8bmrJA1Wbf01bjGIH2twqTs9oKiaACDW7/fwCH8zdiBfmap vFGovywFLqceN+GZn6VZh1BRZyNv8CQhTs0J57W1bLGLBBFbUk9dRW97SW1d7y1vEzY3 Ksqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750459720; x=1751064520; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=E3sD52ssLn/Fq4u0KCaSLZLVQMEcGqSAqTA3x+xA1TQ=; b=K1VsADDUtBcfwIRib6bCcQoPWshaPIrgJR85dEYyLF1K23RhpRvBT7IPGyhDx9VJ/5 kPo9G/vIN5ZJNggl9x1B+Y2nWM8ARdGORf7ixq+2C5hk9NvOEyUqYSOSzqa0NwwMUS59 uiAy/28x5Al6Dy5SIJrDnmertZU0R38jHwRX5ju+FN91fVcGGn7rVfSoCgI+pUw0Vu7/ ANwQ6XOactVC/zWW7/oVG48ZMeuiFeoJ7x8XQXP1IvJlxCg8BftBspw0LeYO4MGMHPyY 1dXw1t8cGphPu0QWBHTJlYkhILXWQNX9jniW6Jc4ohY6okrDHFmEdOk/TuKmcBKll9qU thOg== X-Forwarded-Encrypted: i=1; AJvYcCWhAV1bB2n+xK8unO5ihe0spLirarMG9pQGjmfw461B6yvef/9xQruShvX7F4BwQxAxqEyDDoP2GTNg@lists.postgresql.org X-Gm-Message-State: AOJu0YxghLahn+wfv6EVzNnJfC/L3ziyI5tn7rgifrG1CzjzwxKx6eyS HTaSVRSkxESForLbFrWAaRfb7F72YntSCnWG4k9l/z+lDgalAHWyf1yx X-Gm-Gg: ASbGncu0pAmO1CBl5SWSH2OnKFU+ZTfwjWZFk9RZMIoK0m1ksavahv7z++olnwa7aXR lM6NzyB/kJFqcLWUhviANUd5da3b/r5o4nVKbrKnKkTJtBh0tdvk2fgj3obwYLr56INyOZG/S6H XxD4kctYVPiw+2gWMwqhSC2J41sFygoGl43dc5ZehYbEK0V0zwuJvqj2OWPgoEh0oi19+v5/rOO MevI7PaVL1nmDsfGC+hqTbJHK/0KbBZAaA94FSPDNYHUSBPrR+QJVJO6KiDvHQufLPTI41T0LbL CuW59fj5GI0ptd7BGct2VsRNC34JxP3WCAK7B4CfJTj74Q3qLIQkFeovW3yESZ4ESYY115wtl+/ FA6ee91U82XMBYvBq3nrUgjNTdEivZmTgyTrm+Iiqv/iq0/AAAHhx X-Google-Smtp-Source: AGHT+IGZFtCyh08NQZMlKt4l5dvBmJvZWMQQzi2xZTXCIvFr04n6e2+o4AMbzsiM7MgtmSu+wzA/CQ== X-Received: by 2002:a05:6e02:154c:b0:3dd:c946:a273 with SMTP id e9e14a558f8ab-3de38c5878amr50018615ab.9.1750459720079; Fri, 20 Jun 2025 15:48:40 -0700 (PDT) Received: from nathan (162-195-168-172.lightspeed.stlsmo.sbcglobal.net. [162.195.168.172]) by smtp.gmail.com with ESMTPSA id e9e14a558f8ab-3de37627219sm9413915ab.17.2025.06.20.15.48.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Jun 2025 15:48:39 -0700 (PDT) Date: Fri, 20 Jun 2025 17:48:37 -0500 From: Nathan Bossart To: Tom Lane Cc: mert@futo.org, pgsql-bugs@lists.postgresql.org Subject: Re: BUG #18964: `ALTER DATABASE ... RESET ...` fails to reset extension parameters that no longer exist Message-ID: References: <18964-ba09dea8c98fccd6@postgresql.org> <2474668.1750451081@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="PRs+Mbx6GUCOxb5m" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --PRs+Mbx6GUCOxb5m Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Here is a fragile proof-of-concept patch that demonstrates roughly what I had in mind. -- nathan --PRs+Mbx6GUCOxb5m Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=fix_alter_role_reset_v1.patch diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c index 667df448732..ba1bf49e83c 100644 --- a/src/backend/utils/misc/guc.c +++ b/src/backend/utils/misc/guc.c @@ -250,7 +250,7 @@ static void reapply_stacked_values(struct config_generic *variable, GucContext curscontext, GucSource cursource, Oid cursrole); static bool validate_option_array_item(const char *name, const char *value, - bool skipIfNoPermissions); + bool skipIfNoPermissions, bool isReset); static void write_auto_conf_file(int fd, const char *filename, ConfigVariable *head); static void replace_auto_config_value(ConfigVariable **head_p, ConfigVariable **tail_p, const char *name, const char *value); @@ -6497,7 +6497,7 @@ GUCArrayAdd(ArrayType *array, const char *name, const char *value) Assert(value); /* test if the option is valid and we're allowed to set it */ - (void) validate_option_array_item(name, value, false); + (void) validate_option_array_item(name, value, false, false); /* normalize name (converts obsolete GUC names to modern spellings) */ record = find_option(name, false, true, WARNING); @@ -6574,7 +6574,7 @@ GUCArrayDelete(ArrayType *array, const char *name) Assert(name); /* test if the option is valid and we're allowed to set it */ - (void) validate_option_array_item(name, NULL, false); + (void) validate_option_array_item(name, NULL, false, true); /* normalize name (converts obsolete GUC names to modern spellings) */ record = find_option(name, false, true, WARNING); @@ -6672,7 +6672,7 @@ GUCArrayReset(ArrayType *array) *eqsgn = '\0'; /* skip if we have permission to delete it */ - if (validate_option_array_item(val, NULL, true)) + if (validate_option_array_item(val, NULL, true, true)) continue; /* else add it to the output array */ @@ -6707,10 +6707,18 @@ GUCArrayReset(ArrayType *array) */ static bool validate_option_array_item(const char *name, const char *value, - bool skipIfNoPermissions) + bool skipIfNoPermissions, bool isReset) { struct config_generic *gconf; + bool skip_errors; + + /* + * For RESET and RESET ALL, we treat unknown custom GUCs with reserved + * prefixes the same as if a placeholder is created. That requires we + * skip errors in find_option(). + */ + skip_errors = (isReset && valid_custom_variable_name(name)); /* * There are three cases to consider: @@ -6731,14 +6739,19 @@ validate_option_array_item(const char *name, const char *value, * name is not known and can't be created as a placeholder. Throw error, * unless skipIfNoPermissions is true, in which case return false. */ - gconf = find_option(name, true, skipIfNoPermissions, ERROR); - if (!gconf) + gconf = find_option(name, true, skipIfNoPermissions || skip_errors, ERROR); + if (!gconf && !skip_errors) { /* not known, failed to make a placeholder */ return false; } - if (gconf->flags & GUC_CUSTOM_PLACEHOLDER) + /* + * If we reach this point and gconf is NULL, we know we're dealing with a + * RESET or RESET ALL command for an unknown custom GUC with a reserved + * prefix. We treat that the same as if a placeholder was created. + */ + if (!gconf || gconf->flags & GUC_CUSTOM_PLACEHOLDER) { /* * We cannot do any meaningful check on the value, so only permissions --PRs+Mbx6GUCOxb5m--