pgsql数据备份和恢复

pgsql数据备份和恢复:
1,sql dump
pg_dump dbname > dumpfile
恢复
psql dbname < dumpfile
备份db cluster
pg_dumpall > dumpfile
恢复
psql -f dumpfile postgres

2,文件系统备份
shutdown db server
备份文件系统

3,热备份
需要开启wal archiving
exclusive backup:
SELECT pg_start_backup(‘label’);
使用操作系统命令备份数据文件,归档日志
SELECT pg_stop_backup();

Non-Exclusive backup:
SELECT pg_start_backup(‘label’, false, false);
使用操作系统命令备份数据文件,归档日志
SELECT * FROM pg_stop_backup(false, true);
函数说明:
pg_start_backup(label text [, fast boolean [, exclusive boolean ]])
pg_stop_backup(exclusive boolean [, wait_for_archive boolean ])

4,备份软件
pg_basebackup、pg_rman
pg_basebackup是PostgreSQL自带的一个远程热备工具,可以将远程PostgreSQL热备到本地目录。不支持增量备份。
pg_rman是PostgreSQL的备份与恢复工具,pg_rman必须与被备份数据库安装在同一台机器。支持增量备份。

猜你喜欢

转载自blog.csdn.net/weixin_44311188/article/details/85772417