A backup you have never restored is a guess. In this walkthrough, our team tested the whole cycle on a CentOS server running PostgreSQL 17.11: create a database, take a custom-format backup with pg_dump, drop a table on purpose, and restore it with pg_restore. Every screenshot below comes from that run. If you look after PostgreSQL in production, you can repeat the same steps in a lab before you rely on a backup routine.
The backup and restore flow at a glance
| Stage | Tool or command | What it does |
|---|---|---|
| Prepare | psql | Create a database and a table with sample rows |
| Back up | pg_dump -Fc | Write a custom-format archive of the database |
| Simulate loss | DROP TABLE | Remove the table to test recovery |
| Restore | pg_restore --clean --if-exists | Drop existing objects, then restore them from the archive |
Figure: the four stages of the lab test.
Step 1: Confirm the service and the version
First, check that the PostgreSQL 17 service is running and enabled at boot. The status output shows it active (running) and set to start automatically after a reboot. Then confirm the client version with psql --version, which reports PostgreSQL 17.11 in our lab.


Step 2: Create a database and connect to it
Create a dedicated lab database with CREATE DATABASE dba_backup_lab; and confirm the message reads CREATE DATABASE. Then connect with \c dba_backup_lab. The session confirms it is connected as the postgres user.


Step 3: Create a table and insert sample rows
The test table is employees, with four columns: emp_id as a SERIAL PRIMARY KEY, emp_name, department and salary as NUMERIC(10,2). The INSERT adds four employee records, and PostgreSQL reports INSERT 0 4.


Step 4: Verify the data before you back it up
Run SELECT * FROM employees; to confirm the four rows are in place. Checking the data before the backup gives you a baseline to compare against after the restore.

Step 5: Take a custom-format backup
Create a backup directory, then run pg_dump with the custom format flag, -Fc. The custom format writes a compressed archive that pg_restore reads. The archive in our test was dba_backup_lab.backup, and the file listing shows it at 3.0 KB.
In this lab we wrote the backup to /tmp/pg_backup_lab. The /tmp directory is cleared on reboot, so treat that path as a lab convenience only. In production, write backups to a directory that survives reboots and is copied off the server.



Step 6: Reconnect and simulate accidental data loss
Reconnect to the database with psql -U postgres -d dba_backup_lab, then drop the table with DROP TABLE employees;. PostgreSQL confirms the drop. The table is gone, and this is the situation the backup exists for.


Run \dt to list the tables. The output reads Did not find any relations, which confirms the table is missing.

Step 7: Restore with pg_restore
Restore the database with pg_restore against the custom-format archive. The --clean flag drops existing objects before they are recreated, and --if-exists stops PostgreSQL from raising errors when an object is already missing. --if-exists is only valid when --clean is also set.
pg_restore -U postgres \ --clean \ --if-exists \ -d dba_backup_lab /tmp/pg_backup_lab/dba_backup_lab.backup
Figure 14. pg_restore with --clean and --if-exists, as run in the lab.
Step 8: Confirm the table and the records came back
List the tables again with \dt. The employees table is back in the public schema and owned by postgres. Then check the records: SELECT * returns the four original rows with their original IDs, and SELECT COUNT(*) returns 4.

| emp_id | emp_name | department | salary |
|---|---|---|---|
| 1 | Arun | Database | 35000.00 |
| 2 | Kumar | Cloud | 45000.00 |
| 3 | Priya | Testing | 40000.00 |
| 4 | Rahul | Support | 30000.00 |
(4 rows)
Figure 16. All four original rows are back. Recreated from the lab screenshot.

Step 9: Check the totals
As a final check, sum the salaries. The query returns total_records of 4 and a total_salary of 150000.00, which matches the values before the drop.

Gotcha: restoring into a database that still has the objects
If the table still exists when you restore, pg_restore tries to create objects that are already there and reports errors. The --clean flag solves that by dropping objects first. Add --if-exists to keep the restore output clean when some objects are missing. Test this on a copy before you run it against a live database.
Limits to know
The PostgreSQL 17 documentation sets out a few rules that matter for a backup routine:
| Limit | What it means | What to do instead |
|---|---|---|
| Custom format is for pg_restore | The -Fc archive is not a SQL script. Only pg_restore reads it. | Use pg_restore for custom-format archives. Use plain format if you need a SQL script. |
| Compressed by default | The archive is smaller than the raw data. | Check archive size and restore time when you plan storage. |
| --if-exists needs --clean | The flag is rejected on its own. | Always pass both flags together. |
| Logical snapshot | The archive holds the data as it was at dump time. | Schedule dumps and keep the time of each backup in your runbook. |
Sources: pg_dump, PostgreSQL 17 and pg_restore, PostgreSQL 17.
Where this fits in a DBA's day
A logical backup like this suits smaller databases, single schemas, and table-level recovery. For larger databases, combine logical backups with physical backups and point-in-time recovery. Whichever method you use, run a test restore on a schedule, and keep a copy of the archive away from the database server. A backup that has never been restored is not yet a recovery plan. For teams that want help designing that routine, see our high availability and disaster recovery services and our DBA managed services.
Wrapping up
The test covered the full cycle: a custom-format backup with pg_dump, a deliberate table drop, and a restore with pg_restore --clean --if-exists that brought back all four rows. The commands are simple. The discipline is in running the restore before you need it. If you want a second pair of eyes on your PostgreSQL backup setup, start with our free database audit or talk to our team. For more practical guides, visit the Geopits blog.
FAQ
1. What does the -Fc option do in pg_dump?
It writes a custom-format archive that pg_restore reads. The archive is compressed by default and lets you restore selected objects.
2. Why does pg_restore need --clean?
--clean drops existing objects before pg_restore recreates them. Without it, a restore into a database that still has those objects reports errors.
3. Can I use --if-exists without --clean?
No. The PostgreSQL documentation states that --if-exists is not valid unless --clean is also specified.
4. Is /tmp a safe place for backups?
Not for production. The /tmp directory is cleared on reboot. Use a directory that survives reboots and is copied off the server.
5. Should I test restores on a schedule?
Yes. A backup that has never been restored has not been proven. Restore to a separate database on a regular schedule and compare the row counts.
Related reading
- PostgreSQL performance tuning for slow databases
- PostgreSQL slow after migration: a DBA guide
- SQL Server backup types and creation
Sources
PostgreSQL 17 documentation: pg_dump and pg_restore.


.avif)
