Skip to content

RootDBA

DBA expertise: PostgreSQL, SQL Server & MySQL

Menu
  • Home
  • blog
  • PostgreSql
  • MySql
  • Sql Server
  • About AHMED – Root DBA
Menu

upgrade postgresql

Posted on September 1, 2025September 1, 2025 by AHMED

the upgrad decided to two part

  1. minor upgrade (patch) this when we upgrade from same version but with different build number
    1. example upgrade from 15.1 to 15.2.
  2. major upgrade : this is done when we need to upgrade from postgresql version to another
    1. example : upgrade from version 15 to 16 

minor upgrade

Each PostgreSQL version may require minor upgrades throughout its lifecycle to address critical bugs, enhance performance, or mitigate security vulnerabilities. It’s a best practice to review the release notes and test the new build in a non-production environment before applying it to your production system.
additionally you should consider counter measure in case any failure happen during the upgrade that include taking database backup .

how to perform minor upgrade .

first thing is to collect the require information which invovle getting the current version of postgresql by using the following command 

psql –version

or 

SELECT version();

next is to got to postgresql website and check what is the latest build for our version.
for our db the latest version is 15.8 

now we will start by installing the batch but before that we will first take backup for the databases just in case
we will use pg_dumpall which will take backup of the entire DB cluster 

pg_dumpall -U [username] > [filepath].sql

Pasted image 20240915120037.png
to start first stop postgresql services 

systemctl stop [email protected]

update the server repostory , after that you use apt list -- upgrdable to list the of packages we can upgrade 

sudo apt update apt list –upgradable | grep -w postgresql

now we can upgrade the list postgresql packages by using the following command 

sudo apt install postgresql-15*

this will install the latest version and upgrade the binary

after that run the services and check postgresql log for any error .

major upgrade

for our example we will upgrade from version 15 to version 16 

to start you need to first install postgresql 16 on the system 

install postgresql-16 postgresql-client-16

now stop the services for postgresql 15 

systemctl stop [email protected]

locate the data dir for both version 15 and 16 , you can achieve this faster by running the following command 

pg_lsclusters

now we will use the command pg_upgrade and we will fill old data dir and new datadir
for both version as will as the binary directory for both version 

sudo -u postgres pg_upgrade \ –old-datadir=/var/lib/postgresql/15/main \ –new-datadir=/var/lib/postgresql/16/main \ –old-bindir=/usr/lib/postgresql/15/bin \ –new-bindir=/usr/lib/postgresql/16/bin
0
Visited 19 times, 1 visit(s) today
Category: PostgreSql, Postgresql Dba Guide

Post navigation

← PostgreSql backup using pgbackrest
postgresql Setup replication using repmgr →
© 2025 RootDBA | Powered by Minimalist Blog WordPress Theme