Tutorial Install PostgreSQL on Linux Debian OS



Hi, today I'm gonna share to you, how to installation PostgreSQL on Debian.


Linux downloads (Debian)

PostgreSQL is available in all Debian versions by default. However, Debian "snapshots" a specific version of PostgreSQL that is then supported throughout the lifetime of that Debian version. The PostgreSQL project maintains an Apt repository with all supported of PostgreSQL available.


Included in Distribution

Debian includes PostgreSQL by default. To install PostgreSQL on Debian, use the apt (or other apt-driving) command:

$ apt install postgresql


PostgreSQL Apt Repository

If the version included in your version of Debian is not the one you want, you can use the PostgreSQL Apt Repository. This repository will integrate with your normal systems and patch management, and provide automatic updates for all supported versions of PostgreSQL throughout the support lifetime of PostgreSQL.

The PostgreSQL Apt repository supports the current versions of Debian:

* bookworm (12.x)

* bullseye (11.x)

* buster (10.x)

* sid (unstable)

on the following architectures:

* amd64

* arm64

* i386 (buster and older)

* ppc64el

* s390x


Automated repository configuration:

$ sudo apt install -y postgresql-common

$ sudo /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh


To manually configure the Apt repository, follow these steps:

# Import the repository signing key:

$ sudo apt install curl ca-certificates

$ sudo install -d /usr/share/postgresql-common/pgdg

$ sudo curl -o /usr/share/postgresql-common/pgdg/apt.postgresql.org.asc --fail https://www.postgresql.org/media/keys/ACCC4CF8.asc


# Create the repository configuration file:

$ sudo sh -c 'echo "deb [signed-by=/usr/share/postgresql-common/pgdg/apt.postgresql.org.asc] https://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'


# Update the package lists:

$ sudo apt update


# Install the latest version of PostgreSQL:

# If you want a specific version, use 'postgresql-16' or similar instead of 'postgresql'

$ sudo apt -y install postgresql


Change postgres password

$ sudo passwd postgres

$ sudo chage -I -1 -m 0 -M 99999 -E -1 postgres

$ sudo chage -l postgres

$ su postgres

$ psql

$ ALTER USER postgres WITH PASSWORD 'Jakarta098';

$ exit

$ sudo systemctl restart postgresql


Add access user postgres in /etc/postgresql/17/main/pg_hba.conf :

host    all             postgres        127.0.0.1/32            scram-sha-256

host    all             postgres        ::1/128                 scram-sha-256

host    all             postgres        0.0.0.0/0               scram-sha-256


Change port, access with IP address, and set max connections

$ cd /etc/postgresql/17/main

$ sudo nano postgresql.conf

Change the following :

port = 6002

listen_addresses = '*'

max_connections = 2048

If done, press keyboard Ctrl + x , then type: y , and then press (enter).

The last one, restart PostgreSQL

$ sudo systemctl restart postgresql


Check 6002 of PostgreSQL has already to expose

$ netstat -tulpn | grep 6002

or

$ echo -n | telnet 127.0.0.1 6002


Done.



Source :

https://www.postgresql.org/download/linux/debian/

https://git-maspaad.blogspot.com/2024/06/linux-user-create-new-user-change.html

https://git-maspaad.blogspot.com/2022/08/linux-check-active-ports.html

https://git-maspaad.blogspot.com/2024/02/telnet-auto-close.html

Comments