html
When attempting to start a PostgreSQL 9.3 instance on Ubuntu 12.04 using:
service postgresql start
The system returns:
* The PostgreSQL server failed to start. Please check the log output. [fail]
Yet the expected log file remains empty:
tail /var/log/postgresql/postgresql-9.3-main.log
When PostgreSQL fails to create logs, we need to verify fundamental service configurations:
# Check if PostgreSQL is actually attempting to write logs
psql -U postgres -c "SHOW log_directory;"
psql -U postgres -c "SHOW logging_collector;"
PostgreSQL may be logging elsewhere due to permission issues:
# System-level logs
grep postgres /var/log/syslog
# Kernel messages
dmesg | grep -i postgres
Bypass init scripts to get raw error output:
sudo -u postgres /usr/lib/postgresql/9.3/bin/postgres -D /var/lib/postgresql/9.3/main \
-c config_file=/etc/postgresql/9.3/main/postgresql.conf
- Incorrect permissions on /var/log/postgresql/
sudo chown postgres:postgres /var/log/postgresql/ sudo chmod 750 /var/log/postgresql/
- Missing log directory in postgresql.conf
logging_collector = on log_directory = '/var/log/postgresql'
# Verify data directory permissions
namei -l /var/lib/postgresql/9.3/main
# Check for port conflicts
netstat -tulnp | grep 5432
# Validate config file syntax
sudo -u postgres /usr/lib/postgresql/9.3/bin/postgres \
--config-file=/etc/postgresql/9.3/main/postgresql.conf --check
Enable debug-level logging temporarily:
sudo -u postgres psql -c "ALTER SYSTEM SET log_min_messages TO 'debug5';"
sudo service postgresql restart
Then immediately check both standard output and system logs for any error messages.
When attempting to start PostgreSQL 9.3 on Ubuntu 12.04 with service postgresql start
, the service fails silently without generating any log output in /var/log/postgresql/postgresql-9.3-main.log
. This creates a particularly frustrating debugging scenario where we have zero visibility into the failure cause.
Before diving deep, let's perform basic sanity checks:
# Check if PostgreSQL is already running
ps aux | grep postgres
# Verify data directory permissions (default location)
ls -ld /var/lib/postgresql/9.3/main
# Check available disk space
df -h /var/lib/postgresql
When standard logging fails, we need to manually force logging through these approaches:
# Method 1: Start postgres manually with logging to stderr
sudo -u postgres /usr/lib/postgresql/9.3/bin/postgres -D /var/lib/postgresql/9.3/main -c config_file=/etc/postgresql/9.3/main/postgresql.conf
# Method 2: Enable debug logging temporarily
echo "log_min_messages = debug5" | sudo tee -a /etc/postgresql/9.3/main/postgresql.conf
service postgresql restart
Permission Issues
The most frequent cause of silent failures:
# Repair ownership recursively
sudo chown -R postgres:postgres /var/lib/postgresql/9.3/main
sudo chmod -R 0700 /var/lib/postgresql/9.3/main
Port Conflicts
# Check for port 5432 usage
sudo netstat -tulnp | grep 5432
# Alternative port test
sudo -u postgres psql -p 5433 -c "SELECT version();"
Corrupted Configuration
Validate config files:
# Check config syntax
sudo -u postgres /usr/lib/postgresql/9.3/bin/postgres -D /var/lib/postgresql/9.3/main -C config_file=/etc/postgresql/9.3/main/postgresql.conf --check-config
Strace for System Calls
# Trace the startup process
sudo strace -f -o /tmp/postgres_strace.log sudo -u postgres /usr/lib/postgresql/9.3/bin/postgres -D /var/lib/postgresql/9.3/main
Checking System Journal
Modern systems might log to journald:
journalctl -u postgresql | tail -20
When all else fails, consider these nuclear options:
# Reinitialize the cluster
sudo pg_dropcluster 9.3 main --stop
sudo pg_createcluster 9.3 main --start
# Verify with
sudo pg_lsclusters