赞
踩
postgresql日志类型:
ps:在10.0版本开始,pg_xlog目录被重新命名为pg_wal,pg_clog目录被重命名为pg_xact,pg_log目录被重命名为log
1.log
1)pg_log的开启,修改postgresql.conf相关配置
##开启日志记录
logging_collector = on
##stderr,csvlog,syslog,and eventlog,默认stderr
log_destination = 'stderr'
##日志保存路径
log_directory = '/data/pg_data/log/'
##日志文件格式
log_filename = 'postgresql-%Y-%m-%d_%H%M%S.log'
##日志文件权限
log_file_mode = 0600
##是否开启通过日志覆盖模式
log_truncate_on_rotation = off
##日志输出格式
log_line_prefix = '%t:%r:%u@%d:[%p]:'
##none, ddl, mod, all,需要记录的类型
log_statement = 'ddl'
2.pg_wal
1)WAL(Write-Ahead Logging)
2)WAL日志命名规则
例如:000000010000000000000003
3)WAL日志LSN(log sequence number)编号规则
-- 查看当前的lsn号
select pg_current_wal_lsn();
0/3E4E6A0
-- 查看的当前lsn的wal日志文件名
select pg_walfile_name(pg_current_wal_lsn());
000000030000000000000003
-- 查看当前lsn的偏移量
select pg_walfile_name_offset(pg_current_wal_lsn());
(000000030000000000000003,15001248)
-- 16进制转换数值
select x'E4E6A0'::int
15001248
-- 手动刷新wal
select pg_switch_wal();
4)WAL流程
a.当数据库中的数据发生变更时:
b.触发checkpoint触发场景:
c.checkpoit相关配置
-- 查看checkpoint_timeout配置,默认5min
show checkpoint_timeout;
-- 查看max_wal_size配置,默认1GB
show max_wal_size;
-- checkpoint_completion_target:指定检查点完成的目标。默认0.5
-- 可以降低checkpoint对性能的影,但是数值过大时在数据库出现故障时候,会比较危险
show checkpoint_completion_target;
5)当前WAL的信息获取
pg_controldata -D /data/pg_data/data
pg_control version number: 1100
Catalog version number: 201809051
Database system identifier: 7018374463638270579
Database cluster state: in production
pg_control last modified: Mon 13 Dec 2021 03:16:58 PM CST
Latest checkpoint location: 0/3E4E5F8
Latest checkpoint's REDO location: 0/3E4E5C0
Latest checkpoint's REDO WAL file: 000000030000000000000003
Latest checkpoint's TimeLineID: 3
Latest checkpoint's PrevTimeLineID: 3
Latest checkpoint's full_page_writes: on
Latest checkpoint's NextXID: 0:710
Latest checkpoint's NextOID: 41209
Latest checkpoint's NextMultiXactId: 1
Latest checkpoint's NextMultiOffset: 0
Latest checkpoint's oldestXID: 561
Latest checkpoint's oldestXID's DB: 1
Latest checkpoint's oldestActiveXID: 710
Latest checkpoint's oldestMultiXid: 1
Latest checkpoint's oldestMulti's DB: 1
Latest checkpoint's oldestCommitTsXid:0
Latest checkpoint's newestCommitTsXid:0
Time of latest checkpoint: Mon 13 Dec 2021 03:16:58 PM CST
Fake LSN counter for unlogged rels: 0/1
Minimum recovery ending location: 0/0
Min recovery ending loc's timeline: 0
Backup start location: 0/0
Backup end location: 0/0
End-of-backup record required: no
wal_level setting: replica
wal_log_hints setting: on
max_connections setting: 100
max_worker_processes setting: 8
max_prepared_xacts setting: 0
max_locks_per_xact setting: 64
track_commit_timestamp setting: off
Maximum data alignment: 8
Database block size: 8192
Blocks per segment of large relation: 131072
WAL block size: 8192
Bytes per WAL segment: 16777216
Maximum length of identifiers: 64
Maximum columns in an index: 32
Maximum size of a TOAST chunk: 1996
Size of a large-object chunk: 2048
Date/time type storage: 64-bit integers
Float4 argument passing: by value
Float8 argument passing: by value
Data page checksum version: 0
Mock authentication nonce: 6aa093cf542692ca29bda2051fdfce33f70da31a756e0e6939746a14bb62cb57
6)WAL日志解析工具使用
pg_waldump的使用
pg_waldump使用语法:
pg_waldump [option] … [startseg [endseg]]
常用参数:
参数 | 描述 |
---|---|
-b,--bkp-details | 输出关于备份的相关信息 |
-s,--start=recprt | 从指定WAL RECPTR开始解析 |
-e,--end=recprt | 解析结束到指定WAL RECPTR |
-f,--follow | 解析到最新WAL后继续解析 |
-n,--limit=N | 指定解析记录的数量 |
-p,--path=path | 解析日志的路径 |
-r,--rmgr=rmgr | 只显示资源管理器RMGR生成的记录 |
-t,--timeline | 指定开始解析时间轴的日志 |
-V,--version | 输出版本信息 |
-x,--xid | 只显示事务的XID记录 |
-z,--stats | 不显示记录,只显示statistics信息 |
-?,--help | 帮助信息 |
pg_waldump /data/pg_data/data/pg_wal/000000010000000000000003
rmgr: Btree len (rec/tot): 72/ 72, tx: 673, lsn: 0/0301A5D0, prev 0/0301A520, desc: INSERT_LEAF off 55, blkref #0: rel 1663/13287/2658 blk 14
rmgr: Btree len (rec/tot): 64/ 64, tx: 673, lsn: 0/0301A618, prev 0/0301A5D0, desc: INSERT_LEAF off 366, blkref #0: rel 1663/13287/2659 blk 9
rmgr: Heap len (rec/tot): 175/ 175, tx: 673, lsn: 0/0301A658, prev 0/0301A618, desc: INSERT off 10, blkref #0: rel 1663/13287/1249 blk 52
rmgr: Btree len (rec/tot): 72/ 72, tx: 673, lsn: 0/0301A708, prev 0/0301A658, desc: INSERT_LEAF off 58, blkref #0: rel 1663/13287/2658 blk 14
rmgr: Btree len (rec/tot): 64/ 64, tx: 673, lsn: 0/0301A750, prev 0/0301A708, desc: INSERT_LEAF off 366, blkref #0: rel 1663/13287/2659 blk 9
rmgr: Heap len (rec/tot): 175/ 175, tx: 673, lsn: 0/0301A790, prev 0/0301A750, desc: INSERT off 11, blkref #0: rel 1663/13287/1249 blk 52
rmgr: Btree len (rec/tot): 72/ 72, tx: 673, lsn: 0/0301A840, prev 0/0301A790, desc: INSERT_LEAF off 55, blkref #0: rel 1663/13287/2658 blk 14
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。