http://francs3.blog.163.com/blog/static/40576727201352135115689/
今天一流复制( Streaming Replication) 数据库一目录空间告警,经查是 pg_xlog 目录
WAL 日志文件过多,已超过阀值。
pg_xlog 是数据库重做日志,非常重要,不能直接清理,否则给数据库带来巨大灾难,以
下是流复制环境下清理 pg_xlog 的方法。
--1 查看当前 checkpoint_segments 和 wal_keep_segments
| postgres@db> psql -h 127.0.0.1
psql (9.2.4)
Type "help" for help.
postgres=> show checkpoint_segments;
checkpoint_segments
---------------------
128
(1 row
postgres=> show wal_keep_segments ;
wal_keep_segments
-------------------
4096
(1 row)
|
--2 查看 pg_xlog 文件数量
| postgres@db> cd $PGDATA
postgres@db> ll pg_xlog/ | wc -l
4156
|
至于 pg_xlog 最大文件数量的估算参考之前 blog:
How to estimate total number of WAL segments ?
--3 修改 postgreql.conf
| wal_keep_segments = 2048 |
-
-4 reload 配置文件
| postgres@db> pg_ctl reload -D $PGDATA
server signaled
|
--4 再次查看 wal_keep_segments
| postgres=# show wal_keep_segments ;
wal_keep_segments
-------------------
2048
(1 row)
postgres@db> cd $PGDATA
postgres@db> ll pg_xlog/ | wc -l
4156
|
--5 执行 checkpoint;
| postgres=# checkpoint;
CHECKPOINT
|
--6 再次查看 pg_xlog 文件数量
| postgres@db> ll $PGDATA/pg_xlog/ | wc -l
2310
|
--6 参考
本文介绍了一种在PostgreSQL流复制环境中清理pg_xlog目录中WAL日志的方法,包括调整wal_keep_segments参数、执行checkpoint操作等步骤。

350

被折叠的 条评论
为什么被折叠?



