Install and Use PostgreSQL on CentOS8

PostgreSQL on CentOS8

Are you a Linux professional looking for a reliable and scalable database management system? Learn how to install and use PostgreSQL on CentOS 8 with this step-by-step guide and take your data management to the next level!

Table of Contents

Introduction

PostgreSQL is an open-source, object-relational database system that provides robust data management and secure data storage. It was first released in 1989 and has since then been developed by a global community of developers. PostgreSQL is known for its reliability, scalability, and flexibility and is widely used by organizations of all sizes, from small startups to large enterprises.

If you are a Linux professional who needs to set up PostgreSQL on CentOS 8, you’ve come to the right place. This article will provide you with a step-by-step guide on how to install and use PostgreSQL on CentOS 8.

Prerequisites or system requirements for install

Before we get started with the installation process, there are a few prerequisites that you need to have in place:

  1. A CentOS 8 server with a non-root user with sudo privileges.
  2. A stable internet connection to download the necessary packages.
  3. Basic knowledge of the Linux command line.

Step 1: Update the system

Before installing PostgreSQL, it is important to ensure that your system is up-to-date with the latest patches and security updates. You can do this by running the following command:

				
					$ sudo yum update -y
				
			

Step 2: Install PostgreSQL

To install PostgreSQL, run the following command:

				
					$ sudo yum install postgresql-server postgresql-contrib -y
				
			
PostgreSQL on CentOS8

Photo by admingeek from Infotechys

This command will install both the PostgreSQL server and some additional modules that provide additional functionality, such as data types and extensions.

Step 3: Initialize the PostgreSQL database

After installing PostgreSQL, you need to initialize the database. To do this, run the following command:

				
					$ sudo postgresql-setup initdb
				
			

This command will create the necessary directories and files for the PostgreSQL database.

Step 4: Start the PostgreSQL service

To start the PostgreSQL service, run the following command:

				
					$ sudo systemctl start postgresql
				
			

You can also enable PostgreSQL to start automatically at system boot by running the following command:

				
					$ sudo systemctl enable postgresql
				
			

Step 5: Connect to PostgreSQL

To connect to PostgreSQL, you need to use the psql command-line interface. You can do this by running the following command:

				
					$ sudo -u postgres psql
				
			

This will connect you to the PostgreSQL server as the postgres user.

Step 6: Create a user and database

To create a new user and database, you can use the following commands:

				
					CREATE USER myuser WITH PASSWORD 'mypassword'; 
CREATE DATABASE mydatabase; 
GRANT ALL PRIVILEGES ON DATABASE mydatabase TO myuser;
				
			

Replace myuser and mypassword with the desired username and password, and mydatabase with the desired database name.

Basic usage examples

Now that you have installed and configured PostgreSQL, you can start using it to manage your data. Here are a few basic usage examples:

Creating a table

To create a new table, use the following SQL command:

				
					CREATE TABLE mytable (
 id SERIAL PRIMARY KEY,
name VARCHAR(50), email VARCHAR(50)
);
				
			

This will create a new table called mytable with three columns: id, name, and email.

Inserting data

To insert data into the table, use the following SQL command:

				
					INSERT INTO mytable (name, email) VALUES ('John Doe', 'johndoe@example.com');
				
			

This will insert a new row into the mytable table with the name and email values specified.

Querying data

To query data from the table, use the following SQL command:

				
					SELECT * FROM mytable;
				
			

This will retrieve all the data from the mytable table.

Conclusion

PostgreSQL is a powerful and reliable database management system that is widely used by Linux professionals to store and manage data. By following the steps outlined in this article, you should be able to easily install and configure PostgreSQL on your CentOS 8 server.

Once installed, you can use PostgreSQL to create tables, insert data, and query data using SQL commands. These basic usage examples will help you get started with PostgreSQL, and you can explore more advanced features and functionality as needed.

Overall, PostgreSQL is a great choice for Linux professionals who need a robust and scalable database management system. With its open-source nature and active developer community, PostgreSQL is constantly evolving and improving, making it a reliable and secure option for organizations of all sizes.

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *