PostgreSQL is a highly regarded open-source object-relational database system known for its reliability, robust features, and exceptional performance. With over 30 years of active development, PostgreSQL has become a popular choice among businesses and developers. In this guide, we will walk you through the step-by-step process of installing PostgreSQL on AlmaLinux 9, ensuring that you can leverage the power of this powerful database management system.
1. Updating the System
Before we begin the installation process, it is essential to update the system to the latest version. By running the following commands, you can ensure that your AlmaLinux 9 system is up to date:
dnf update
2. Installing the PostgreSQL Repository
To install PostgreSQL on AlmaLinux 9, we need to add the official PostgreSQL repository. Execute the following command to add the repository:
dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-9-x86_64/pgdg-redhat-repo-latest.noarch.rpm
3. Installing the PostgreSQL Server
Once the repository is added, we can proceed with installing the PostgreSQL server. At the time of writing this article, version 14.4 is the latest available version. To install this version, use the following command:
dnf install -y postgresql14-server
4. Creating a New PostgreSQL Database Cluster
After installing the PostgreSQL server, we need to initialize a database storage area on disk. Execute the following command to accomplish this:
/usr/pgsql-14/bin/postgresql-14-setup initdb
5. Starting and Enabling the PostgreSQL Service
To start the PostgreSQL service, use the following command:
systemctl start postgresql-14
To enable the PostgreSQL service to start automatically at boot, execute the following command:
systemctl enable postgresql-14
To verify the status of the PostgreSQL service, run the following command:
systemctl status postgresql-14
6. Managing PostgreSQL Roles
PostgreSQL uses roles to manage database access and permissions. By default, PostgreSQL creates a superuser role named “postgres.” Switch to the “postgres” account using the following command:
sudo -i -u postgres
To access the PostgreSQL prompt, use the “psql” utility:
psql
To exit the PostgreSQL shell, type q
.
To switch back to the root user account, simply type:
exit
7. Creating a PostgreSQL Database
To create a new PostgreSQL database, use the createdb
command followed by the desired database name. For example, to create a database named “my_db,” execute the following command:
createdb my_db
8. Opening a Postgres Prompt with the New Role
To manage PostgreSQL roles efficiently, we can create a new user and grant appropriate permissions. First, switch back to the root user account by exiting the current user mode:
exit
Next, run the adduser
command to add the new user to the system. For example, to add a user named “Adam,” execute the following command:
adduser Adam
To switch to the newly added user and enter the PostgreSQL database, use the following command:
sudo -i -u Adam psql -d my_db
Once you are logged in as the “Adam” user and connected to the “my_db” database, you can check your current connection information by typing conninfo
.
9. Conclusion
Congratulations! You have successfully installed PostgreSQL on AlmaLinux 9. By following the steps outlined in this guide, you can now leverage the power of PostgreSQL’s reliability and robust features for your database management needs.
10. Additional Information
For more information or assistance with PostgreSQL installation and management, consider utilizing Shape.host’s Linux SSD VPS services. Shape.host offers reliable and scalable cloud hosting solutions, empowering businesses with efficient and secure environments for their database management needs.