Step One: Update Yum Repository
Before installing PostgreSQL, it's good practice to update the Yum repository to ensure you are fetching the latest packages. Open the terminal and execute:
This command fetches the latest information about available packages.
sudo yum update
Step Two: Install PostgreSQL
Now, use the following command to install PostgreSQL:
This will install the PostgreSQL server and additional contributed modules.
sudo yum install postgresql-server postgresql-contrib
Step Three: Initialize the Database
After installation, initialize the PostgreSQL database and enable automatic start on system boot:
sudo postgresql-setup initdb sudo systemctl enable postgresql
Step Four: Start PostgreSQL Service
Start the PostgreSQL service using the following command:
sudo systemctl start postgresql
Verify that the service is running without errors:
sudo systemctl status postgresql
Step Five: Access PostgreSQL Shell
Access the PostgreSQL shell using the psql command:
Now, you are in the PostgreSQL interactive shell, and you can start creating databases, users, and performing other administrative tasks.
sudo -u postgres psql
Additional Tips
Secure Your PostgreSQL Installation
Edit the PostgreSQL configuration file to enhance security:
Adjust access controls according to your security requirements.
sudo nano /var/lib/pgsql/data/pg_hba.conf
Firewall Configuration
If your firewall is enabled, allow PostgreSQL traffic:
sudo firewall-cmd --add-service=postgresql --permanent sudo firewall-cmd --reload
Conclusion for PostgreSQL on CentOS 7
Congratulations! You've successfully installed PostgreSQL on CentOS 7 using Yum. This provides you with a robust and efficient relational database system, ready for your applications. Remember to tailor security settings based on your specific requirements. This guide ensures a smooth installation process, making PostgreSQL on CentOS 7 easily accessible for your database needs.