东瑜

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
  135 随笔 :: 0 文章 :: 11 评论 :: 21万 阅读

作者:@张扶摇
本文为作者原创,转载请注明出处:https://www.cnblogs.com/zhangshengdong/p/13153422.html


目录

开启PG的归档模式
1.查看pg的数据目录
2.查看pg的归档情况
3.查看归档的模式和位置
4.建立归档目录
5.配置归档参数
6.重启pg
7.查看&&切换归档日志
8.查看目录位置的归档文件

开启PG的归档模式

1.查看pg的数据目录

postgres=# SHOW data_directory;
     data_directory     
------------------------
 /var/lib/pgsql/12/data
(1 row)

2.查看pg的归档情况

postgres=# show archive_mode;
 archive_mode 
--------------
 off
(1 行记录)

可以看到,归档模式为OFF。

3.查看归档的模式和位置

rpm安装的pg,配置文件在/var/lib/pgsql/12/data/postgresql.conf

[postgres@localhost data]$ cat postgresql.conf |grep archive_mode
#archive_mode = off             # enables archiving; off, on, or always
[postgres@localhost data]$ cat postgresql.conf |grep archive_command
#archive_command = ''           # command to use to archive a logfile segment

4.建立归档目录

[postgres@localhost ~]$ cd /var/lib/pgsql/12/
[postgres@localhost 12]$ ls -l
总用量 8
drwx------ 20 postgres postgres 4096 6月  17 16:21 data
-rw-------  1 postgres postgres  997 6月  17 16:21 initdb.log
[postgres@localhost 12]$ mkdir arch

5.配置归档参数

vi /var/lib/pgsql/12/data/postgresql.conf

# - Archiving -

archive_mode = on              # enables archiving; off, on, or always
                                # (change requires restart)
archive_command = 'DATE=`date +%Y%m%d`;DIR="/var/lib/pgsql/12/arch/$DATE";(test -d $DIR || mkdir -p $DIR)&& cp %p $DIR/%f'             # command to use to archive a logfile segment

6.重启pg

systemctl stop postgresql-12
systemctl start postgresql-12 

7.查看&&切换归档日志

[postgres@localhost ~]$ psql
psql (12.3)
输入 "help" 来获取帮助信息.

postgres=# show archive_mode;
 archive_mode 
--------------
 on
(1 行记录)

postgres=# select pg_switch_wal();
 pg_switch_wal 
---------------
 0/169E208
(1 行记录)

8.查看目录位置的归档文件

[postgres@localhost ~]$ ls -l /var/lib/pgsql/12/arch/
总用量 4
drwx------ 2 postgres postgres 4096 6月  17 16:55 20200617


[postgres@localhost 20200617]$ ls -l 
总用量 32768
-rw------- 1 postgres postgres 16777216 6月  17 16:55 000000010000000000000001
-rw------- 1 postgres postgres 16777216 6月  17 16:57 000000010000000000000002


感谢您的阅读,如果您觉得阅读本文对您有帮助,请点一下“推荐”按钮。本文欢迎各位转载,但是转载文章之后必须在文章页面中给出作者和原文连接
posted on   东瑜  阅读(3736)  评论(0编辑  收藏  举报
编辑推荐:
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?
· 如何调用 DeepSeek 的自然语言处理 API 接口并集成到在线客服系统
\\页脚html代码
点击右上角即可分享
微信分享提示