Skip to content

Commit f79c4d1

Browse files
authored
chore: more pg_upgrade script nix-centric fixes (#1059)
1 parent 93e4db1 commit f79c4d1

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

.github/workflows/publish-nix-pgupgrade-scripts.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Publish pg_upgrade_scripts
1+
name: Publish nix pg_upgrade_scripts
22

33
on:
44
push:

ansible/files/admin_api_scripts/pg_upgrade_scripts/initiate.sh

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ LOG_FILE="/var/log/pg-upgrade-initiate.log"
4040
POST_UPGRADE_EXTENSION_SCRIPT="/tmp/pg_upgrade/pg_upgrade_extensions.sql"
4141
OLD_PGVERSION=$(run_sql -A -t -c "SHOW server_version;")
4242

43+
SERVER_LC_COLLATE=$(run_sql -A -t -c "SHOW lc_collate;")
44+
SERVER_LC_CTYPE=$(run_sql -A -t -c "SHOW lc_ctype;")
45+
SERVER_ENCODING=$(run_sql -A -t -c "SHOW server_encoding;")
46+
4347
POSTGRES_CONFIG_PATH="/etc/postgresql/postgresql.conf"
4448
PGBINOLD="/usr/lib/postgresql/bin"
4549
PGLIBOLD="/usr/lib/postgresql/lib"
@@ -268,8 +272,11 @@ function initiate_upgrade {
268272
echo "4. Setup locale if required"
269273
if ! grep -q "^en_US.UTF-8" /etc/locale.gen ; then
270274
echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen
271-
locale-gen
272275
fi
276+
if ! grep -q "^C.UTF-8" /etc/locale.gen ; then
277+
echo "C.UTF-8 UTF-8" >> /etc/locale.gen
278+
fi
279+
locale-gen
273280

274281
if [ -z "$IS_CI" ] && [ -z "$IS_LOCAL_UPGRADE" ]; then
275282
# awk NF==3 prints lines with exactly 3 fields, which are the block devices currently not mounted anywhere
@@ -345,7 +352,12 @@ function initiate_upgrade {
345352
echo "9. Creating new data directory, initializing database"
346353
chown -R postgres:postgres "$MOUNT_POINT/"
347354
rm -rf "${PGDATANEW:?}/"
348-
su -c "$PGBINNEW/initdb -L $PGSHARENEW -D $PGDATANEW/" -s "$SHELL" postgres
355+
356+
if [ "$IS_NIX_UPGRADE" = "true" ]; then
357+
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 -c ". /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh && $PGBINNEW/initdb --encoding=$SERVER_ENCODING --lc-collate=$SERVER_LC_COLLATE --lc-ctype=$SERVER_LC_CTYPE -L $PGSHARENEW -D $PGDATANEW/" -s "$SHELL" postgres
358+
else
359+
su -c "$PGBINNEW/initdb -L $PGSHARENEW -D $PGDATANEW/" -s "$SHELL" postgres
360+
fi
349361

350362
UPGRADE_COMMAND=$(cat <<EOF
351363
time ${PGBINNEW}/pg_upgrade \
@@ -363,9 +375,8 @@ EOF
363375

364376
if [ "$IS_NIX_BASED_SYSTEM" = "true" ]; then
365377
UPGRADE_COMMAND=". /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh && $UPGRADE_COMMAND"
366-
fi
367-
368-
su -c "$UPGRADE_COMMAND --check" -s "$SHELL" postgres
378+
fi
379+
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 --check" -s "$SHELL" postgres
369380

370381
echo "10. Stopping postgres; running pg_upgrade"
371382
# Extra work to ensure postgres is actually stopped
@@ -381,11 +392,7 @@ EOF
381392
CI_stop_postgres
382393
fi
383394

384-
if [ "$IS_NIX_BASED_SYSTEM" = "true" ]; then
385-
LC_ALL=en_US.UTF-8 LC_CTYPE=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
386-
else
387-
su -c "$UPGRADE_COMMAND" -s "$SHELL" postgres
388-
fi
395+
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
389396

390397
# copying custom configurations
391398
echo "11. Copying custom configurations"

0 commit comments

Comments
 (0)