How To Install PostgreSQL on Ubuntu
Installing PostgreSQL on Ubuntu 22.04
Start by updating package index and installing PostgreSQL:
sudo apt update
sudo apt install postgresql postgresql-contrib
After installation check if PostgreSQL running by:
sudo service postgresql status
Set postgres user's password:
sudo -i -u postgres
psql
\password postgres
Enter your password twice and then quit PostgreSQL prompt:
\q
To go back to original user:
exit
Allowing Connections to PostgreSQL
Update the postgresql.conf file located in /etc/postgresql/{version}/main/postgresql.conf as shown in below image. Update listen_addresses with value '*'
Since we are using v14 for this example:
sudo nano /etc/postgresql/14/main/postgresql.conf
Update pg_hba.conf file as shown in below image.
sudo nano /etc/postgresql/14/main/pg_hba.conf
Simply restart PostgreSQL after these changes:
sudo systemctl restart postgresql
Open port 5432 in your firewall:
sudo ufw allow 5432/tcp
sudo ufw reload
Test from your client if you can access PostgreSQL.
Comments
Comments are closed