reindexdb: Skip reindexing temporary tables and indexes.
authorFujii Masao
Mon, 30 Sep 2024 02:13:55 +0000 (11:13 +0900)
committerFujii Masao
Mon, 30 Sep 2024 02:16:27 +0000 (11:16 +0900)
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 in that case still does not skip them and can cause an error.

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

Author: Fujii Masao
Reviewed-by: Michael Paquier
Discussion: https://postgr.es/m/5f37ee56-14fb-44fe-9150-9eb97e10538b@oss.nttdata.com

src/bin/scripts/reindexdb.c

index 947cfc4065f58d58345e9d95f77a54df2b835f1c..db1d7f07fc07ec661bc35ce2f657dbc0795cf043 100644 (file)
@@ -670,6 +670,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;
 
@@ -692,6 +694,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)