iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more
You cannot upgrade PostgreSQL 16 to 18 by replacing the Docker image tag. The new image supplies PostgreSQL 18 executables, but it does not convert the existing PostgreSQL 16 data directory into a PostgreSQL 18 cluster. Perform a supported major-version migration first, then configure the container volume for the PostgreSQL 18 image layout.
Why changing the image tag is not a database upgrade
PostgreSQL 16 to 18 is a major-version change. Major releases can alter internal storage formats and system-table layouts, so a cluster created by one major version cannot simply be opened by another. PostgreSQL’s upgrade documentation explains that “For major releases of PostgreSQL, the internal data storage format is subject to change, thus complicating upgrades.” PostgreSQL: Upgrading a PostgreSQL Cluster.
A Docker tag selects server software; it does not migrate the files in a persistent volume. PostgreSQL protects against starting an incompatible data directory with a different major-version server. This differs from a minor update within the same major version, where the data directory remains compatible and updated executables can generally use it while the server is stopped.
Crashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minutePC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11What changed in the PostgreSQL 18 Docker image
The Docker Official Image changed its default data-directory arrangement for PostgreSQL 18 and newer. Its documentation states: “The PGDATA environment variable of the image was changed to be version specific in PostgreSQL 18 and above.” Docker Official Image: postgres.
#1 Best Overall
| Image generation | Default data directory | Declared volume mount point |
|---|---|---|
| PostgreSQL 17 and below | /var/lib/postgresql/data |
/var/lib/postgresql/data |
| PostgreSQL 18 and above | For PostgreSQL 18, /var/lib/postgresql/18/docker |
/var/lib/postgresql |
With an older image, mounting a volume at /var/lib/postgresql can miss the actual data directory. In that case, data may go into an anonymous volume that is not reused when the container is recreated. Conversely, adopting the PostgreSQL 18 parent-volume layout for existing files requires putting them in the major-version-specific subdirectory described by the image documentation. Moving files into that layout is directory restructuring, not a conversion of the cluster’s storage format.
Choose a migration method before changing persistent storage
There is no single best method for every database. The right choice depends on database size, acceptable downtime, available disk space, extensions, rollback needs, and deployment topology. The official documentation describes the methods, but does not establish a universal runtime or space requirement for a particular service.
Rank #2
| Method | How it works | Downtime and space | Key considerations |
|---|---|---|---|
pg_upgrade |
Builds the new cluster’s system tables and reuses or copies old user-data files after compatibility checks. | Downtime depends on the operation and workload; no general duration or disk figure is established. | Requires old and new PostgreSQL binaries and cluster directories. Copy is the default; link and clone modes have specific filesystem and safety implications. Check extension and module compatibility. |
| Logical dump and restore | Exports database objects and data from the old cluster and restores them into a new one, for example with pg_dumpall. |
Downtime and temporary space depend on the chosen workflow and workload; no general figures are established. | Use a logical backup and restore procedure. A filesystem-level copy alone is not a major-version migration. |
| Replication-based migration | Uses a replication workflow to move changes or data between clusters. | Depends on topology and the specific procedure; no general figures are established. | Can suit particular downtime requirements, but must follow the PostgreSQL procedure appropriate to the deployment. |
When to use pg_upgrade
pg_upgrade is designed for major-version upgrades and can reuse data files when compatibility checks pass. It needs both PostgreSQL versions’ binaries and access to the old and new cluster directories. Run pg_upgrade --check before the real upgrade, and also use the applicable check for the selected transfer mode.
The Tool Desk
Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Copy mode makes a separate copy of the data files. Link mode is faster and uses less space, but the relevant data directories must be on the same filesystem. Once the new cluster has started in link mode, the old cluster may no longer be safe to start. Do not treat the old directory as a rollback copy after that point.
Rank #3
When to use dump and restore or replication
Logical dump and restore is an alternative when a logical migration better fits the database or operational plan. Replication methods may be suitable where the topology and downtime target support them. In either case, follow the procedure for the exact PostgreSQL versions and deployment; these options are not interchangeable with copying a data directory at the filesystem level.
Check extensions and application compatibility
A successful server-level migration does not prove every extension or application integration is ready for PostgreSQL 18. In particular, pg_upgrade cannot verify the binary compatibility of external modules. Install the appropriate shared-object files for the new cluster and run extension updates when the applicable instructions require them. Review application-facing migration notes, then validate the service against the new cluster before retiring the old one.
Plan the Docker change as two separate tasks
- Confirm the actual versions. Verify the running server version and intended target. A move from 16 to 18 is a major-version migration, regardless of the container tag.
- Secure recovery options. Back up the database and retain a recovery route before altering persistent storage or running an upgrade.
- Select and follow a migration procedure. Use
pg_upgrade, logical dump and restore, or a replication method appropriate to the database and downtime requirements. - Check dependencies. Confirm that extensions, custom modules, and application components are compatible with the target version.
- Set the image’s volume layout. PostgreSQL 17 and below use
/var/lib/postgresql/data; PostgreSQL 18 uses/var/lib/postgresqlas the declared volume and defaults to/var/lib/postgresql/18/dockerforPGDATA. - Run checks and validate. Complete migration checks before starting the new cluster, and verify application behavior before discarding the old cluster.
The exact commands depend on details such as Compose configuration, custom PGDATA, named versus bind volumes, extensions, replication setup, architecture, and filesystem layout. Consult the version-specific procedures rather than treating this sequence as a one-size-fits-all command recipe. PostgreSQL: pg_upgrade and PostgreSQL 16: Upgrading a PostgreSQL Cluster.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
What the mount-path change can and cannot do
Correcting the mount point ensures the container uses the intended persistent storage layout. It does not make PostgreSQL 16 files readable as a PostgreSQL 18 cluster. Complete the database migration with a supported PostgreSQL method, and handle the Docker volume layout as a separate configuration change.
Quick Recap
Best Value
- Docker, Docker Swarm, Docker Compose, Programmer, Developer, Coding, Programming, Software Engineer, Code, DevOps, Deploy, Deployment, Kubernetes, Salt, Puppet, Chef, Terraform, Container, AWS, Azure, Cloud, Geek, Funny, Computer, Software, Tech, IT
- Integration, Scrum, Compile, Compilation, Science, Bug, Debug, Python, Linux, Java, Javascript, Scala, Dotnet, Kotlin
- Lightweight, Classic fit, Double-needle sleeve and bottom hem
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

