PostgreSQL Backup Verification on openSUSE Leap

Why PostgreSQL backup verification matters before you need it
PostgreSQL backup verification is the difference between having a file and having a restore plan. On a production server, you need to know the backup runs, the archive is readable, the data directory restores cleanly, and the service comes back after a failure.
This tutorial uses openSUSE Leap, which fits disciplined server work well because it ships with systemd, firewalld, AppArmor, and stable package versions. If you run your database on a Hostperl VPS, a dedicated server, or a self-managed bare metal machine, this procedure gives you a practical way to confirm your backups before an outage forces the test for you. If you're choosing storage and recovery capacity for a database-heavy workload, you can pair this workflow with Hostperl VPS for smaller deployments or dedicated server hosting when you need larger disks and more memory headroom.
We will set up PostgreSQL, create a backup job, validate the backup with a restore test, and then check rollback steps. The goal is a repeatable operating routine, not a one-time command run.
What you will build
You will create a small PostgreSQL 16 instance on openSUSE Leap, protect the backup directory, and verify the backup with a separate restore. The same pattern works for production databases, but you should always test on a non-production restore target first.
- OpenSUSE Leap host with systemd and firewalld
- PostgreSQL 16 server and client tools
- A dedicated backup directory at
/var/backups/postgresql - A restore validation directory at
/var/lib/pgsql/restore-test - A repeatable verification script and a clean rollback path
Before you begin, keep the original root session open until you confirm the non-root admin works. For a broader recovery playbook after a bad database change, see PostgreSQL restore validation on RHEL 9 and PostgreSQL PITR recovery guidance.
Connect to the server and confirm openSUSE Leap
On your local computer, start by connecting as root.
ssh root@203.0.113.10203.0.113.10 is a reserved documentation address. Replace it with the real public IP assigned to your Hostperl server.
Once you are connected, check the operating system.
cat /etc/os-releaseOn the VPS as root, this should show openSUSE Leap. If it does not, stop here and adapt the package commands to your actual distribution.
Create a non-root administrator and test SSH access
Do not work as root for the rest of the tutorial. Create a sudo-capable administrator named deploy, then test the login in a second terminal before you change any login policy.
On the VPS as root, create the account and grant sudo access.
useradd -m -s /bin/bash deploy
passwd deploy
usermod -aG wheel deployThis creates the user, sets a password, and adds it to the wheel group used on SUSE systems for privilege escalation.
Now create the SSH directory and add your public key. Replace the key string with your own public key.
mkdir -p /home/deploy/.ssh
chmod 700 /home/deploy/.ssh
cat > /home/deploy/.ssh/authorized_keys <<'EOF'
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIExampleKeyReplaceThisWithYourOwn deploy@example.com
EOF
chown -R deploy:deploy /home/deploy/.ssh
chmod 600 /home/deploy/.ssh/authorized_keysThen open a second terminal and log in as the new user.
ssh deploy@203.0.113.10If your provider uses a default non-root account, use that account name instead of root. After you log in, confirm sudo access.
sudo -v
whoami
pwdYou should see deploy from whoami. Keep the root session open until this works.
Update packages and install PostgreSQL 16
On the VPS as the non-root sudo user, refresh package metadata and install PostgreSQL plus the client tools.
sudo zypper refresh
sudo zypper install -y postgresql16-server postgresql16 postgresql16-contribOn openSUSE Leap, package names follow the distribution repository naming. After installation, confirm the version.
psql --version
postgres --versionYou should see PostgreSQL 16.x. If the repository is missing the versioned package names, check enabled repositories before proceeding.
zypper lr -uIf you later deploy a larger database on a Hostperl dedicated server or a regional instance with fast NVMe, this same backup process scales well because it depends on disk throughput and restore testing discipline.
Initialize PostgreSQL and start the service
On the VPS as root, initialize the database cluster with the distribution helper, then start and enable the service.
sudo systemctl enable --now postgresqlOn openSUSE, the packaged service usually handles the initial database setup through vendor scripts. Confirm that PostgreSQL is active.
sudo systemctl status postgresql --no-pager
sudo ss -ltnp | grep 5432You should see the service in active (running) state and a listener on port 5432.
Create a backup user, database, and test data
Backups are only useful if they capture something real. Create a small test database and table so your restore test proves more than an empty cluster.
On the VPS as the non-root sudo user, switch into the PostgreSQL account and create the database objects.
sudo -iu postgres psqlInside the PostgreSQL prompt, run the following SQL, then exit with \q.
CREATE USER backupuser WITH PASSWORD 'ChangeThisBackupUserPasswordNow';
CREATE DATABASE backupdemo OWNER backupuser;
\c backupdemo
CREATE TABLE orders (
id bigserial PRIMARY KEY,
customer_name text NOT NULL,
created_at timestamptz NOT NULL DEFAULT now()
);
INSERT INTO orders (customer_name) VALUES ('Hostperl Test Customer');
Next, create a backup directory with strict permissions.
sudo mkdir -p /var/backups/postgresql
sudo chown postgres:postgres /var/backups/postgresql
sudo chmod 700 /var/backups/postgresqlThis keeps SQL dumps and compressed archives away from normal users.
Create a repeatable backup script
Use a simple shell script so you can schedule the backup later without rewriting the command. The script creates a timestamped plain dump and a compressed custom-format dump, then records a checksum.
On the VPS as root, create the script.
sudo tee /usr/local/sbin/pg-backup-demo.sh > /dev/null <<'EOF'
#!/bin/bash
set -euo pipefail
BACKUP_DIR="/var/backups/postgresql"
DATE="$(date +%F_%H-%M-%S)"
PLAIN_FILE="${BACKUP_DIR}/backupdemo-${DATE}.sql"
CUSTOM_FILE="${BACKUP_DIR}/backupdemo-${DATE}.dump"
CHECKSUM_FILE="${BACKUP_DIR}/backupdemo-${DATE}.sha256"
sudo -u postgres pg_dump backupdemo > "${PLAIN_FILE}"
sudo -u postgres pg_dump -Fc backupdemo > "${CUSTOM_FILE}"
sha256sum "${PLAIN_FILE}" "${CUSTOM_FILE}" > "${CHECKSUM_FILE}"
EOF
sudo chmod 750 /usr/local/sbin/pg-backup-demo.sh
sudo chown root:root /usr/local/sbin/pg-backup-demo.shRun the script once.
sudo /usr/local/sbin/pg-backup-demo.sh
sudo ls -lh /var/backups/postgresqlYou should see the .sql, .dump, and .sha256 files. If you do not, inspect the script permissions and PostgreSQL access.
Validate the PostgreSQL backup verification results
A backup passes only when it can be read. First, check the checksum file. Then inspect the dump contents.
sudo sha256sum -c /var/backups/postgresql/backupdemo-*.sha256
sudo -u postgres pg_restore -l /var/backups/postgresql/backupdemo-*.dump | head -n 20
sudo head -n 20 /var/backups/postgresql/backupdemo-*.sqlSuccessful checksum verification tells you the files were not altered after creation. The listing from pg_restore -l confirms that the compressed dump is readable.
Run a restore test in an isolated location
Now restore the backup into a separate database, not over your live one. That gives you a safe verification point and a rollback path if the dump is corrupt.
On the VPS as root, create a scratch database and restore into it.
sudo -iu postgres createdb restorecheck
sudo -iu postgres pg_restore -d restorecheck /var/backups/postgresql/backupdemo-*.dump
sudo -iu postgres psql -d restorecheck -c "SELECT count(*) FROM orders;"
sudo -iu postgres psql -d restorecheck -c "SELECT * FROM orders;"You should see one row from the sample table. If the count is not 1, the restore test did not reproduce the source data and you should stop.
For practical restore work on production systems, this kind of validation pairs well with the guidance in MariaDB restore testing and secrets rotation habits for application backups when your stack includes containers or multiple services.
Schedule the backup with systemd and verify persistence
A real hosting server needs automation. Use a systemd timer so the backup runs after reboot without relying on a user session.
On the VPS as root, create the service unit.
sudo tee /etc/systemd/system/pg-backup-demo.service > /dev/null <<'EOF'
[Unit]
Description=PostgreSQL demo backup
[Service]
Type=oneshot
ExecStart=/usr/local/sbin/pg-backup-demo.sh
EOFCreate the timer next.
sudo tee /etc/systemd/system/pg-backup-demo.timer > /dev/null <<'EOF'
[Unit]
Description=Run PostgreSQL demo backup daily
[Timer]
OnCalendar=daily
Persistent=true
Unit=pg-backup-demo.service
[Install]
WantedBy=timers.target
EOFCheck the unit files, reload systemd, and enable the timer.
sudo systemd-analyze verify /etc/systemd/system/pg-backup-demo.service /etc/systemd/system/pg-backup-demo.timer
sudo systemctl daemon-reload
sudo systemctl enable --now pg-backup-demo.timer
sudo systemctl list-timers --all | grep pg-backup-demoVerify reboot persistence by checking the timer after a reboot. The Persistent=true setting means missed runs should catch up after downtime.
Allow PostgreSQL access only where needed
If this server serves only local applications, keep PostgreSQL bound to localhost. If you need remote access, open port 5432 only to trusted addresses. On openSUSE Leap, use firewalld when you need network exposure.
On the VPS as root, first check whether firewalld is active.
sudo systemctl status firewalld --no-pager
sudo firewall-cmd --stateIf it is active and you really need remote connections, allow PostgreSQL from a controlled zone or subnet. Replace the source subnet with your own management network.
sudo firewall-cmd --permanent --add-service=postgresql
sudo firewall-cmd --reload
sudo firewall-cmd --list-servicesDo not open PostgreSQL to the entire internet unless you have a specific, reviewed design for that exposure.
Troubleshooting the most likely failures
1. PostgreSQL will not start. Check the logs first.
sudo journalctl -u postgresql -b --no-pager | tail -n 50Look for permission errors, port conflicts, or initialization problems. If the data directory ownership is wrong, fix it and restart.
sudo chown -R postgres:postgres /var/lib/pgsql
sudo systemctl restart postgresql2. The backup script creates empty files. Confirm that the commands run as the PostgreSQL user and that the database exists.
sudo -u postgres psql -l
sudo -u postgres pg_dump backupdemo | headIf the database name is wrong, update the script and rerun it.
3. Restore fails with missing objects or permissions. Inspect the dump and verify the source database role.
sudo -u postgres pg_restore -l /var/backups/postgresql/backupdemo-*.dump | head -n 40
sudo -iu postgres psql -d restorecheck -c '\dt'If the target database already contains conflicting objects, drop and recreate the restore test database before trying again.
sudo -iu postgres dropdb restorecheck
sudo -iu postgres createdb restorecheck
sudo -iu postgres pg_restore -d restorecheck /var/backups/postgresql/backupdemo-*.dumpSafe rollback and recovery path
If a backup validation run exposes a problem, your rollback is simple: stop using the broken backup set, keep the previous known-good archive, and restore from the last verified dump into a clean database. For production change control, also keep a second copy of the verified backup off the server, such as on object storage or a separate backup host.
If you need to undo the test-only objects from this tutorial, remove the scratch database and optional timer after you confirm the process.
sudo -iu postgres dropdb restorecheck
sudo systemctl disable --now pg-backup-demo.timer
sudo rm -f /etc/systemd/system/pg-backup-demo.service /etc/systemd/system/pg-backup-demo.timer
sudo systemctl daemon-reloadThat leaves the PostgreSQL server intact and removes only the test automation.
Final checks from the server and a client
On the VPS as root, confirm the service, timer, and listener.
sudo systemctl is-active postgresql
sudo systemctl is-active pg-backup-demo.timer
sudo ss -ltnp | grep 5432On the VPS as the non-root sudo user, confirm the backup directory and the latest files.
sudo ls -lh /var/backups/postgresql
sudo tail -n 20 /var/backups/postgresql/backupdemo-*.sqlOn a client or admin workstation, if remote PostgreSQL access is enabled, test the port reachability from your trusted network.
nc -vz 203.0.113.10 5432Replace 203.0.113.10 with the real server IP. A successful connection means the firewall and listener are aligned with your design.
If you run PostgreSQL on Hostperl, this backup-verification workflow is a practical baseline for production readiness. For workloads that need more disk throughput or larger restore windows, compare Hostperl VPS with dedicated server hosting before you plan your retention policy.
Hostperl support teams regularly help customers validate restores before launch, during migrations, and after maintenance windows. That is the point of testing here: fewer surprises later.
FAQ
How often should I test PostgreSQL backups?
Run a restore test at least weekly for active production systems, and after any change to backup tooling, storage, or major PostgreSQL versions.
Should I use plain SQL dumps or custom-format dumps?
Use both if you can. Plain SQL is easy to inspect, while custom-format dumps support more flexible restore operations with pg_restore.
Can I trust checksum files alone?
No. Checksums help confirm file integrity, but only a real restore test proves that the backup contains usable data.
Do I need firewalld open for local-only backups?
No. If PostgreSQL is only accessed locally by applications on the same host, keep the port closed to the network.
What is the safest rollback after a failed validation?
Keep the last known-good archive, restore it into a fresh test database, and do not overwrite the live cluster until the restore passes again.
