Fix search_path to a safe value during maintenance operations.

Jeff Davis <jdavis@postgresql.org>

Commit: 2af07e2f749a9208ca1ed84fa1d8fe0e75833288
Author: Jeff Davis <jdavis@postgresql.org>
Date: 2024-03-05T01:31:38Z
Releases: 17.0
Fix search_path to a safe value during maintenance operations.

While executing maintenance operations (ANALYZE, CLUSTER, REFRESH
MATERIALIZED VIEW, REINDEX, or VACUUM), set search_path to
'pg_catalog, pg_temp' to prevent inconsistent behavior.

Functions that are used for functional indexes, in index expressions,
or in materialized views and depend on a different search path must be
declared with CREATE FUNCTION ... SET search_path='...'.

This change was previously committed as 05e1737351, then reverted in
commit 2fcc7ee7af because it was too late in the cycle.

Preparation for the MAINTAIN privilege, which was previously reverted
due to search_path manipulation hazards.

Discussion: https://postgr.es/m/d4ccaf3658cb3c281ec88c851a09733cd9482f22.camel@j-davis.com
Discussion: https://postgr.es/m/E1q7j7Y-000z1H-Hr%40gemulon.postgresql.org
Discussion: https://postgr.es/m/e44327179e5c9015c8dda67351c04da552066017.camel%40j-davis.com
Reviewed-by: Greg Stark, Nathan Bossart, Noah Misch

Files

PathChange+/−
contrib/amcheck/t/004_verify_nbtree_unique.pl modified +20 −13
contrib/amcheck/verify_nbtree.c modified +2 −0
doc/src/sgml/amcheck.sgml modified +3 −0
doc/src/sgml/brin.sgml modified +3 −1
doc/src/sgml/ref/analyze.sgml modified +6 −0
doc/src/sgml/ref/cluster.sgml modified +6 −0
doc/src/sgml/ref/create_index.sgml modified +6 −0
doc/src/sgml/ref/refresh_materialized_view.sgml modified +6 −0
doc/src/sgml/ref/reindex.sgml modified +6 −0
doc/src/sgml/ref/vacuum.sgml modified +6 −0
src/backend/access/brin/brin.c modified +2 −0
src/backend/catalog/index.c modified +9 −0
src/backend/catalog/namespace.c modified +3 −0
src/backend/commands/analyze.c modified +2 −0
src/backend/commands/cluster.c modified +2 −0
src/backend/commands/indexcmds.c modified +8 −0
src/backend/commands/matview.c modified +2 −0
src/backend/commands/vacuum.c modified +2 −0
src/bin/scripts/t/100_vacuumdb.pl modified +0 −4
src/include/utils/guc.h modified +6 −0
src/test/modules/test_oat_hooks/expected/alter_table.out modified +2 −0
src/test/modules/test_oat_hooks/expected/test_oat_hooks.out modified +4 −0
src/test/regress/expected/matview.out modified +3 −1
src/test/regress/expected/namespace.out modified +44 −0
src/test/regress/expected/privileges.out modified +6 −6
src/test/regress/expected/vacuum.out modified +1 −1
src/test/regress/sql/matview.sql modified +3 −1
src/test/regress/sql/namespace.sql modified +32 −0
src/test/regress/sql/privileges.sql modified +4 −4
src/test/regress/sql/vacuum.sql modified +1 −1

Documentation touched

Discussion