Automated Upgrade and Migration
I have now upgraded PostgreSQL from version 17 to 18 using a simpler method: directly using the built-in update command.
Please remember to back up your data in advance.
bashsudo apt update
sudo apt upgrade
- At this point, you will be prompted whether to upgrade the database cluster (this will happen twice). If you need to upgrade, select YES. The upgrade will take approximately 3 minutes (depending on the number of databases and machine configuration). The upgrade and data migration will then be completed automatically.
- At the same time, both the old and new versions of the database will be automatically retained, and the new database will be started. You can check this using the
pg_lsclusterscommand.

Traditional and Robust Method
Recently, PostgreSQL released the official version 17. As an avid follower of new versions, I naturally needed to update to the latest. Below is a record of my process for upgrading Postgres 16 to 17 and completing data migration.
Create New Database Version
- My databases are primarily started using Docker, with the following
docker composescript:
yamlversion: '3.8'
services:
# Old version database
postgres16:
container_name: postgres16
image: postgres:16-alpine
volumes:
- /data/postgre16:/var/lib/postgresql/data
ports:
- '5432:5432'
environment:
- POSTGRES_PASSWORD=xxxxxx
-
