Ubuntu 26.04

PostgreSQL 18 : Backup and Restore2026/05/28

 

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

# [ubuntu] user takes backup of [testdb]
ubuntu@www:~$
pg_dump -U ubuntu --format=t -d testdb > pg_testdb.tar

ubuntu@www:~$
total 8
-rw-rw-r-- 1 ubuntu ubuntu 6656 May 28 02:09 pg_testdb.tar


# admin user [postgres] takes backup of all databases

postgres@www:~$
mkdir ~/backups

postgres@www:~$
pg_dumpall -f ~/backups/pg_DB_all.sql

postgres@www:~$
ll ~/backups

total 8
-rw-rw-r-- 1 postgres postgres 4304 May 28 02:10 pg_DB_all.sql
[2] Restore Databases.
# [ubuntu] user restores [testdb] database from backup file

ubuntu@www:~$
pg_restore -U ubuntu -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

Matched Content