1. Prepare for PostgreSQL18 installation
bash brew services install postgresql@18
brew services stop postgresql@17
If you have any extensions installed outside the default PostgreSQL installation, make them available for PostgreSQL 18 as well.
brew reinstall pgvector
2. Upgrade PostgreSQL 18
brew install postgresql@18/opt/homebrew/opt/postgresql@18/bin/pg_upgrade \
-d /opt/homebrew/var/postgresql@17 \
-D /opt/homebrew/var/postgresql@18 \
-b /opt/homebrew/opt/postgresql@17/bin \
-B /opt/homebrew/opt/postgresql@18/bin
logs:
% /opt/homebrew/opt/postgresql@18/bin/pg_upgrade \
-d /opt/homebrew/var/postgresql@17 \
-D /opt/homebrew/var/postgresql@18 \
-b /opt/homebrew/opt/postgresql@17/bin \
-B /opt/homebrew/opt/postgresql@18/bin
Performing Consistency Checks
-----------------------------
Checking cluster versions ok
Checking database connection settings ok
Checking database user is the install user ok
Checking for prepared transactions ok
Checking for contrib/isn with bigint-passing mismatch ok
Checking for valid logical replication slots ok
Checking for subscription state ok
Checking data type usage ok
Checking for objects affected by Unicode update ok
Checking for not-null constraint inconsistencies ok
Creating dump of global objects ok
Creating dump of database schemas
ok
Checking for presence of required libraries ok
Checking database user is the install user ok
Checking for prepared transactions ok
Checking for new cluster tablespace directories ok
If pg_upgrade fails after this point, you must re-initdb the
new cluster before continuing.
Performing Upgrade
------------------
Setting locale and encoding for new cluster ok
Analyzing all rows in the new cluster ok
Freezing all rows in the new cluster ok
Deleting files from new pg_xact ok
Copying old pg_xact to new server ok
Setting oldest XID for new cluster ok
Setting next transaction ID and epoch for new cluster ok
Deleting files from new pg_multixact/offsets ok
Copying old pg_multixact/offsets to new server ok
Deleting files from new pg_multixact/members ok
Copying old pg_multixact/members to new server ok
Setting next multixact ID and offset for new cluster ok
Resetting WAL archives ok
Setting frozenxid and minmxid counters in new cluster ok
Restoring global objects in the new cluster ok
Restoring database schemas in the new cluster
ok
Copying user relation files
ok
Setting next OID for new cluster ok
Sync data directory to disk ok
Creating script to delete old cluster ok
Checking for extension updates notice
Your installation contains extensions that should be updated
with the ALTER EXTENSION command. The file
update_extensions.sql
when executed by psql by the database superuser will update
these extensions.
Upgrade Complete
----------------
Some statistics are not transferred by pg_upgrade.
Once you start the new server, consider running these two commands:
/opt/homebrew/opt/postgresql@18/bin/vacuumdb --all --analyze-in-stages --missing-stats-only
/opt/homebrew/opt/postgresql@18/bin/vacuumdb --all --analyze-only
Running this script will delete the old cluster's data files:
./delete_old_cluster.sh
3. Post Upgrade Activities
\connect searchdb
ALTER EXTENSION "vector" UPDATE;
ALTER EXTENSION "btree_gist" UPDATE;
#Once you start the new server, consider running these two commands:
/opt/homebrew/opt/postgresql@18/bin/vacuumdb --all --analyze-in-stages --missing-stats-only
/opt/homebrew/opt/postgresql@18/bin/vacuumdb --all --analyze-only
./delete_old_cluster.sh
4. Troubleshooting
Symptom:
Performing Consistency Checks
-----------------------------
Checking cluster versions ok
old cluster does not use data checksums but the new one does
Failure, exiting
Fix:
# Remove the new PostgreSQL 18 data directory
rm -rf /opt/homebrew/var/postgresql@18
# Initialize without checksums to match your old cluster
/opt/homebrew/opt/postgresql@18/bin/initdb -D /opt/homebrew/var/postgresql@18 --no-data-checksums
Symptom:
Checking for presence of required libraries fatal
Your installation references loadable libraries that are missing from the
new installation. You can add these libraries to the new installation,
or remove the functions using them from the old installation. A list of
problem libraries is in the file:
/opt/homebrew/var/postgresql@18/pg_upgrade_output.d/20251021T115934.477/loadable_libraries.txt
Failure, exiting
Fix:#
# Reinstall extension to make it available for new PG version
# pgvector used as example
brew reinstall pgvector