Hands-on Lab·PostgreSQL
PostgreSQL Database Restore
The database is dropped for real - which first requires evicting every connection - and rebuilt from the dump. An untested backup is a guess; this is the test.
Backup and Restore Guide 22 of 47 Beginner
- OSUbuntu 26.04 LTS
- PostgreSQL18.6-0ubuntu0.26.04.1
- wal_levelreplica
- TimeAbout 14 min
DROP DATABASE fails while any session is connected, including idle ones. pg_terminate_backend over pg_stat_activity is the standard way to clear them.
| Server Name | IP Address | OS | Roles | CPU | RAM | HDD |
|---|---|---|---|---|---|---|
| db-a01 | 192.168.0.81 | Ubuntu 26.04 LTS | Primary / Source / Replica Set Member 1 | 2 Core | 4 GB | 50 GB |
This guide includes
Use this when a restore has to be proved rather than assumed. This matters because dropping a database first requires evicting every connection - and verification is the numbers you wrote down, not an exit code.
- evicting the connections, since DROP DATABASE refuses while any remain
- recreating and restoring, since a plain dump is only SQL
- verifying against the numbers you recorded beforehand
Before you start
- The dump from the previous guide.
- A server you are willing to destroy.
-
Evict the connections, then drop it
-
Recreate and restore
-
Verify against the numbers you wrote down