From 8ee74b3f17ab3b9a4f18d585769ba8da05c96fc5 Mon Sep 17 00:00:00 2001
From: Laurenz Albe <laurenz.albe@cybertec.at>
Date: Thu, 15 Jan 2026 23:37:00 +0100
Subject: [PATCH v2] Prevent ANALYZE from waiting for synchronous standbys

If the cluster to upgrade has synchronous replication configured,
"vacuumdb --analyze-only" will hang waiting for the feedback of a
synchronous standby, but there is none during an upgrade.

To prevent that, set "synchronous_commit" to "local" while optimizer
statistics are being calculated.

https://postgr.es/m/flat/d3f21029c8ea11f6a61cfb8045ac11480787411e.camel@cybertec.at
---
 pg_upgradecluster.d/analyze | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/pg_upgradecluster.d/analyze b/pg_upgradecluster.d/analyze
index 6480b5e..2a8d145 100755
--- a/pg_upgradecluster.d/analyze
+++ b/pg_upgradecluster.d/analyze
@@ -19,6 +19,9 @@ case $newversion in
         ;;
 esac
 
+# don't hang waiting for a synchronous standby server
+export PGOPTIONS="$PGOPTIONS -csynchronous_commit=local"
+
 case $newversion in
     9.2|9.3)
         vacuumdb $flags --analyze-only
-- 
2.52.0

