Solved Need procedure to upgrade my databases

Well i do "pkg upgrade". And i end up with versions too new, where i should have used to older versions to make dumps and to reimport.
My procedure is "broken"....
Feel free to advice.
 
haha, well I will said I will go with a container or something that let me install the older version and work from there to export then load onto the new one
 
What DB? I had to use a -f to restore a DB one time with MariaDB (dumped 13.1, restored to 12-something; 4/5 restored no problem but 1 needed -f but still imported/ran fine)
 
Sounds like the perfect use case for ZFS. Roll it back and export.

But to me if you have to do that to upgrade a program maybe you should look at another dB.

ZFS replication is perfect for problems like this no? Is this a UFS system?
 
you ask you get, this one was ai,
Code:
oot@myfreebsd:/var/db/postgres # cat upgrade_postgresql  
#!/bin/sh
set -eu

OLD_VER="18"
NEW_VER="19"
PG_HOME="/var/db/postgres"
DUMP_FILE="${PG_HOME}/pg${OLD_VER}_full_backup.sql"
OLD_DATA="${PG_HOME}/data${OLD_VER}"
NEW_DATA="${PG_HOME}/data${NEW_VER}"

# Ensure script is run as root
if [ "$(id -u)" -ne 0 ]; then
    echo "Error: This script must be run as root." >&2
    exit 1
fi

echo "==> Step 1: Dumping PostgreSQL ${OLD_VER} databases and roles..."
su -l postgres -c "pg_dumpall -f '${DUMP_FILE}'"

# Verify dump file exists and is non-empty
if [ ! -s "${DUMP_FILE}" ]; then
    echo "Error: Dump file ${DUMP_FILE} is missing or empty. Aborting!" >&2
    exit 1
fi
echo "Dump successful: $(ls -lh "${DUMP_FILE}" | awk '{print $5}')"

echo "==> Step 2: Backing up configuration files..."
cp -p "${OLD_DATA}/postgresql.conf" "${PG_HOME}/postgresql.conf.pg${OLD_VER}.bak"
cp -p "${OLD_DATA}/pg_hba.conf" "${PG_HOME}/pg_hba.conf.pg${OLD_VER}.bak"

echo "==> Step 3: Stopping PostgreSQL ${OLD_VER} and swapping packages..."
service postgresql stop
pkg delete -y "postgresql${OLD_VER}-server" "postgresql${OLD_VER}-client"
pkg install -y "postgresql${NEW_VER}-server" "postgresql${NEW_VER}-client"

echo "==> Step 4: Initializing PostgreSQL ${NEW_VER}..."
service postgresql initdb

echo ""
echo "========================================================================="
echo "PAUSE: PostgreSQL ${NEW_VER} is initialized at ${NEW_DATA}."
echo "If you had custom settings, review and merge them now from:"
echo "  - ${PG_HOME}/postgresql.conf.pg${OLD_VER}.bak"
echo "  - ${PG_HOME}/pg_hba.conf.pg${OLD_VER}.bak"
echo "Press [Enter] when ready to start PostgreSQL ${NEW_VER} and restore data..."
echo "========================================================================="
read -r _

echo "==> Step 5: Starting PostgreSQL ${NEW_VER} and importing dump..."
service postgresql start
su -l postgres -c "psql -v ON_ERROR_STOP=1 -f '${DUMP_FILE}' postgres"

echo "==> Step 6: Rebuilding optimizer statistics..."
su -l postgres -c "vacuumdb --all --analyze-in-stages"

echo ""
echo "Upgrade to PostgreSQL ${NEW_VER} complete!"
echo "Once verified, remember to clean up:"
echo "  rm -rf '${OLD_DATA}' '${DUMP_FILE}'"
root@myfreebsd:/var/db/postgres #

Need something similar mariadb & other.
 
yeah, that is what I was saying but using containers/podman instead of installing on system :)... (Im still learning about podman on freebsd but I think should work almost the same)
 
Back
Top