This is an old revision of the document!
Overview
PostgreSQL's latest major version is 12. That being said, it is fairly easy to migrate between versions even major ones. There are couple ways to upgrade, depending on how much you want to risk to compromise with. Practically there are 2 ways of Upgrade in any database:
- In-Place: You upgrade on the same host
- Out-Of-Place: You upgrade using 2nd host, most often via Replication or data migration directly to the new release.
We will discuss both methods in this section. So let's get started:
In-Place
Important to note here is that even the In-place upgrade isn't so risky as with other databases (Oracle / SQL / DB2 and so on). The steps to perform In-Place upgrade in PostgreSQL between major version are pretty straight-forward. So let's get going: In this case, we will also, upgrade from 9.6 → 10.
Install the new Release
You can install the new version by either compiling the source or using package manager (in my case yum).
[root@localhost 9.6]# yum install postgresql10-server.x86_64 Loaded plugins: fastestmirror, langpacks Dependencies Resolved ============================================================================================================================================================================================================================================================================= Package Arch Version Repository Size ============================================================================================================================================================================================================================================================================= Installing: postgresql10-server x86_64 10.11-2PGDG.rhel7 pgdg10 4.5 M Installing for dependencies: libicu x86_64 50.2-3.el7 base 6.9 M postgresql10 x86_64 10.11-2PGDG.rhel7 pgdg10 1.6 M postgresql10-libs x86_64 10.11-2PGDG.rhel7 pgdg10 356 k Transaction Summary ============================================================================================================================================================================================================================================================================= Installed: postgresql10-server.x86_64 0:10.11-2PGDG.rhel7 Dependency Installed: libicu.x86_64 0:50.2-3.el7 postgresql10.x86_64 0:10.11-2PGDG.rhel7 postgresql10-libs.x86_64 0:10.11-2PGDG.rhel7 Complete!
The new version, will come in it's own binary and data locations:
/var/lib/pgsql/10/data /usr/pgsql-10/bin
Create Database base
After that, we have to create a database base:
-bash-4.2$ /usr/pgsql-10/bin/initdb -D /var/lib/pgsql/10/data The files belonging to this database system will be owned by user "postgres". This user must also own the server process. The database cluster will be initialized with locale "en_US.UTF-8". The default database encoding has accordingly been set to "UTF8". The default text search configuration will be set to "english". Data page checksums are disabled. fixing permissions on existing directory /var/lib/pgsql/10/data ... ok creating subdirectories ... ok selecting default max_connections ... 100 selecting default shared_buffers ... 128MB selecting default timezone ... America/New_York selecting dynamic shared memory implementation ... posix creating configuration files ... ok running bootstrap script ... ok performing post-bootstrap initialization ... ok syncing data to disk ... ok WARNING: enabling "trust" authentication for local connections You can change this by editing pg_hba.conf or using the option -A, or --auth-local and --auth-host, the next time you run initdb. Success. You can now start the database server using: /usr/pgsql-10/bin/pg_ctl -D /var/lib/pgsql/10/data -l logfile start -bash-4.2$
It is very good idea to check for possible compatability problems between the two versions in order to play it safe:
-bash-4.2$ /usr/pgsql-10/bin/pg_upgrade -b /usr/pgsql-9.6/bin/ -B /usr/pgsql-10/bin -d /var/lib/pgsql/9.6/data -D /var/lib/pgsql/10/data -c Performing Consistency Checks on Old Live Server ------------------------------------------------ Checking cluster versions ok Checking database user is the install user ok Checking database connection settings ok Checking for prepared transactions ok Checking for reg* data types in user tables ok Checking for contrib/isn with bigint-passing mismatch ok Checking for invalid "unknown" user columns ok Checking for hash indexes ok Checking for presence of required libraries ok Checking database user is the install user ok Checking for prepared transactions ok *Clusters are compatible* <- This line is VERY IMPORTANT :) -bash-4.2$