PostgreSQL 18 : Backup and Restore2025/11/17 |
|
For Backup and Restore PostgreSQL Data, it's possible to run with [pg_dump] and [pg_restore]. |
|
| [1] | Backup Databases. |
# available types for [--format=*]
# p = plain (SQL)
# c = custom (compression)
# t = tar
# d = directory
# [fedora] user takes backup of [testdb]
[fedora@www ~]$ pg_dump -U fedora --format=t -d testdb > pg_testdb.tar [fedora@www ~]$ total 8 -rw-r--r--. 1 fedora fedora 6656 Nov 17 10:12 pg_testdb.tar # admin user [postgres] takes backup of all databases [postgres@www ~]$ pg_dumpall -f ~/backups/pg_DB_all.sql [postgres@www ~]$ ll ~/backups total 8 -rw-r--r--. 1 postgres postgres 4122 Nov 17 10:13 pg_DB_all.sql |
| [2] | Restore Databases. |
|
# [fedora] user restores [testdb] database from backup file [fedora@www ~]$ pg_restore -U fedora -d testdb pg_testdb.tar
# admin user [postgres] restores all database from backup file # if the type of backup file is SQL text, use [psql] command for restoring [postgres@www ~]$ psql -f ~/backups/pg_DB_all.sql |
| Sponsored Link |
|
|