In this guide we are going to install Postgresql 14 in Rocky Linux 9.
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. Postgres, 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.
Check these also:
- How to Install and Configure Postgres 15 on Rocky/Alma Linux 9
- How to Install and Configure Postgres 14 on Alma Linux 9
- How to Install Postgres 14 on Rocky Linux 8/Centos 8
- How to Install & Configure Postgres 14 on FreeBSD 13
- Postgres Permissions - Create, Update, Delete Database Users
- Running Postgresql 14 with Docker and Docker-Compose
- How to Install and Configure Postgres 14 on Debian 11
- How to Install and Configure Postgres 14 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:
- Rocky Linux 9 server
- Root access to the server or user with root access
- Internet access from the server
- Basic knowledge of Linux terminal
Ensure the server is up to date
Before proceeding, let us ensure that our server has up to date packages. Use this command to update the packages:
|
|
Installing and starting Postgres Server
The default repositories for Rocky Linux 9 has an older version of PostgresQL.
We will use the repo provided by the postgres team to set up repositories for postgres 14 then install the package.
Let us Install the repository RPM using this command:
|
|
Finally install PostgreSQL 14 server:
|
|
Let’s also install the Contrib package which provides several additional features for the PostgreSQL database system:
|
|
Once the installation is complete, initialize the PostgreSQL database with the following command:
|
|
Start the postgres service with this command:
|
|
Then enable the service so it starts when the server reboots.
|
|
Confirm that Postgres is running:
|
|
The Active: active (running)
shows that the service is up and running.
Next, let us verify that the installation was successful by connecting to the PostgreSQL database server and printing its version:
|
|
Output:
|
|
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 ident authentication
, 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 in thepg_hba.conf
are met.Password
- A role can connect by providing a password. The passwords can be stored asscram-sha-256
,md5
, andpassword
(clear-text
).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.
Connecting to postgres database
By Switching to postres
user
Switch over to the postgres account on your server by typing this in the terminal;:
|
|
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 postgres
user
Use this to run the command directly as the postgres
user using sudo
|
|
Output:
|
|
Ensure that you run the above command as a user that has sudo privileges.
Configuring postgres 14 instance for remote access
To achieve this, we will modify postgres configuration files. We need to open the files and adjust the configs are required. The main configuration file for Postgresql 14 can be found in this path /var/lib/pgsql/14/data/pg_hba.conf
Let’s change peer identification to trust:
|
|
Change ident identification to md5 to allow password login.
|
|
Add a block to allow access from everywhere:
Add this content to the file /var/lib/pgsql/14/data/pg_hba.conf
|
|
Ensure PostgreSQL is listening on *
Add this line to the config here /var/lib/pgsql/14/data/postgresql.conf
|
|
Enable and restart postgresql server to reload the configurations:
|
|
User management
Creating Superuser
Now that everything is set up, let us create a super user. Connect to the DB as postres role:
|
|
Create super user with name root
:
|
|
Output:
|
|
Managing Application Users
Use this to create a database, create a user and grant that user all accesss to that database:
|
|
Checkout this comprehensive guide on user and permission management in postgres here.
Connecting to the instance from remote host
Use this command to connect to the postgres instance from local machine:
|
|
Conclusion
Up to this point we have managed to install Postgresql 14 on an Rocky Linux 9 server, do some basic configurations then do basic user management.