Get a Pentest and security assessment of your IT network.

Cyber Security

Backtrack 5 Postgres Database Fix

TL;DR

Your Backtrack 5 R2-64 bit PostgreSQL database isn’t starting? This guide walks you through common causes and fixes, focusing on permissions, configuration files, and service management.

Fixing a Non-Loading Postgres Database in Backtrack 5

  1. Check the Service Status
    • First, see if the PostgreSQL service is even running. Open a terminal and type:
      sudo /etc/init.d/postgresql status
    • If it’s not running (shows ‘stopped’), try to start it:
      sudo /etc/init.d/postgresql start
    • Look for any error messages during the startup attempt. These are crucial clues!
  2. Examine Log Files
    • PostgreSQL logs errors to a specific file. The location varies, but common places include:
      • /var/log/postgresql
      • /var/log/postgres
      • Check the postgresql.conf file (see step 3) for the exact log path.
    • Use a text editor or command like tail -f /path/to/logfile to view the latest entries in real-time as you attempt to start the service.
      sudo tail -f /var/log/postgresql/postgresql.log
  3. Verify Configuration File Permissions
    • The postgresql.conf file needs to be readable by the PostgreSQL user (usually ‘postgres’). Check its permissions:
      ls -l /etc/postgresql/9.1/main/postgresql.conf

      (Replace ‘9.1’ with your Postgres version if different.)

    • If the permissions are incorrect (e.g., owned by root and not readable by postgres), change them:
      sudo chown postgres:postgres /etc/postgresql/9.1/main/postgresql.conf
      sudo chmod 640 /etc/postgresql/9.1/main/postgresql.conf
  4. Check Data Directory Permissions
    • The PostgreSQL data directory also needs the correct permissions. Find its location in postgresql.conf (look for the ‘data_directory’ setting).
      grep data_directory /etc/postgresql/9.1/main/postgresql.conf
    • Once you know the path, verify permissions:
      ls -l /var/lib/postgresql/9.1/main

      (Replace ‘9.1’ with your version and adjust the path as needed.)

    • Ensure the ‘postgres’ user owns the directory and has read/write access:
      sudo chown -R postgres:postgres /var/lib/postgresql/9.1/main
      sudo chmod -R 700 /var/lib/postgresql/9.1/main
  5. Ensure the Data Directory Exists
    • If the data directory specified in postgresql.conf doesn’t exist, PostgreSQL won’t start.
      ls -l /var/lib/postgresql/9.1/main
    • Create it if necessary:
      sudo mkdir -p /var/lib/postgresql/9.1/main

      (Replace ‘9.1’ with your version and adjust the path as needed.)

  6. Restart PostgreSQL
    • After making any changes to permissions or configuration, restart the service:
      sudo /etc/init.d/postgresql restart
    • Check the status again to confirm it’s running.
      sudo /etc/init.d/postgresql status
  7. Database Cluster Initialization (If Data Directory Was Empty)
    • If you had to create the data directory, you need to initialize a new database cluster:
      sudo -u postgres initdb -D /var/lib/postgresql/9.1/main

      (Replace ‘9.1’ with your version and adjust the path as needed.)

Related posts
Cyber Security

Zip Codes & PII: Are They Personal Data?

Cyber Security

Zero-Day Vulnerabilities: User Defence Guide

Cyber Security

Zero Knowledge Voting with Trusted Server

Cyber Security

ZeroNet: 51% Attack Risks & Mitigation