陈老师:1415968548 郑老师:2735197625 乐老师:354331153
客服热线:
19941464235/19906632509(微信同号)

客服微信

PostgreSQL归档配置

作者:崔鹏
原创
发布时间:2023-12-19 10:12
浏览量:643

作者:崔鹏

中国首批PGCM大师,PostgreSQL官方认证讲师 ,拥有PostgreSQL数据库管理高级工程师(PGCM)、MySQL 5.7/8.0 OCP、Oracle 11g OCM等证书。


查看归档参数是否开启


postgres@pgexp1-> psqlpostgres=# show archive_mode; archive_mode -------------- off(1 row)


开启归档


postgres@pgexp1-> cd $PGDATApostgres@pgexp1-> vi postgresql.conf


添加以下参数


wal_level = replicaarchive_mode = onarchive_command = 'DIR=/opt/pg_arch/`date +%F`; test ! -d $DIR && mkdir -p $DIR; chmod 755 $DIR; test ! -f $DIR/%f && cp %p $DIR/%f; chmod 755 $DIR/%f'


重启数据库


postgres@pgexp1-> pg_ctl restart


检查归档日志是否生效


postgres@pgexp1-> psqlpostgres=# show archive_mode; archive_mode -------------- on(1 row)#切换归档postgres=# select pg_switch_wal();  pg_switch_wal --------------- 0/2000160(1 row)