Skip to content

Commit bd0ed77

Browse files
authored
generate locales pre-upgrade; remove libpq symlinking (#856)
* chore: patch pg_cron post-upgrade; generate locales pre-upgrade; remove libpq symlinking * chore: revert pg_cron fix * chore: update locale check
1 parent 2d0bb05 commit bd0ed77

File tree

1 file changed

+15
-24
lines changed
  • ansible/files/admin_api_scripts/pg_upgrade_scripts

1 file changed

+15
-24
lines changed

ansible/files/admin_api_scripts/pg_upgrade_scripts/initiate.sh

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,6 @@ cleanup() {
8585
fi
8686
fi
8787

88-
if [ -f "/usr/lib/postgresql/lib/aarch64/libpq.so.5.bak" ]; then
89-
rm /usr/lib/postgresql/lib/aarch64/libpq.so.5
90-
mv /usr/lib/postgresql/lib/aarch64/libpq.so.5.bak /usr/lib/postgresql/lib/aarch64/libpq.so.5
91-
fi
92-
9388
if [ "$IS_DRY_RUN" = false ]; then
9489
echo "Restarting postgresql"
9590
systemctl enable postgresql
@@ -183,16 +178,6 @@ function initiate_upgrade {
183178

184179
chown -R postgres:postgres "/tmp/pg_upgrade_bin/$PGVERSION"
185180

186-
# Make latest libpq available to pg_upgrade
187-
mkdir -p /usr/lib/aarch64-linux-gnu
188-
if [ -f "/usr/lib/aarch64-linux-gnu/libpq.so.5" ]; then
189-
mv /usr/lib/aarch64-linux-gnu/libpq.so.5 /usr/lib/aarch64-linux-gnu/libpq.so.5.bak
190-
fi
191-
if [ -f "${PG_UPGRADE_BIN_DIR}/libpq.so.5" ]; then
192-
cp "${PG_UPGRADE_BIN_DIR}/libpq.so.5" "${PGLIBNEW}/libpq.so.5"
193-
fi
194-
ln -s "${PGLIBNEW}/libpq.so.5" /usr/lib/aarch64-linux-gnu/libpq.so.5
195-
196181
# upgrade job outputs a log in the cwd; needs write permissions
197182
mkdir -p /tmp/pg_upgrade/
198183
chown -R postgres:postgres /tmp/pg_upgrade/
@@ -208,15 +193,21 @@ function initiate_upgrade {
208193
apt-get update && apt --fix-broken install -y libprotobuf-c1
209194
fi
210195

196+
echo "4. Setup locale if required"
197+
if ! grep -q "^en_US.UTF-8" /etc/locale.gen ; then
198+
echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen
199+
locale-gen
200+
fi
201+
211202
if [ "$IS_DRY_RUN" = false ]; then
212203
# awk NF==3 prints lines with exactly 3 fields, which are the block devices currently not mounted anywhere
213204
# excluding nvme0 since it is the root disk
214-
echo "4. Determining block device to mount"
205+
echo "5. Determining block device to mount"
215206
BLOCK_DEVICE=$(lsblk -dprno name,size,mountpoint,type | grep "disk" | grep -v "nvme0" | awk 'NF==3 { print $1; }')
216207
echo "Block device found: $BLOCK_DEVICE"
217208

218209
mkdir -p "$MOUNT_POINT"
219-
echo "5. Mounting block device"
210+
echo "6. Mounting block device"
220211

221212
sleep 5
222213
e2fsck -pf "$BLOCK_DEVICE"
@@ -234,10 +225,10 @@ function initiate_upgrade {
234225
chmod 600 /etc/postgresql-custom/pgsodium_root.key
235226
fi
236227

237-
echo "6. Disabling extensions and generating post-upgrade script"
228+
echo "7. Disabling extensions and generating post-upgrade script"
238229
handle_extensions
239230

240-
echo "7. Granting SUPERUSER to postgres user"
231+
echo "8. Granting SUPERUSER to postgres user"
241232
run_sql -c "ALTER USER postgres WITH SUPERUSER;"
242233

243234
if [ -d "/usr/share/postgresql/${PGVERSION}" ]; then
@@ -275,7 +266,7 @@ function initiate_upgrade {
275266

276267
export LD_LIBRARY_PATH="${PGLIBNEW}"
277268

278-
echo "8. Creating new data directory, initializing database"
269+
echo "9. Creating new data directory, initializing database"
279270
chown -R postgres:postgres "$MOUNT_POINT/"
280271
rm -rf "${PGDATANEW:?}/"
281272
su -c "$PGBINNEW/initdb -L $PGSHARENEW -D $PGDATANEW/" -s "$SHELL" postgres
@@ -297,7 +288,7 @@ EOF
297288
if [ "$IS_DRY_RUN" = true ]; then
298289
UPGRADE_COMMAND="$UPGRADE_COMMAND --check"
299290
else
300-
echo "9. Stopping postgres; running pg_upgrade"
291+
echo "10. Stopping postgres; running pg_upgrade"
301292

302293
# Extra work to ensure postgres is actually stopped
303294
# Mostly needed for PG12 projects with odd systemd unit behavior
@@ -312,20 +303,20 @@ EOF
312303
su -c "$UPGRADE_COMMAND" -s "$SHELL" postgres
313304

314305
# copying custom configurations
315-
echo "10. Copying custom configurations"
306+
echo "11. Copying custom configurations"
316307
mkdir -p "$MOUNT_POINT/conf"
317308
cp -R /etc/postgresql-custom/* "$MOUNT_POINT/conf/"
318309

319310
# removing wal-g config as to allow it to be explicitly enabled on the new instance
320311
rm -f "$MOUNT_POINT/conf/wal-g.conf"
321312

322313
# copy sql files generated by pg_upgrade
323-
echo "11. Copying sql files generated by pg_upgrade"
314+
echo "12. Copying sql files generated by pg_upgrade"
324315
mkdir -p "$MOUNT_POINT/sql"
325316
cp /tmp/pg_upgrade/*.sql "$MOUNT_POINT/sql/" || true
326317
chown -R postgres:postgres "$MOUNT_POINT/sql/"
327318

328-
echo "12. Cleaning up"
319+
echo "13. Cleaning up"
329320
cleanup "complete"
330321
}
331322

0 commit comments

Comments
 (0)