PostgreSQL is a powerful and reliable open-source object-relational database system that has been developed for over 30 years. With its robust features and excellent performance, PostgreSQL has earned a strong reputation in the industry. In this guide, we will walk you through the process of installing PostgreSQL on AlmaLinux 8, a popular Linux distribution.
1. Introduction to PostgreSQL
PostgreSQL is an advanced open-source database system that offers a wide range of features and capabilities. It is known for its reliability, data integrity, and performance, making it a popular choice for both small and large-scale applications. PostgreSQL supports various data types, including structured, semi-structured, and unstructured data, providing flexibility in data management.
2. Checking PostgreSQL Modules
Before proceeding with the installation, let’s check the available PostgreSQL modules in AlmaLinux 8. To list the PostgreSQL modules, open the terminal and run the following command:
dnf module list postgresql
The command will display a list of available PostgreSQL modules along with their versions and profiles.
3. Enabling the PostgreSQL Module
To enable a specific version of the PostgreSQL module, use the following command:
dnf module enable postgresql:<version>
Replace <version>
with the desired version number. For example, to enable version 12 of the PostgreSQL module, run the following command:
dnf module enable postgresql:12
4. Installing the PostgreSQL Server
After enabling the PostgreSQL module, you can proceed with the installation of the PostgreSQL server. Use the following command to install the server:
dnf install postgresql-server
This command will install the PostgreSQL server along with its dependencies.
5. Initializing a New PostgreSQL Database Cluster
Once the installation is complete, you need to initialize a database storage area on the disk. Use the following command to initialize the PostgreSQL database cluster:
postgresql-setup --initdb
This command will initialize the database in the specified storage area and create necessary configuration files.
6. Starting and Enabling the PostgreSQL Service
To start the PostgreSQL service, use the following command:
systemctl start postgresql
After starting the service, you can enable it to start automatically on system boot:
systemctl enable postgresql
7. Creating PostgreSQL Roles
To create a new role in PostgreSQL, switch to the postgres
account using the following command:
sudo -i -u postgres
Once you are in the postgres
account, you can access the PostgreSQL prompt using the psql
utility:
psql
You will now be able to interact with the PostgreSQL prompt, indicated by the postgres=#
prompt.
8. 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 mydb
, use the following command:
createdb mydb
This command will create a new database with the specified name.
9. Opening a PostgreSQL Prompt with a New Role
If you want to connect to the PostgreSQL database with a newly created role, you need to add the user to the system and then switch to that user. Use the following commands to add the user and switch to it:
sudo adduser <username> sudo -i -u <username>
Replace <username>
with the desired username. For example, to create a user named jones
, use the following commands:
sudo adduser jones sudo -i -u jones
Once you have switched to the new user, you can access the PostgreSQL prompt using the psql
command:
psql
Now you are connected to the PostgreSQL database with the new role, indicated by the username=#
prompt.
10. Additional Information: Shape.host Services
At Shape.host, we provide reliable and scalable Linux SSD VPS hosting solutions. Our services are designed to meet the needs of businesses looking for efficient and secure cloud hosting options. With our cutting-edge technology and expert support, we ensure that your PostgreSQL installations run smoothly and efficiently.
11. Conclusion
Installing PostgreSQL on AlmaLinux 8 is a straightforward process that involves enabling the PostgreSQL module, installing the server, initializing the database cluster, and creating roles and databases. By following the steps outlined in this guide, you can set up a PostgreSQL environment and start leveraging its powerful features for your applications. Remember to choose a reliable hosting provider like Shape.host to ensure optimal performance and security for your PostgreSQL installations.
Now that you have learned how to install PostgreSQL on AlmaLinux 8, you can confidently leverage its capabilities for your database management needs. Start exploring the power of PostgreSQL and unlock new possibilities for your applications.