On Fri, 2023-06-09 at 15:16 -0700, Jeff Davis wrote:
> On Fri, 2023-06-09 at 20:54 +0000, Jeff Davis wrote:
> > Fix search_path to a safe value during maintenance operations.
> 
> Looks like this is causing pg_amcheck failures in the buildfarm.
> Investigating...

It looks related to bt_index_check_internal(), which is called by SQL
functions bt_index_check() and bt_index_parent_check(). SQL functions
can be called in parallel, so it raises the error:

  ERROR:  cannot set parameters during a parallel operation

because commit 05e1737351 added the SetConfigOption() line. Normally
those functions would not be called in parallel, but
debug_parallel_mode makes that happen.

Attached a patch to mark those functions as PARALLEL UNSAFE, which
fixes the problem.

Alternatively, I could just take out that line, as those SQL functions
are not controlled by the MAINTAIN privilege. But for consistency I
think it's a good idea to leave it in so that index functions are
called with the right search path for amcheck.


-- 
Jeff Davis
PostgreSQL Contributor Team - AWS

From 0bc11bbc4b06228d33bd9fc6b29dcc9a25d81151 Mon Sep 17 00:00:00 2001
From: Jeff Davis <[email protected]>
Date: Fri, 9 Jun 2023 17:24:53 -0700
Subject: [PATCH v1] amcheck: mark bt_index_check() PARALLEL UNSAFE.

These functions call bt_index_check_internal(), which needs to set the
right search path before executing any index functions.

Discussion: https://postgr.es/m/20230609232446.GA123624@nathanxps13
---
 contrib/amcheck/Makefile              |  4 +++-
 contrib/amcheck/amcheck--1.3--1.4.sql | 13 +++++++++++++
 contrib/amcheck/amcheck.control       |  2 +-
 3 files changed, 17 insertions(+), 2 deletions(-)
 create mode 100644 contrib/amcheck/amcheck--1.3--1.4.sql

diff --git a/contrib/amcheck/Makefile b/contrib/amcheck/Makefile
index b82f221e50..4896c586f8 100644
--- a/contrib/amcheck/Makefile
+++ b/contrib/amcheck/Makefile
@@ -7,7 +7,9 @@ OBJS = \
 	verify_nbtree.o
 
 EXTENSION = amcheck
-DATA = amcheck--1.2--1.3.sql amcheck--1.1--1.2.sql amcheck--1.0--1.1.sql amcheck--1.0.sql
+DATA = amcheck--1.3--1.4.sql amcheck--1.2--1.3.sql amcheck--1.1--1.2.sql \
+	amcheck--1.0--1.1.sql amcheck--1.0.sql
+
 PGFILEDESC = "amcheck - function for verifying relation integrity"
 
 REGRESS = check check_btree check_heap
diff --git a/contrib/amcheck/amcheck--1.3--1.4.sql b/contrib/amcheck/amcheck--1.3--1.4.sql
new file mode 100644
index 0000000000..409cd55195
--- /dev/null
+++ b/contrib/amcheck/amcheck--1.3--1.4.sql
@@ -0,0 +1,13 @@
+/* contrib/amcheck/amcheck--1.3--1.4.sql */
+
+-- complain if script is sourced in psql, rather than via CREATE EXTENSION
+\echo Use "ALTER EXTENSION amcheck UPDATE TO '1.4'" to load this file. \quit
+
+--
+-- Mark bt_index_check functions as PARALLEL UNSAFE.
+--
+ALTER FUNCTION bt_index_check(regclass) PARALLEL UNSAFE;
+ALTER FUNCTION bt_index_check(regclass, boolean) PARALLEL UNSAFE;
+ALTER FUNCTION bt_index_parent_check(regclass) PARALLEL UNSAFE;
+ALTER FUNCTION bt_index_parent_check(regclass, boolean) PARALLEL UNSAFE;
+ALTER FUNCTION bt_index_parent_check(regclass, boolean, boolean) PARALLEL UNSAFE;
diff --git a/contrib/amcheck/amcheck.control b/contrib/amcheck/amcheck.control
index ab50931f75..e67ace01c9 100644
--- a/contrib/amcheck/amcheck.control
+++ b/contrib/amcheck/amcheck.control
@@ -1,5 +1,5 @@
 # amcheck extension
 comment = 'functions for verifying relation integrity'
-default_version = '1.3'
+default_version = '1.4'
 module_pathname = '$libdir/amcheck'
 relocatable = true
-- 
2.34.1

Reply via email to