postgresql 數據庫的 xlog、wal 的文件名組成

os: centos 7.4
db: postgresql 10.10

PG使用無符號64bit整型(uint64)作爲日誌文件的尋址空間,爲了高效管理事務日誌文件,PG把日誌文件劃分爲N個大小爲16M(默認值)的WAL segment file.

版本

# cat /etc/centos-release
CentOS Linux release 7.4.1708 (Core) 
# 
# su - postgres
Last login: Sat Oct 26 22:55:25 CST 2019 on pts/0
$
$ psql -c "select version();"
                                                 version                                                  
----------------------------------------------------------------------------------------------------------
 PostgreSQL 10.10 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-36), 64-bit
(1 row)

wal filename

關閉 postgresql

# su - postgres 
$ cd $PGDATA/pg_wal
$ ls -l
total 425984
-rw------- 1 postgres postgres 16777216 Mar 21 20:20 000000010000000800000020
-rw------- 1 postgres postgres 16777216 Mar 19 15:17 000000010000000800000021
-rw------- 1 postgres postgres 16777216 Mar 19 15:17 000000010000000800000022
-rw------- 1 postgres postgres 16777216 Mar 19 15:18 000000010000000800000023
-rw------- 1 postgres postgres 16777216 Mar 19 15:18 000000010000000800000024
-rw------- 1 postgres postgres 16777216 Mar 19 15:18 000000010000000800000025
-rw------- 1 postgres postgres 16777216 Mar 19 15:18 000000010000000800000026
-rw------- 1 postgres postgres 16777216 Mar 19 15:18 000000010000000800000027
-rw------- 1 postgres postgres 16777216 Mar 19 15:18 000000010000000800000028
-rw------- 1 postgres postgres 16777216 Mar 19 15:18 000000010000000800000029
-rw------- 1 postgres postgres 16777216 Mar 19 15:18 00000001000000080000002A
-rw------- 1 postgres postgres 16777216 Mar 19 15:18 00000001000000080000002B
-rw------- 1 postgres postgres 16777216 Mar 19 15:18 00000001000000080000002C
-rw------- 1 postgres postgres 16777216 Mar 19 15:18 00000001000000080000002D
-rw------- 1 postgres postgres 16777216 Mar 19 15:18 00000001000000080000002E
-rw------- 1 postgres postgres 16777216 Mar 19 15:18 00000001000000080000002F
-rw------- 1 postgres postgres 16777216 Mar 19 15:18 000000010000000800000030
-rw------- 1 postgres postgres 16777216 Mar 19 15:18 000000010000000800000031
-rw------- 1 postgres postgres 16777216 Mar 19 15:18 000000010000000800000032
-rw------- 1 postgres postgres 16777216 Mar 19 15:18 000000010000000800000033
-rw------- 1 postgres postgres 16777216 Mar 19 15:18 000000010000000800000034
-rw------- 1 postgres postgres 16777216 Mar 19 15:18 000000010000000800000035
-rw------- 1 postgres postgres 16777216 Mar 19 15:18 000000010000000800000036
-rw------- 1 postgres postgres 16777216 Mar 19 15:18 000000010000000800000037
-rw------- 1 postgres postgres 16777216 Mar 19 15:18 000000010000000800000038
-rw------- 1 postgres postgres 16777216 Mar 19 15:18 000000010000000800000039
drwx------ 2 postgres postgres        6 Oct  5 21:54 archive_status

postgres=# select pg_current_wal_lsn();

 pg_current_wal_lsn      
--------------------
 8/20E63FE8         
(1 row)

postgres=# select pg_current_wal_lsn(),
                  pg_walfile_name(pg_current_wal_lsn()),
                  pg_walfile_name_offset(pg_current_wal_lsn());

 pg_current_wal_lsn |     pg_walfile_name      |       pg_walfile_name_offset        
--------------------+--------------------------+-------------------------------------
 8/20E63FE8         | 000000010000000800000020 | (000000010000000800000020,15089640)
(1 row)

pg_current_wal_lsn()= 8/20E63FE8
對應的 pg_walfile_name= 000000010000000800000020
同時也會留意到有很多文件比 000000010000000800000020 大,那是因爲 postgresql 會預生產 wal 文件來提高性能。

以 000000010000000800000020 爲例(24個字符,每8個字符爲一個邏輯單位),文件的組成部分如下

  1. 第1部分是時間線ID(TimeLineID) = 00000001
  2. 第2部分是邏輯文件ID(LogId) = 00000008
  3. 第3部分是物理文件ID(LogSeg) = 00000020

參考:

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章