First, create a postgresql repository file
$ sudo sh -c 'echo "deb https://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
Then, import repository signing key
$ wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
Update the package list
$ sudo apt update
Install postgresql
$ sudo apt install postgresql-16 -y
Configure postgresql to listen on all interfaces rather than just localhost
- Edit /etc/postgresql/16/main/postgresql.conf
$ sudo vi /etc/postgresql/16/main/postgresql.conf
- Add below configuration
listen_addresses = '*'
- Save and exit
Start postgresql
$ sudo systemctl start postgresql
Enable postgresql on boot
$ sudo systemctl enable postgresql
Allow postgresql port (5432) on ufw
$ sudo ufw allow 5432/tcp
Access to postgresql database and check version
$ sudo su - postgrespostgres@host:~$ psqlpostgres=# select version();
The output should look like below
Type \q to exit psql
No comments:
Post a Comment