pg_current_xlog_insert_location、pg_current_xlog_location、pg_current_xlog_flush_location的含义

os: centos 7.4
postgresql: 9.6.10

最近在看postgresql的管理函数时,看到下面这几个函数,研究了一下:

pg_current_xlog_insert_location()	pg_lsn	Get current transaction log insert location
pg_current_xlog_location()	        pg_lsn	Get current transaction log write location
pg_current_xlog_flush_location()	pg_lsn	Get current transaction log flush location

pg_current_xlog_insert_location()	pg_lsn	获得当前事务日志插入位置
pg_current_xlog_location()	        pg_lsn	获得当前事务日志写入位置
pg_current_xlog_flush_location()	pg_lsn	得到当前的事务日志刷写位置

修改postgresql.conf 文件参数

synchronous_commit = off
wal_writer_delay = 200ms 

插入数据,查看

postgres=# create table tmp_t0 (c0 varchar(100),c1 varchar(100));
CREATE TABLE
postgres=# 
postgres=# 
postgres=# insert into tmp_t0 select md5(id::varchar),md5(id::varchar) from generate_series(1,1000000) as id;

postgres=# \x
postgres=# select pg_current_xlog_insert_location(),
                  pg_current_xlog_location(),
                  pg_current_xlog_flush_location();
-[ RECORD 1 ]-------------------+-----------
pg_current_xlog_insert_location | 0/15062020
pg_current_xlog_location        | 0/14C62000
pg_current_xlog_flush_location  | 0/14800000

可以看出:

pg_current_xlog_insert_location | 0/15062020
>=
pg_current_xlog_location        | 0/14C62000
>=
pg_current_xlog_flush_location  | 0/14800000

正确的理解应该是这样的:

pg_current_xlog_insert_location() 写入 wal buffer 的位置
pg_current_xlog_location()        write 到 wal 文件的位置
pg_current_xlog_flush_location()  wal 数据 flush 到磁盘的位置

参考:
https://www.postgresql.org/docs/9.6/static/functions-admin.html
http://postgres.cn/docs/9.6/functions-admin.html

你可能感兴趣的:(#,postgresql,wal,xlog,log)