Welcome to CentOS Tutorial. In this article, we are going to install the PostgreSQL 10 on CentOS 8. PostgreSQL is a popular RDBMS available for free. Installing PostgreSQL is not difficult. With a few commands, we can get PostgreSQL Server up and running within minutes. There are personal reasons why I prefer PostgreSQL rather than other RDBMS server such as MySQL or MariaDB.
Steps to Install PostgreSQL 10 on CentOS 8
First, let’s check the availability of the PostgreSQL package in CentOS repository. Please execute these commands below as root user.
dnf module list postgresql
Output
As you can see there are two PostgreSQL versions available from the repository. In this case, we are going to install version 10. To do this, use this command
dnf install @postgresql:10
Output
Or basically, because PostgreSQL 10 is the default package, you can just use this command to install
dnf install postgresql
Additionally, you may also need to install the following package
dnf install postgresql-contrib
Once the installation completes, continue with this command to initialize the database.
postgresql-setup initdb
Now start the service and enable during startup
systemctl start postgresql
systemctl enable postgresql
Make sure you see the service is active
Change the postgres password
By default, postgres user does not have password. We can change the password with this command
Login as postgres user and then execute psql command:
su - postgres
psql
ALTER USER postgres WITH PASSWORD '12345';
Enable Remote Connection to PostgreSQL Server
In order to enable remote connection to the server, we need to edit the following files:
- postgresql.con
- pg_hba.conf
su
nano nano /var/lib/pgsql/data/postgresql.conf
Edit the value of listen_addresses = ‘localhost‘ to ‘*’ as follow:
- Connection Settings - listen_addresses = '*' # what IP address(es) to listen on;
Next, edit the pg_hba.conf
su
nano /var/lib/pgsql/data/pg_hba.conf
add the following line to the end of the file
host all all 0.0.0.0/0 md5
Restart PostgreSQL service
su
systemctl restart postgresql
Done. Now try to connect to the server from other computer. In this case, I use Navicat Premium to connect to the server from a Windows 10 PC.
Thank you for reading this article, I hope you enjoy it. Cheers.
Leave a Reply