Table of Contents
Today, In this article we will show you how to install PostgreSQL 13 on Ubuntu 22.04 LTS Linux. A highly well-known open source Object-Relational database management system (DBMS) designed for dependability, efficiency, and data integrity assurance is called PostgreSQL. With over 30 years of development, the project has established a solid reputation for dependability, feature robustness, and performance.
A platform-independent object-relational database management system is called Postgres (ORDBMS). The database management system is a common component of Linux distributions. Additionally, Windows and macOS computers support its use. The DBMS is suitable for data warehouse databases due to object relationality. In contrast to relational database management systems like MySQL, it allows for the relational storage of complex data items in the database.
Postgres utilizes a client-server architecture. The server is in charge of overseeing the databases, processing client requests, and responding to them. A client software with a graphical user interface is often included in Linux distributions in addition to the server and a command line-based client. In a distributed architecture, client and server communication occurs across a TCP/IP connection. We mentioned below are the steps to install PostgreSQL 13 on Ubuntu 22.04 LTS Linux.
Steps to install PostgreSQL 13 on Ubuntu 22.04 LTS Linux
Update Ubuntu system
Step 1: We always work on a latest release of OS to make sure there are no old dependency issues. Login to your Ubuntu server and run the following commands to update all the packages installed.
sudo apt update && sudo apt -y full-upgrade[ -f /var/run/reboot-required ] && sudo reboot -f
Step 2: Once the system has been updated, We recommend you perform a reboot to get the new kernel running incase it was updated.
sudo reboot
Add PostgreSQL 13 repository to Ubuntu 22.04|20.04|18.04
Step 1: Install required dependency packages
sudo apt updatesudo apt install curl gpg gnupg2 software-properties-common apt-transport-https lsb-release ca-certificates
Step 2: Now that we have updated and rebooted our system, let’s add the APT repository required to pull the packages form the PostgreSQL repository.
curl -fsSL gpg –dearmor -o /etc/apt/trusted.gpg.d/postgresql.gpg
Step 3: After importing GPG key, add repository contents to your Ubuntu 22.04|20.04|18.04 system:
echo “deb `lsb_release -cs`-pgdg main” |sudo tee /etc/apt/sources.list.d/pgdg.list
Step 4: The repository added contains many different packages including third party addons. They include:
Install PostgreSQL 13 on Ubuntu 22.04|20.04|18.04
Step 1: With the repository added we can install the PostgreSQL 13 packages on our Ubuntu 22.04|20.04|18.04 Linux server. But first update the package index for the version to be available at the OS level.
sudo apt update
Step 2: The run the commands below to install PostgreSQL 13 on Ubuntu 22.04|20.04|18.04 Linux system.
sudo apt install postgresql-13 postgresql-client-13
Test PostgreSQL Connection
Step 1: During installation, a postgres user is created automatically. This user has full superadmin access to your entire PostgreSQL instance. Before you switch to this account, your logged in system user should have sudo privileges.
sudo su – postgres
Step 2: Let’s reset this user password to a strong Password we can remember.
psql -c “alter user postgres with password ‘StrongAdminP@ssw0rd’”
Step 3: Start PostgreSQL prompt by using the command:
$ psql
Step 4: Get connection details like below.
$ psqlpsql (13.7 (Ubuntu 13.7-1.pgdg22.04+1))Type “help” for help.
postgres=# conninfo
Step 5: You are connected to database “postgres” as user “postgres” via socket in “/var/run/postgresql” at port “5432”.Let’s create a test database and user to see if it’s working.
postgres=# CREATE DATABASE mytestdb;CREATE DATABASEpostgres=# CREATE USER mytestuser WITH ENCRYPTED PASSWORD ‘MyStr0ngP@SS’;CREATE ROLEpostgres=# GRANT ALL PRIVILEGES ON DATABASE mytestdb to mytestuser;GRANT
Step 6: Connect to database:
postgres-# c mytestdbYou are now connected to database “mytestdb” as user “postgres”.
Step 7: Other PostgreSQL utilities installed such as createuser and createdb can be used to create database and users.
postgres@ubuntu:~$ createuser myuser –passwordPassword:postgres@ubuntu:~$ createdb mydb -O myuserpostgres@ubuntu:~$ psql -l
Step 8: We can create and connect to a database on PostgreSQL server.
Configure remote Connection
Ubuntu’s PostgreSQL 13 installation only allows connections from localhost. Ideally, distant clients would connect to a central database server in a production environment, but only over a private network (LAN).
Step 1: To enable remote connections, edit PostgreSQL configuration file:
sudo nano /etc/postgresql/13/main/postgresql.conf
Step 2: Uncomment line 59 and change the Listen address to accept connections within your networks.
# Listen on all interfaceslisten_addresses = ‘*’
# Listen on specified private IP addresslisten_addresses = ‘192.168.10.11’
Step 3: Also set PostgreSQL to accept remote connections from allowed hosts.
$ sudo nano /etc/postgresql/13/main/pg_hba.conf
# Accept from anywherehost all all 0.0.0.0/0 md5
# Accept from trusted subnethost all all 10.10.10.0/24 md5
Step 4: After the change, restart postgresql service.
sudo systemctl restart postgresql
Final Words
We hope you like our article on how to install PostgreSQL 13 on Ubuntu 22.04 LTS Linux. Information is stored and retrieved using PostgreSQL, an extremely potent object-relational database management system written in C and C++. A highly compliant and adaptable database, PostgreSQL can manage numerous processes concurrently. PostgreSQL 13 is a significant improvement. PostgreSQL has seen a lot of notable performance upgrades, substantial security updates, and outstanding feature additions that have made using, administering, and working with it even more impressive.