52
52
SERVER_ENCODING=$( run_sql -A -t -c " SHOW server_encoding;" )
53
53
54
54
POSTGRES_CONFIG_PATH=" /etc/postgresql/postgresql.conf"
55
- PGBINOLD=" $( pg_config --bindir ) "
55
+ PGBINOLD=" /usr/lib/postgresql/bin "
56
56
57
57
PG_UPGRADE_BIN_DIR=" /tmp/pg_upgrade_bin/$PGVERSION "
58
58
NIX_INSTALLER_PATH=" /tmp/persistent/nix-installer"
@@ -242,10 +242,6 @@ function initiate_upgrade {
242
242
fi
243
243
244
244
PGDATAOLD=$( cat " $POSTGRES_CONFIG_PATH " | grep data_directory | sed " s/data_directory = '\(.*\)'.*/\1/" )
245
- # Resolve symlink if it exists
246
- if [ -L " $PGDATAOLD " ]; then
247
- PGDATAOLD=$( readlink -f " $PGDATAOLD " )
248
- fi
249
245
250
246
PGDATANEW=" $MOUNT_POINT /pgdata"
251
247
@@ -259,12 +255,12 @@ function initiate_upgrade {
259
255
if [ -n " $IS_LOCAL_UPGRADE " ]; then
260
256
mkdir -p " $PG_UPGRADE_BIN_DIR "
261
257
mkdir -p /tmp/persistent/
262
- # Use NIX_FLAKE_VERSION if set, otherwise use default
263
- if [ -n " $NIX_FLAKE_VERSION " ]; then
258
+ if [ -n " $NIX_FLAKE_VERSION " ]; then
264
259
echo " $NIX_FLAKE_VERSION " > " $PG_UPGRADE_BIN_DIR /nix_flake_version"
265
260
else
266
261
echo " a7189a68ed4ea78c1e73991b5f271043636cf074" > " $PG_UPGRADE_BIN_DIR /nix_flake_version"
267
262
fi
263
+
268
264
tar -czf " /tmp/persistent/pg_upgrade_bin.tar.gz" -C " /tmp/pg_upgrade_bin" .
269
265
rm -rf /tmp/pg_upgrade_bin/
270
266
fi
@@ -329,7 +325,6 @@ function initiate_upgrade {
329
325
# upgrade job outputs a log in the cwd; needs write permissions
330
326
mkdir -p /tmp/pg_upgrade/
331
327
chown -R postgres:postgres /tmp/pg_upgrade/
332
- chmod 0700 /tmp/pg_upgrade/
333
328
cd /tmp/pg_upgrade/
334
329
335
330
# Fixing erros generated by previous dpkg executions (package upgrades et co)
@@ -415,6 +410,7 @@ function initiate_upgrade {
415
410
fi
416
411
else
417
412
su -c " $PGBINNEW /initdb -L $PGSHARENEW -D $PGDATANEW / --username=supabase_admin" -s " $SHELL " postgres
413
+
418
414
fi
419
415
420
416
# This line avoids the need to supply the supabase_admin password on the old
@@ -427,51 +423,39 @@ $(cat /etc/postgresql/pg_hba.conf)" > /etc/postgresql/pg_hba.conf
427
423
run_sql -c " select pg_reload_conf();"
428
424
fi
429
425
430
- # Build the base upgrade command
426
+ TMP_CONFIG=" /tmp/pg_upgrade/postgresql.conf"
427
+ cp " $POSTGRES_CONFIG_PATH " " $TMP_CONFIG "
428
+
429
+ # Check if max_slot_wal_keep_size exists in the config
430
+ if grep -q " max_slot_wal_keep_size" " $TMP_CONFIG " ; then
431
+ # Find and replace the existing setting
432
+ sed -i ' s/^\s*max_slot_wal_keep_size\s*=.*$/max_slot_wal_keep_size = -1/' " $TMP_CONFIG "
433
+ else
434
+ # Add the setting if not found
435
+ echo " max_slot_wal_keep_size = -1" >> " $TMP_CONFIG "
436
+ fi
437
+
438
+ chown postgres:postgres " $TMP_CONFIG "
439
+
431
440
UPGRADE_COMMAND=$( cat << EOF
432
- ${PGBINNEW} /pg_upgrade \
441
+ time ${PGBINNEW} /pg_upgrade \
433
442
--old-bindir="${PGBINOLD} " \
434
443
--new-bindir=${PGBINNEW} \
435
- --old-datadir=" ${PGDATAOLD} " \
444
+ --old-datadir=${PGDATAOLD} \
436
445
--new-datadir=${PGDATANEW} \
437
446
--username=supabase_admin \
438
- --jobs="${WORKERS} " -r
447
+ --jobs="${WORKERS} " -r \
448
+ --old-options="-c config_file=$TMP_CONFIG " \
449
+ --old-options="-c shared_preload_libraries='${SHARED_PRELOAD_LIBRARIES} '" \
450
+ --new-options="-c data_directory=${PGDATANEW} " \
451
+ --new-options="-c config_file=$TMP_CONFIG " \
452
+ --new-options="-c shared_preload_libraries='${SHARED_PRELOAD_LIBRARIES} '"
439
453
EOF
440
454
)
441
455
442
- # Add common options including config file
443
- UPGRADE_COMMAND=" $UPGRADE_COMMAND \
444
- --old-options=\" -c shared_preload_libraries='${SHARED_PRELOAD_LIBRARIES} '\" \
445
- --old-options=\" -c data_directory=${PGDATAOLD} \" \
446
- --new-options=\" -c data_directory=${PGDATANEW} \" \
447
- --new-options=\" -c shared_preload_libraries='${SHARED_PRELOAD_LIBRARIES} '\" "
448
-
449
- # Add remaining version-specific options
450
- if [[ " $PGVERSION " =~ ^17.* ]]; then
451
- # Create temporary config file for old instance
452
- TMP_CONFIG=" /tmp/pg_upgrade/postgresql.conf"
453
- cp " $POSTGRES_CONFIG_PATH " " $TMP_CONFIG "
454
- echo " max_slot_wal_keep_size = -1" >> " $TMP_CONFIG "
455
- chown postgres:postgres " $TMP_CONFIG "
456
-
457
- UPGRADE_COMMAND=" $UPGRADE_COMMAND \
458
- --old-options='-c config_file=$TMP_CONFIG ' \
459
- --new-options='-c max_slot_wal_keep_size=-1' \
460
- --new-options='-c unix_socket_directories=/tmp/pg_upgrade'"
461
- else
462
- UPGRADE_COMMAND=" $UPGRADE_COMMAND \
463
- --old-options='-c config_file=${POSTGRES_CONFIG_PATH} '"
464
- fi
465
-
466
456
if [ " $IS_NIX_BASED_SYSTEM " = " true" ]; then
467
- # Ensure nix environment is loaded for both old and new instances
468
- UPGRADE_COMMAND=" . /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh && PGBINOLD=${PGBINOLD} $UPGRADE_COMMAND "
469
- fi
470
-
471
- # Set max_slot_wal_keep_size in environment for PG17 upgrades
472
- if [[ " $PGVERSION " =~ ^17.* ]]; then
473
- export PGDATA_UPGRADE_MAX_SLOT_WAL_KEEP_SIZE=-1
474
- fi
457
+ UPGRADE_COMMAND=" . /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh && $UPGRADE_COMMAND "
458
+ fi
475
459
476
460
if [[ " $PGVERSION " =~ ^17.* ]]; then
477
461
GRN_PLUGINS_DIR=/var/lib/postgresql/.nix-profile/lib/groonga/plugins LC_ALL=en_US.UTF-8 LANGUAGE=en_US.UTF-8 LANG=en_US.UTF-8 LOCALE_ARCHIVE=/usr/lib/locale/locale-archive su -pc " $UPGRADE_COMMAND --check" -s " $SHELL " postgres
@@ -493,20 +477,14 @@ EOF
493
477
CI_stop_postgres
494
478
fi
495
479
496
- # Create and set permissions on socket directory for PG17 upgrades
497
- if [[ " $PGVERSION " =~ ^17.* ]]; then
498
- mkdir -p /tmp/pg_upgrade
499
- chown postgres:postgres /tmp/pg_upgrade
500
- chmod 0700 /tmp/pg_upgrade
501
- fi
502
-
503
480
# Start the old PostgreSQL instance with version-specific options
504
481
if [[ " $PGVERSION " =~ ^17.* ]]; then
505
482
GRN_PLUGINS_DIR=/var/lib/postgresql/.nix-profile/lib/groonga/plugins LC_ALL=en_US.UTF-8 LANGUAGE=en_US.UTF-8 LANG=en_US.UTF-8 LOCALE_ARCHIVE=/usr/lib/locale/locale-archive su -pc " $UPGRADE_COMMAND " -s " $SHELL " postgres
506
483
else
507
484
GRN_PLUGINS_DIR=/var/lib/postgresql/.nix-profile/lib/groonga/plugins LC_ALL=en_US.UTF-8 LC_CTYPE=$SERVER_LC_CTYPE LC_COLLATE=$SERVER_LC_COLLATE LANGUAGE=en_US.UTF-8 LANG=en_US.UTF-8 LOCALE_ARCHIVE=/usr/lib/locale/locale-archive su -pc " $UPGRADE_COMMAND " -s " $SHELL " postgres
508
485
fi
509
486
487
+ # copying custom configurations
510
488
echo " 11. Copying custom configurations"
511
489
mkdir -p " $MOUNT_POINT /conf"
512
490
cp -R /etc/postgresql-custom/* " $MOUNT_POINT /conf/"
0 commit comments