文章目录
备份表结构 (导出文本文件格式dump)
pg_dump -U postgres -d test -f test.sql -s
备份表结构、数据(导出文本文件格式dump)
pg_dump -U postgres -d test -f test.sql
恢复数据库(dump文件为文本文件格式)
psql -d test -U postgres -f test.sql
数据库dump文件指定压缩级别 (dump文件为文本文件格式)
添加 -Z参数,指定压缩级别:
pg_dump -U postgres -d test -Z 9 -f /data/pgsql/backups/dev_$backup_date.gz
数据库恢复(压缩后的dump文件,dump文件为文本文件格式)
cat dev_20221128.gz | gunzip | psql -d test
指定文件导出格式 (二进制压缩文件)
添加 -F参数,指定dump文件格式:
默认是-F p文本格式, -F c指定导出一个二进制文件
pg_dump -U postgres -d test -Z 9 -F c -f /data/pgsql/backups/test.dump
恢复数据库(二进制压缩文件)
pg_restore -U postgres -C -d postgres /data/pgsql/backups/test.dump