When working with WHM/cPanel backups, PostgreSQL databases are typically compressed into .tar archives containing both schema and data. Unlike plain SQL dumps, these archives preserve database objects in PostgreSQL's custom format, which requires specific restoration procedures.
# Verify PostgreSQL service status
sudo systemctl status postgresql
# Check disk space availability
df -h /var/lib/postgresql
# Confirm file permissions
ls -l /backup/cpbackup/daily/client03/psql/client03.tar
The correct pg_restore command needs proper file path specification and database connection parameters:
# Basic restoration (interactive password prompt)
pg_restore --verbose --clean --create --dbname=postgres \
/backup/cpbackup/daily/client03/psql/client03.tar
# Alternative with explicit connection parameters
PGPASSWORD="yourpassword" pg_restore -h localhost -p 5432 -U postgres \
-d client03 /backup/cpbackup/daily/client03/psql/client03.tar
The "Permission denied" error typically occurs due to:
# 1. PostgreSQL user lacking read access
sudo chmod 640 /backup/cpbackup/daily/client03/psql/client03.tar
sudo chown postgres:postgres /backup/cpbackup/daily/client03/psql/client03.tar
# 2. SELinux context issues (on CentOS/RHEL)
sudo restorecon -Rv /backup/cpbackup/daily/client03/psql/
For complex cases, consider these additional parameters:
# Partial restoration of specific tables
pg_restore -t users -t orders -d client03 client03.tar
# Parallel restoration for large databases
pg_restore -j 4 -d client03 client03.tar
# Generate SQL script instead of direct restore
pg_restore -f restore_script.sql client03.tar
# Connect to PostgreSQL and verify
psql -U postgres -d client03 -c "\dt"
psql -U postgres -d client03 -c "SELECT count(*) FROM pg_tables"
- Check PostgreSQL logs:
sudo tail -n 50 /var/log/postgresql/postgresql-*.log
- Test with smaller backup files first
- Consider using
--no-owner
flag if encountering role permission errors
When WHM performs PostgreSQL backups during incremental backups, it typically creates compressed .tar
files containing database dumps. These archives follow a specific structure that pg_restore can process, but proper permissions and paths are crucial.
The "Permission denied" error typically occurs when:
- The PostgreSQL user lacks read access to the backup file
- The file is in a restricted directory
- SELinux policies are blocking access (common on CentOS/RHEL)
Here's the complete workflow I've used successfully:
# 1. Verify backup file exists and permissions
ls -l /backup/cpbackup/daily/client03/psql/client03.tar
# 2. Set proper ownership (adjust postgres user if different)
sudo chown postgres:postgres /backup/cpbackup/daily/client03/psql/client03.tar
# 3. Restore with proper connection parameters
sudo -u postgres pg_restore \
-d client03 \
-v \
-j 4 \
--format=t \
/backup/cpbackup/daily/client03/psql/client03.tar
For complex cases, additional flags can help:
# Restore specific tables only
pg_restore -t customers -t orders -d client03 backup.tar
# Create database if not existing
pg_restore -C -d postgres backup.tar
# Restore with parallel jobs for large databases
pg_restore -j 8 -d client03 backup.tar
If SELinux is enabled, you may need to adjust contexts:
# Check current context
ls -Z /backup/cpbackup/daily/client03/psql/client03.tar
# Set proper context
sudo chcon -R -t postgresql_db_t /backup/cpbackup/daily/client03/psql/
Always verify after restoration:
psql -d client03 -c "SELECT count(*) FROM pg_tables;"
psql -d client03 -c "\dt+"