Fedora37 PostgreSQL14のデータベースをバックアップ/リストアする方法
環境
# cat /etc/redhat-release
Fedora release 37 (Thirty Seven)
操作方法
1.データベースをバックアップします
書式
# [--format=*] で指定可能な形式 # p = plain (SQL) # c = custom (圧縮形式) # t = tar # d = directory
使用例
1.[postgres] ユーザーが自身が所有する [testdb] データベースをバックアップします
$ pg_dump -U postgres --format=t -d testdb > dbbackup.tar $ ll *.tar -rw-r--r--. 1 postgres postgres 6656 1月 1 11:36 dbbackup.tar
2.管理ユーザー [postgres] で全データベースをバックアップします
$ pg_dumpall -f ~/backups/pg_DB_all.sql $ ls ~/backups pg_DB_all.sql
3.バックアップファイルからのデータベースのリストアです
[postgres] ユーザーがバックアップファイルから [testdb] データベースをリストア
$ pg_restore -U postgres -d testdb dbbackup.tar
管理ユーザー [postgres] でバックアップファイルから全データベースをリストアします
$ psql -f ~/backups/pg_DB_all.sql