Ubuntu/Linux
Prep Ubuntu 14 (noble) for Installation##
Time requirement: 10 mins
PostgreSQL 17 Installation on Ubuntu 24
Add the PostgreSQL 17 repository for automated updates:
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
Import the repository signing key to assure valid deployment:
curl -fsSL https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/postgresql.gpg
Update the package list
sudo apt update
Step 2 - Install PostgreSQL 17
Install PostgreSQL 17 and contrib modules:
sudo apt install postgresql-17
output follows:
Created symlink /etc/systemd/system/multi-user.target.wants/postgresql.service → /usr/lib/systemd/system/postgresql.service.
Setting up postgresql-17 (17.4-1.pgdg24.04+2) ...
Creating new PostgreSQL cluster 17/main ...
/usr/lib/postgresql/17/bin/initdb -D /var/lib/postgresql/17/main --auth-local peer --auth-host scram-sha-256 --no-instructions
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/postgresql/17/main ... ok
Start and enable PostgreSQL service:
sudo systemctl start postgresql
sudo systemctl enable postgresql
Check the version and ensure it’s Postgresql 17:
psql --version
Step 3 - Configure PostgreSQL 17
Edit postgresql.conf to allow remote connections
sudo nano /etc/postgresql/17/main/postgresql.conf
listen_addresses = '*'
Configure PostgreSQL to use md5 password authentication
sudo sed -i '/^host/s/ident/md5/' /etc/postgresql/17/main/pg_hba.conf
sudo sed -i '/^local/s/peer/trust/' /etc/postgresql/17/main/pg_hba.conf
echo "host all all 0.0.0.0/0 md5" | sudo tee -a /etc/postgresql/17/main/pg_hba.conf
Restart PostgreSQL
sudo systemctl restart postgresql
Allow PostgreSQL port through the uncomplicated firewall (ufw):
sudo ufw allow 5432/tcp
Step 4 - Connect to PostgreSQL
sudo -u postgres psql
ALTER USER postgres PASSWORD '${NewPassword}';
or using psql tool:
psql -h localhost -U postgres -d postgres
Removing PostgreSQL
As postgres is tied to default port 5432, assure you have a clean environment prior to installation.
This assures errors upon loading (especially during automated installs)
do not fail silently
how to remove Postgresql from ubuntu noble (24.02)
-
use APT tool to remove software packages
sudo apt-get --purge remove postgresql postgresql-*
or
sudo apt-get --purge remove postgresql postgresql-doc postgresql-common
-
optionally remove folders:
sudo rm -rf /var/lib/postgresql/
sudo rm -rf /var/log/postgresql/
sudo rm -rf /etc/postgresql/
-
remove postgresql user:
sudo deluser postgres