Tuesday, November 12, 2024

How to Fix & Troubleshooting PostgreSQL 9.5 Startup Issues on CentOS 7

Setting up PostgreSQL on CentOS can sometimes lead to unexpected errors, especially when working with older versions like PostgreSQL 9.5. If you’re encountering issues where PostgreSQL fails to start, this guide will walk you through diagnosing and potentially resolving the problem.

Issue Summary

While following the PostgreSQL installation guide from the official PostgreSQL Wiki, you might encounter an error that prevents PostgreSQL from starting. Running systemctl start postgresql-9.5.service may produce the following output:


Job for postgresql-9.5.service failed because the control process exited with error code. See "systemctl status postgresql-9.5.service" and "journalctl -xe" for details.

Upon checking the status with systemctl status postgresql-9.5.service, you may see an error message indicating that the service failed due to a configuration issue or missing dependencies.

Step-by-Step Solution

Here are some steps to troubleshoot and potentially resolve this problem.

1. Confirm Repository and Package Installation

First, ensure that your CentOS system has the correct repositories and that all PostgreSQL-related packages are properly installed. Follow these steps to check and install PostgreSQL:

  1. Edit the Repository: Open the CentOS repository file to make sure it’s configured correctly:


    vi /etc/yum.repos.d/CentOS-Base.repo
  2. Add PostgreSQL Repository: Add the PostgreSQL 9.5 repository to ensure that CentOS can locate the required packages:


    yum localinstall http://yum.postgresql.org/9.5/redhat/rhel-7-x86_64/pgdg-centos95-9.5-2.noarch.rpm
  3. Verify Available Packages:


    yum list postgres*
  4. Install Required Packages:


    yum install -y postgresql95-server.x86_64 postgresql95-contrib.x86_64 postgresql95-libs.x86_64

2. Initialize the Database

After ensuring the packages are installed, initialize the PostgreSQL database:


/usr/pgsql-9.5/bin/postgresql95-setup initdb

3. Check SELinux Configuration

Sometimes SELinux policies can prevent PostgreSQL from starting. Although you tried setting setenforce 0 to disable SELinux temporarily, you may want to ensure that SELinux is not interfering permanently by editing the configuration:

  1. Open the SELinux configuration file:


    vi /etc/selinux/config
  2. Set SELINUX to permissive or disabled (if security requirements allow):


    SELINUX=permissive
  3. Reboot the system if you made changes to this file.

4. Enable and Start PostgreSQL Service

After configuration, enable and start the PostgreSQL service:


systemctl enable postgresql-9.5.service systemctl start postgresql-9.5.service

5. Verify the Service Status

After starting the service, check its status to confirm it’s running correctly:


systemctl status postgresql-9.5.service

If everything is working correctly, you should see output similar to the following:


postgresql-9.5.service - PostgreSQL 9.5 database server Loaded: loaded (/usr/lib/systemd/system/postgresql-9.5.service; enabled) Active: active (running) since [timestamp]

Additional Troubleshooting Tips

If PostgreSQL still fails to start, consider these additional checks:

  • Check PostgreSQL Logs: Look at the PostgreSQL log files for more details on what might be causing the failure. Logs are often located in /var/lib/pgsql/9.5/data/pg_log/.

  • Permissions: Ensure that PostgreSQL directories and files have the correct permissions. Specifically, check that /var/run/postgresql has the correct owner and permissions as specified in your configuration files:

    chown -R postgres:postgres /var/run/postgresql chmod 0755 /var/run/postgresql
  • Dependencies and Library Paths: Verify that the required libraries are accessible. Double-check the content of postgresql-pgdg-libs.conf and other configuration files for paths and permissions.

Conclusion

Following these steps should help you troubleshoot and resolve issues with starting PostgreSQL 9.5 on CentOS 7. Ensure all configurations are set as expected, required libraries are accessible, and SELinux policies are configured correctly.

0 comments:

Post a Comment