In this blog post, we are going to show you how to install PostgreSQL on Ubuntu 22.04 OS.
PostgreSQL is a very powerful object-relational database management system written in C and C++ and used for storing and retrieving information. PostgreSQL is a highly compliant and extensible database that can handle multiple tasks at the same time. Learn about the differences between PostgreSQL, MySQL, and SQLite.
Installing PostgreSQL on Ubuntu 22.04 is a very easy task and can take up to 10 minutes. Let’s get started!
Table of Contents
Prerequisites
- A server with Ubuntu 22.04 as OS
- User privileges: root or non-root user with sudo privileges
Step 1. Update the System
We need to update the system packages to the latest versions available.
Step 2. Install PostgreSQL
The latest PostgreSQL version 14 is available in the default repository of Ubuntu 22.04, so we just need to execute the command below:
Once, installed start and enable the PostgreSQL service.
Check if the service is up and running:
You should receive the following output:
Another way to check about the PostgreSQL service and port is to run the command below:
You should receive the following output:
To check the installed PostgreSQL version, execute the following command:
You should receive the following output:
Step 3. Configure PostgreSQL
The configuration changes of PostgreSQL 14, are locate at /etc/postgresql/14/main/postgresql.conf on your server. In this file, you can configure incoming connections, security and authentication, resource usage, etc.
In the next few paragraphs, we are going to show you some of the basic PostgreSQL commands and configurations.
Accessing the PostgreSQL console
To access the PostgreSQL console execute the following command on your server:
You should receive the following output:
List Databases
To list the databases, execute the \l command:
You should receive the following output:
Select Database
To select a database, execute the \c “database name” command:
You should receive the following output:
Quit PostgreSQL shell
To quit from the PostgreSQL shell, just type “\q.”
Allow Remote Access
To allow remote access so PostgreSQL can be accessed from everywhere, you need to open the /etc/postgresql/14/main/pg_hba.conf file and configure the following lines of code to look like those described below:
Save the file, close it, and restart the PostgreSQL service for the changes to take effect.
Increase Memory Usage
To increase the memory usage of PostgreSQL open the /etc/postgresql/14/main/postgresql.conf file and configure the following lines of code to look like those described below:
The default value of shared_buffers is 128MB. Save the file, close it and restart the PostgreSQL service for the changes to take effect.
Congratulations! You successfully installed and configured the latest PostgreSQL 14 version on Ubuntu 22.04.
Of course, you don’t have to install PostgreSQL on Ubuntu 22.04 if you use one of our PostgreSQL VPS Hosting plans, in which case you can simply ask our expert Linux admins to install PostgreSQL 14 on Ubuntu 22.04 for you. They are available 24×7 and will take care of your request immediately.
If you liked this post on how to install PostgreSQL on Ubuntu 22.04, please share it with your friends on social networks or simply leave a reply below.