重庆思庄Oracle、Redhat认证学习论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 671|回复: 0
打印 上一主题 下一主题

PG开启归档步骤

[复制链接]
跳转到指定楼层
楼主
发表于 2023-5-19 19:09:19 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
1、查询数据库的安装位置和归档时否开启
step 1:查看数据目录(找出conf文件位置)
postgres=# show data_directory;
   data_directory   
--------------------
/postgresql/pgdata
(1 row)

step 2:查看归档是否开启
postgres=# show archive_mode;
archive_mode
--------------
off
(1 row)

2、开启归档模式(开启后有一定的性能损耗)
step 1:创建归档目录
mkdir -p /postgresql/archive

step 2:修改目录所有者
chown postgres.postgres /postgresql/archive

step 3:修改postgresql.conf配置文件
archive_mode = on #开启归档

archive_command = 'DATE=date +%Y%m%d;DIR="/postgresql/archive/$DATE";(test -d $DIR || mkdir -p $DIR)&& cp %p $DIR/%f' #配置归档命令,%p : 表示将要归档的wal文件包含完整路径的信息的文件名,%f : 代表不包含路径信息的wal文件的文件名

step 3:重启pg
3、验证归档情况
step 1:查看归档是否开启
postgres=# show archive_mode;
archive_mode
--------------
on
(1 row)

postgres=# select name,setting from pg_settings where name like 'archive%';
          name           |                                              setting                                             
-------------------------+---------------------------------------------------------------------------------------------------
archive_cleanup_command |
archive_command         | DATE=$(date +%Y%m%d);DIR="/postgresql/archive/$DATE";(test -d $DIR || mkdir -p $DIR)&& cp %p $DIR/%f
archive_mode            | on
archive_timeout         | 1800
(4 rows)



step 2:检查点 , 刷新脏数据
checkpoint

OK
时间: 0.004s

step 3:查看归档情况
select pg_switch_wal();
postgres=# select pg_switch_wal();
pg_switch_wal
---------------
0/17287E70
(1 row)


step 4:查看归档文件
[postgres@webserver ~]$ cd /postgresql/archive/

[postgres@webserver archive]$ ls -ltr
总用量 65536
-rw------- 1 postgres postgres 16777216 5月  19 05:57 000000010000000000000017
-rw------- 1 postgres postgres 16777216 5月  19 05:59 000000010000000000000018
-rw------- 1 postgres postgres 16777216 5月  19 05:59 000000010000000000000019
-rw------- 1 postgres postgres 16777216 5月  19 06:20 00000001000000000000001A
drwx------ 2 postgres postgres       70 5月  19 06:21 20230519
[postgres@webserver archive]$ ls -ltr 20230519/
总用量 32768
-rw------- 1 postgres postgres 16777216 5月  19 06:21 00000001000000000000001B
-rw------- 1 postgres postgres 16777216 5月  19 06:21 00000001000000000000001C
[postgres@webserver archive]$
[postgres@webserver archive]$ ls -ltr /postgresql/pgdata/pg_wal/
总用量 147456
-rw------- 1 postgres postgres 16777216 5月  19 02:42 00000001000000000000001B
-rw------- 1 postgres postgres 16777216 5月  19 02:42 00000001000000000000001C
-rw------- 1 postgres postgres 16777216 5月  19 02:42 00000001000000000000001D
-rw------- 1 postgres postgres 16777216 5月  19 02:42 00000001000000000000001E
-rw------- 1 postgres postgres 16777216 5月  19 02:42 00000001000000000000001F
-rw------- 1 postgres postgres 16777216 5月  19 05:57 000000010000000000000017
-rw------- 1 postgres postgres 16777216 5月  19 05:59 000000010000000000000018
-rw------- 1 postgres postgres 16777216 5月  19 05:59 000000010000000000000019
drwx------ 2 postgres postgres      117 5月  19 05:59 archive_status
-rw------- 1 postgres postgres 16777216 5月  19 05:59 00000001000000000000001A
[postgres@webserver archive]$ ls -ltr /postgresql/pgdata/pg_wal/archive_status/
总用量 0
-rw------- 1 postgres postgres 0 5月  19 05:57 000000010000000000000017.done
-rw------- 1 postgres postgres 0 5月  19 05:59 000000010000000000000018.done
-rw------- 1 postgres postgres 0 5月  19 05:59 000000010000000000000019.done
[postgres@webserver archive]$

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 支持支持 反对反对
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|手机版|小黑屋|重庆思庄Oracle、Redhat认证学习论坛 ( 渝ICP备12004239号-4 )

GMT+8, 2024-5-18 12:01 , Processed in 0.173002 second(s), 19 queries .

重庆思庄学习中心论坛-重庆思庄科技有限公司论坛

© 2001-2020

快速回复 返回顶部 返回列表