v1-0001-reindexdb-Skip-reindexing-temporary-tables-and-in.patch

text/plain

Filename: v1-0001-reindexdb-Skip-reindexing-temporary-tables-and-in.patch
Type: text/plain
Part: 0
Message: Re: vacuumdb: permission denied for schema "pg_temp_7"

Patch

Same data as JSON: GET /api/v1/attachments/:id/patch the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes. API reference →
Format: format-patch
Series: patch v1-0001
Subject: reindexdb: Skip reindexing temporary tables and indexes.
File+
src/bin/scripts/reindexdb.c 4 0
From b2e857eeaa9161aa4308df5158b8f11935cca977 Mon Sep 17 00:00:00 2001
From: Fujii Masao <fujii@postgresql.org>
Date: Thu, 26 Sep 2024 21:06:49 +0900
Subject: [PATCH v1] reindexdb: Skip reindexing temporary tables and indexes.

Reindexing temp tables or indexes of other sessions is not allowed.
However, reindexdb in parallel mode previously listed them as
the objects to process, leading to failures.

This commit ensures reindexdb in parallel mode skips temporary tables
and indexes by adding a condition based on the relpersistence column
in pg_class to the object listing queries, preventing these issues.

Note that this commit does not affect reindexdb when temporary tables
or indexes are explicitly specified using the -t or -j options;
reindexdb still does not skip them and can cause an error.

Back-patch to v13 where parallel mode was introduced in reindexdb.

Discussion: https://postgr.es/m/5f37ee56-14fb-44fe-9150-9eb97e10538b@oss.nttdata.com
---
 src/bin/scripts/reindexdb.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/src/bin/scripts/reindexdb.c b/src/bin/scripts/reindexdb.c
index 904c196fbb..af0738d933 100644
--- a/src/bin/scripts/reindexdb.c
+++ b/src/bin/scripts/reindexdb.c
@@ -649,6 +649,8 @@ get_parallel_object_list(PGconn *conn, ReindexType type,
 								 "   AND c.relkind IN ("
 								 CppAsString2(RELKIND_RELATION) ", "
 								 CppAsString2(RELKIND_MATVIEW) ")\n"
+								 "   AND c.relpersistence != "
+								 CppAsString2(RELPERSISTENCE_TEMP) "\n"
 								 " ORDER BY c.relpages DESC;");
 			break;
 
@@ -671,6 +673,8 @@ get_parallel_object_list(PGconn *conn, ReindexType type,
 									 " WHERE c.relkind IN ("
 									 CppAsString2(RELKIND_RELATION) ", "
 									 CppAsString2(RELKIND_MATVIEW) ")\n"
+									 "   AND c.relpersistence != "
+									 CppAsString2(RELPERSISTENCE_TEMP) "\n"
 									 " AND ns.nspname IN (");
 
 				for (cell = user_list->head; cell; cell = cell->next)
-- 
2.45.2