PostgreSQL日誌號LSN簡記

來源:互聯網
上載者:User

標籤:編號   一段   恢複   目錄   sys   post   proc   日誌   status   

弄明白日誌號的原理之後,一段時間又有點忘記了,乾脆整理一遍:

 

(一)wal檔案命名規則

1)在$PGDATA目錄下面的pg_xlog目錄中存放著xlog記錄檔(10.1之後變為了pg_wal):

total 165896
-rw-r--r-- 1 apple staff 660K 11 22 15:46 000000010000000000000013.dump
-rw------- 1 apple staff 295B 11 22 16:12 000000010000000000000014.00000028.backup
-rw------- 1 apple staff 16M 12 15 16:28 000000010000000000000046
-rw------- 1 apple staff 16M 12 15 16:30 000000010000000000000047
-rw------- 1 apple staff 16M 12 15 16:30 000000010000000000000048
-rw-r--r-- 1 apple staff 357K 1 16 16:27 000000010000000000000044.dump
-rw------- 1 apple staff 16M 3 27 09:49 000000010000000000000045
-rw------- 1 apple staff 16M 3 27 09:49 000000010000000000000044
drwx------ 4 apple staff 136B 4 9 10:52 archive_status

2)wal日誌號由64位組成,即有2**64個日誌編號,用完了需要重設,但是這個數量已經很多了,相當於1024P個,1024*1024個T。

記錄檔則由24個16進位數字組成,分三部分:時間軸、LSN高32位、LSN低32位/(2**24)的值(即低32位中最高兩位,表示該記錄檔的LSN起始編號,結合具體的LSN方便理解一點)。

 

(二)在資料庫查看具體的日誌編號LSN

1)用到的一些方法:

apple=# select proname from pg_proc where proname like ‘pg_%_location‘;
proname
---------------------------------
pg_current_xlog_insert_location
pg_current_xlog_location
pg_last_xlog_receive_location
pg_last_xlog_replay_location
pg_tablespace_location
(5 rows)

 

2)資料庫中可以查詢到當前的日誌編號情況:

apple=# select pg_current_xlog_location();
pg_current_xlog_location
--------------------------
0/45000098
(1 row)

 

可以看到:

0表示LSN的高32位

45表示對應的xlog檔案的最後兩位

000098表示當前的LSN在對應的xlog中的位移位元組地址,我記得有人寫過工具來讀取xlog中對應塊的資料並解析的,需要的時候再用用。

從current_xlog_location也可以推斷出該日誌對應的xlog檔案:

時間軸0000000000000045 ----> 000000010000000000000045

 

(三)LSN在用於恢複時

1)通過pg_controldata來擷取control檔案中的控制資訊:

appledeMacBook-Pro-2:pg_xlog apple$ pg_controldata
pg_control version number: 942
Catalog version number: 201510051
Database system identifier: 6451705940496018968
Database cluster state: in production
pg_control last modified: 一 4/ 9 10:52:12 2018
Latest checkpoint location: 0/45000028        
Prior checkpoint location: 0/446C7878
Latest checkpoint‘s REDO location: 0/45000028  
Latest checkpoint‘s REDO WAL file: 000000010000000000000045
Latest checkpoint‘s TimeLineID: 1
Latest checkpoint‘s PrevTimeLineID: 1
Latest checkpoint‘s full_page_writes: on
Latest checkpoint‘s NextXID: 0/535519
Latest checkpoint‘s NextOID: 20278

 

2)用於恢複的兩個LSN

Latest checkpoint location: 0/45000028         --表示在做checkpoint本身的日誌號
Prior checkpoint location: 0/446C7878
Latest checkpoint‘s REDO location: 0/45000028  --表示checkpoint時wal日誌的位置,也是恢複時,開始日誌復原的起始日誌號,即從45這個wal檔案中的28位元組處開始重做wal日誌

 

PostgreSQL日誌號LSN簡記

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.