How to Install PostgreSQL on Ubuntu 22.04 | Holhol24
PostgreSQL is a unfastened and open-source relational database control machine (ORDBMS) emphasizing extensibility and SQL compliance. It is understood for its robust popularity for reliability, information integrity, and function.
PostgreSQL is to be had for Linux, Windows, FreeBSD, OpenBSD, and macOS.
In this submit, we will be able to see find out how to set up PostgreSQL on Ubuntu 22.04.
Install PostgreSQL on Ubuntu 22.04
You can set up the PostgreSQL database server from,
1. Install PostgreSQL from Ubuntu Repository
Installing PostgreSQL from the Ubuntu repository is a simple approach. Hardly it takes 5 mins to put in PostgreSQL.
First, replace the repository index.
sudo apt replace
Then, set up the newest model of PostgreSQL (v14) the usage of the beneath command.
sudo apt set up -y postgresql
By now, the PostgreSQL provider will probably be up and operating. You can take a look at the standing of the provider with the beneath command.
sudo systemctl standing postgresql
Output:
● postgresql.provider - PostgreSQL RDBMS Loaded: loaded (/lib/systemd/machine/postgresql.provider; enabled; seller preset: enabled) Active: lively (exited) since Wed 2022-05-25 01:39:45 EDT; 2min 5s in the past Process: 4794 ExecStart=/bin/true (code=exited, standing=0/SUCCESS) Main PID: 4794 (code=exited, standing=0/SUCCESS) CPU: 1ms May 25 01:39:45 ubuntu2204 systemd[1]: Starting PostgreSQL RDBMS... May 25 01:39:45 ubuntu2204 systemd[1]: Finished PostgreSQL RDBMS.
2. Install PostgreSQL from PostreSQL Repository
PostgreSQL Global Development Group publishes programs for Ubuntu working machine via devoted repositories, and the programs of their repository are more energizing than the ones to be had within the OS repository.
First, upload the PostgreSQL repository in your machine with the beneath command.
wget -qO - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo gpg --dearmor -o /usr/percentage/keyrings/postgresql-keyring.gpg echo "deb [arch=amd64 signed-by=/usr/share/keyrings/postgresql-keyring.gpg] http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" | sudo tee /and many others/apt/assets.listing.d/postgresql.listing
Then, replace the repository index.
sudo apt replace
Finally, set up the newest model of PostgreSQL the usage of the beneath command.
sudo apt set up -y postgresql
By now, the PostgreSQL provider must be up and operating.
Change PostgreSQL Server Listening Address
By default, PostgreSQL listens at the localhost (127.0.0.1). This conduct restricts exterior packages from connecting to the database. So, you want to configure PostgreSQL to hear the machine IP deal with to permit connections from exterior packages. To do this, edit the postgresql.conf
record.
sudo nano /and many others/postgresql/14/primary/postgresql.conf
Then, set the listen_addresses
to *
or machine
.
listen_addresses = '192.168.0.10'
Finally, restart the PostgreSQL provider.
sudo systemctl restart postgresql
Access PostgreSQL Database Server
To set up the PostgreSQL database, it is important to log in as a postgres
person (Linux person) and must invoke PSQL shell the usage of the psql
command.
sudo -u postgres psql
Output:
psql (14.3 (Ubuntu 14.3-0ubuntu0.22.04.1)) Type "help" for lend a hand. postgres=#
On psql
shell, run the beneath command to switch the postgres
person (Database admin password).
postgres=# password
OR
postgres=# password postgres
Conclusion
That’s All. I am hoping you may have realized find out how to set up PostgreSQL on Ubuntu 22.04.