Postgresql is an open source object-relational database system with over 30 years of active development that has earned it a strong reputation for reliability, feature robustness, and performance. It is a free and open-source relational database management system emphasizing extensibility and SQL compliance. It was originally named POSTGRES, referring to its origins as a successor to the Ingres database developed at the University of California, Berkeley.
PostgreSQL is used as the primary data store or data warehouse for many web, mobile, geospatial, and analytics applications. PostgreSQL can store structured and unstructured data in a single product.
In this guide we are going to install Postgresql 14 in Ubuntu 20.04.
Updated July 2026. These steps still work for PostgreSQL 14, but a couple of things have changed since this was first written: Ubuntu 20.04 LTS reached the end of its standard support on 31 May 2025 (security updates now require Ubuntu Pro / ESM), and PostgreSQL 14 reaches end of life on 12 November 2026. If you are starting fresh, install on a current LTS such as Ubuntu 24.04 and consider a newer PostgreSQL release (18 is the latest). The repository setup below has been updated to use a signed keyring in place of the now-removed
apt-key.
Related content:
- How to Install and Configure Postgres 14 Ubuntu 22.04
- How to Install & Configure Postgres 14 on FreeBSD 13
- Postgres Permissions - Create, Update, Delete Database Users
- How to Install and Configure Postgres 14 on Debian 11
- How to Install and Configure Postgres 14 on Centos 8
- How to Install and Configure Postgres 13 on Centos 8
- Running Postgresql 14 with Docker and Docker-Compose
- How to Install and Configure Postgres 13 Ubuntu 20.04
- How to Install and Configure Postgres 14 on Fedora 34
- How to Install & Configure Postgres 14 on OpenSUSE Leap 15.3
Prerequisites
To follow along, ensure you have the following:
- Ubuntu 20.04 server
- Root access to the server or user with root access
- Internet access from the server
- Knowledge of Linux terminal
Table of content
- Ensure that your system packages are up to date
- Installing Postgres 14
- PostgreSQL Roles and Databases Authentication Methods
- Connecting to Postgres Database
- Configuring postgres instance for remote access
- User management
- Connecting to the instance from remote host
1. Ensure that your system packages are up to date
Let’s refresh your server’s local package index using this command:
| |
Then we upgrade the packages in our system with this:
| |
2. Installing Postgres 14
Postgres is provided in the default Ubuntu repositories. To check the version provided, use this command:
| |
The default packages provided by the default repositories are Postgres 12. If you only need Postgres 12, you can install it with the following command. The -contrib package adds some additional utilities and functionality:
| |
Since we are looking to install Postgres 14, we will need to add the PostgreSQL PGDG repository that provides the packages.
First install the tools used to fetch the key, then download the PGDG repository signing key into a dedicated keyring:
| |
Then add the PGDG repository, referencing that keyring with signed-by:
| |
Older guides import this key with
wget ... | sudo apt-key add -.apt-keyis deprecated and has been removed from recent APT releases, so use thesigned-bykeyring shown above instead. If you prefer, PostgreSQL now ships an automated setup that does all of the above for you:
1 2sudo apt install -y postgresql-common sudo /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh
Now let’s update the package lists:
| |
Then we install the specific version of postgres we want. Use postgresql-14 instead of postgresql:
| |
Once the installation is successful, Postgres 14 will be started.
Use this command to check the service status:
| |
Output:
| |
Next, let’s verify the installation by connecting to the PostgreSQL database server and checking its version. Use this command:
| |
Output:
| |
The exact string will vary with the point release you get — as of this update the latest PostgreSQL 14 release is 14.23.
3. PostgreSQL Roles and Databases Authentication Methods
PostgreSQL uses a concept called roles to handle client authentication and authorization. By default, Postgres is set up to use peer authentication for local connections, meaning that it associates Postgres roles with a matching Unix/Linux system account. If a role exists within Postgres, a Unix/Linux username with the same name is able to sign in as that role.
The installation procedure created a user account called postgres that is associated with the default postgres role. In order to use PostgreSQL, you can log in to that account.
PostgreSQL supports multiple authentication methods. The most commonly-used methods are:
Trust– A role can connect without a password, as long as the conditions defined inpg_hba.confare met.Password– A role can connect by providing a password. The passwords can be stored asscram-sha-256,md5, andpassword(clear-text). Since PostgreSQL 14 the default isscram-sha-256.Ident– Only supported on TCP/IP connections. It works by obtaining the client’s operating system user name, with an optional user name mapping.Peer– Same as Ident, but it is supported on local connections only.
4. Connecting to Postgres Database
- By switching to the
postgresuser
Switch over to the postgres account on your server by typing:
| |
You can now access a Postgres prompt immediately by typing:
| |
This will log you into the PostgreSQL prompt, and from here you are free to interact with the database management system right away.
- By running the command as the postgres user
Use this to run the command directly as the postgres user using sudo:
| |
5. Configuring postgres instance for remote access
By default postgres is only set up to be accessed locally. This is not ideal if we want to access our server from another host. In this section we are going to configure postgres to allow access from remote hosts.
Postgres 14’s configuration files live under /etc/postgresql/14/main/. The client authentication file is /etc/postgresql/14/main/pg_hba.conf:
| |
Change peer identification to trust
Use this command to change peer to trust:
| |
This will update the line in the config file to this:
| |
trustlets any local user connect as any role without a password. That is convenient on a throwaway lab box, but unsafe on shared or production systems — keeppeer(or usescram-sha-256) there.
Add a block to allow access from everywhere
Add this content to the file /etc/postgresql/14/main/pg_hba.conf to allow all hosts password access:
| |
Then add this:
| |
Older guides use
md5here. Since PostgreSQL 14 the default password hashing is the strongerscram-sha-256, so prefer it unless you must support very old clients. Note that0.0.0.0/0exposes Postgres to every host on the network — restrict this to the specific IPs or subnets that need access and keep the server behind a firewall.
Ensure PostgreSQL is listening on *
Add this line to the config here /etc/postgresql/14/main/postgresql.conf to allow postgres to listen on all hosts:
| |
To apply the configurations, we need to restart the postgres 14 service.
Enable and restart the postgresql server to reload the configs:
| |
6. User management
Create Super user
It would be better if we created a superuser to administer the postgres service. This is that one user that has permissions to manage other users and databases.
Connect to the DB as the postgres role:
| |
Create a superuser with the name root using this command:
| |
Check the user if it has been created and granted the necessary privileges:
| |
Managing application users
Use this to create a database, create a user and grant that user all access to that database:
| |
On PostgreSQL 15 and newer the
publicschema is locked down by default, so the new user may also needGRANT ALL ON SCHEMA public TO app_user;before it can create objects. On PostgreSQL 14 the grant above is enough.
Checkout this comprehensive guide on user and permission management in postgres here.
7. Connecting to the instance from remote host
Use this command to test that you can connect:
| |
Conclusion
Up to this point we have managed to install Postgresql 14 on an Ubuntu server, do some basic configurations then do basic user management.