pgsql的备份和恢复:备份:
1.pg_dump:(sql转储,类似于mysql的binlog的dump,可以加上压缩如gzip,可以设置压缩级别)备份:pg_dump dbname > outfile
恢复:psql dbname < infile
outfile 和infile是同一个文件
2.pg_dumpall:(sql转储,导出所有的db)
备份:pg_dumpall -f outfile
恢复:psql -f outfile postgres
3.pitr:在线备份,和oracle的归档原理差不多.
archive(归档文件):database manager 把query语句记录在 archive文件里,archive文件一般有多个,有固定大小.采取轮循的方式写.然后到了触发一定条件的时候,如:记录了1个小时的query语句了或者写满了1/2的时候.就执行这些query语句并把结果写到数据文件里.即记录到硬盘中.1.要使用pitr,必须打开pgsql的归档模式(archive)
在postgresql.conf文件中,设置如下:
# - Archiving -
archive_mode = on # allows archiving to be done
# (change requires restart)
archive_command = 'cp "%p" /usr/local/pgsql/backup/"%f"'
# command to use to archive a logfile segment
archive_timeout = 60 # force a logfile segment switch after this
# time; 0 is