4. Crash
•
Many database actions involve modifying more than one page.
•
Example: Splitting an index page.
•
Writing two data pages A and B is not atomic.
•
One write must happen before the other.
•
•
We need to give the operating system and disk controller freedom to reorder the writes;
we don't even know which one will happen first.
We could crash in between.
!
•
Writing one data page isn't even atomic.
•
Pages are 8kB, but the disk writes in chunks as small as 512 bytes.
•
We could crash in the middle (“torn page”).
23. 配置 - WAL參數
•
wal_sync_method
•
決定PostgreSQL以什麼樣⼦子的形式讓系統將Transaction寫⼊入磁碟
•
•
fsync (call fsync() at each commit)
•
fsync_writethrough (call fsync() at each commit, forcing write-through of any disk write
cache)
•
•
fdatasync (call fdatasync() at each commit)
•
•
open_datasync (write WAL files with open() option O_DSYNC)
open_sync (write WAL files with open() option O_SYNC)
⼀一般採⽤用系統預設,官⽅方⽂文件建議使⽤用pg_test_fsync來測試寫⼊入性能之後,在決定採⽤用的模式
wal_debug
•
每個XLogInsert及XFLogFlush的⾏行為將寫⼊入到Server Log內
•
未來將提供更好的機制來取代這個功能
24. 配置 - Archive
•
Archive (打包, ⼜又名歸檔)
•
•
也同時可作為備份歸檔⽤用途
•
•
由於WAL相當肥⼤大,所以可將使⽤用過的Log打包起來節省空間
利⽤用Archive做熱備援可參考: http://kaien.kaienroid.com/blog/?p=334
相關參數
•
archive_mode (Boolean)
•
•
是否啟動打包模式
archive_command (String)
•
•
•
使⽤用系統指令進⾏行打包
Any %p in the string is replaced by the path name of the file to archive, and any %f is replaced by only the
file name. (The path name is relative to the working directory of the server, i.e., the cluster's data directory.)
Use %% to embed an actual % character in the command. It is important for the command to return a zero
exit status only if it succeeds.
archive_timeout
•
強制Server在固定時間進⾏行打包