Hi all,
(Original author and Alvaro in CC, for comments)

reindexdb --schema has the idea of not quoting the schema given in
input of the command line.  For example, if a schema uses upper-case
characters, the command could fail.  Perhaps a fmtIdEnc() should be
applied, in the same fashion as --tablespace?  This point has come
from Alvaro, during a recent review for a separate patch.

Here is the suggested change:
        case REINDEX_SCHEMA:
-           appendPQExpBufferStr(sql, name);
+           appendPQExpBufferStr(sql, fmtIdEnc(name, PQclientEncoding(conn)));

There may be a point in treating that as a bug, but that's also a
backward-incompatible change so perhaps that could just be left as-is.
The new quoting behavior feels upgraded to me, though, but perhaps I'm
just biased.

Comments and/or opinions are welcome.
Thanks,
--
Michael
From 4f523f7174af6ab7ab18c55b08f7d42ab83e6046 Mon Sep 17 00:00:00 2001
From: Michael Paquier <[email protected]>
Date: Sat, 14 Nov 2026 11:18:03 +0900
Subject: [PATCH] reindexdb: Fix quoting for schema name in REINDEX SCHEMA

The quoting used for the schema name was incorrect, leading to a failure
in running an internal REINDEX query when specifying a quoted schema.

Like --tablespace, let's treat schema names as double-quoted
identifiers.

Reported-by: Alvaro Herrera <[email protected]>
Discussion: https://postgr.es/m/TODO
Backpatch-through: 15 (?) or not as it could be argued that this is a
backward-incompatible break.
---
 src/bin/scripts/reindexdb.c        | 2 +-
 src/bin/scripts/t/090_reindexdb.pl | 5 +++++
 doc/src/sgml/ref/reindexdb.sgml    | 1 +
 3 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/src/bin/scripts/reindexdb.c b/src/bin/scripts/reindexdb.c
index f955a6f05473..41b7da6276f1 100644
--- a/src/bin/scripts/reindexdb.c
+++ b/src/bin/scripts/reindexdb.c
@@ -569,7 +569,7 @@ gen_reindex_command(PGconn *conn, ReindexType type, const 
char *name,
                        appendQualifiedRelation(sql, name, conn, echo);
                        break;
                case REINDEX_SCHEMA:
-                       appendPQExpBufferStr(sql, name);
+                       appendPQExpBufferStr(sql, fmtIdEnc(name, 
PQclientEncoding(conn)));
                        break;
        }
 
diff --git a/src/bin/scripts/t/090_reindexdb.pl 
b/src/bin/scripts/t/090_reindexdb.pl
index 467e50e6b3b2..e72df83992d0 100644
--- a/src/bin/scripts/t/090_reindexdb.pl
+++ b/src/bin/scripts/t/090_reindexdb.pl
@@ -303,6 +303,11 @@ $node->issues_sql_like(
        ],
        qr/statement:\ REINDEX INDEX "s'4"."i'4";/,
        'parallel reindexdb for index with quotes in name');
+# The schema name given to REINDEX SCHEMA must be quoted.
+$node->issues_sql_like(
+       [ 'reindexdb', '--schema' => q{s'4}, 'postgres' ],
+       qr/statement: REINDEX SCHEMA "s'4";/,
+       'reindexdb for schema with quotes in name');
 # Note that the ordering of the commands is not stable, so the second
 # command for s2.t2 is not checked after.
 $node->issues_sql_like(
diff --git a/doc/src/sgml/ref/reindexdb.sgml b/doc/src/sgml/ref/reindexdb.sgml
index a90e48ea86ba..50875c513d5f 100644
--- a/doc/src/sgml/ref/reindexdb.sgml
+++ b/doc/src/sgml/ref/reindexdb.sgml
@@ -210,6 +210,7 @@ PostgreSQL documentation
       <listitem>
        <para>
         Reindex <replaceable class="parameter">schema</replaceable> only.
+        (This name is processed as a double-quoted identifier.)
         Multiple schemas can be reindexed by writing multiple
         <option>-S</option> switches.
        </para>
-- 
2.56.0

Attachment: signature.asc
Description: PGP signature

Reply via email to