Skip to content

Instantly share code, notes, and snippets.

@petravic
Last active May 20, 2020 11:24
Show Gist options
  • Save petravic/e042969217d7e636cba5c04ebb5a10a8 to your computer and use it in GitHub Desktop.
Save petravic/e042969217d7e636cba5c04ebb5a10a8 to your computer and use it in GitHub Desktop.
PostgreSQL 12 instalation/upgrade on Debian Linux

Custom PostgreSQL install repository setup

Install to be able to sign custom repository

apt install gnupg gnupg2

Add custom repository to apt list

nano /etc/apt/sources.list.d/pgdg.list

In Nano add this line and save

deb http://apt.postgresql.org/pub/repos/apt/ buster-pgdg main

Sign added repository

wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -

Signing needs to return

OK

Update repositories

apt update

New PostgreSQL version instalation

Install new PostgreSQL version

apt install postgresql-12

If database has connections outside localhost (for you to be able to connect with desktop client)

cd /etc/postgresql/12/main/
nano postgresql.conf

In nano find (CTRL + W) listen_addresses, remove comment symbol (#) and CHANGE localhost with *

listen_addresses = '*'

To setup hosts that can access database open confiruration file

nano pg_hba.conf

In Nano add hosts that need to connect to database

host all all 10.63.0.0/16 md5

Check if postgresql is active listening on configured port (default 5432)

lsof -i -P -n | grep LISTEN

Cluster management for upgrading old PostgreSQL version to newer one

Drop default empty cluster created with new version instalation

pg_dropcluster 12 main

Stop old version cluster before upgrade

pg_ctlcluster 11 main stop

Upgrade old version cluster to new version (in this case 11->12)

pg_upgradecluster -v 12 11 main -m upgrade

Start upgraded cluster

pg_ctlcluster 12 main start

Reload deamon to use new version on server restart

systemctl daemon-reload
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment