顺手记录下简单版本的编译步骤
./configuremakesumake installadduser postgresmkdir usr/local/pgsql/datachown postgres usr/local/pgsql/datasu - postgres/usr/local/pgsql/bin/initdb -D usr/local/pgsql/data/usr/local/pgsql/bin/pg_ctl -D usr/local/pgsql/data -l logfile start
直入正题
今天主要学习下PostgreSQL的后端进程中的checkpointer对应的checkpoint
先看看都有哪些后端进程
[postgres@mingfan bin]$ ps -ef |grep postgrespostgres 389889 1 0 22:11 ? 00:00:00 usr/local/pgsql/bin/postgres -D ../datapostgres 389891 389889 0 22:11 ? 00:00:00 postgres: checkpointerpostgres 389892 389889 0 22:11 ? 00:00:00 postgres: background writerpostgres 389893 389889 0 22:11 ? 00:00:00 postgres: walwriterpostgres 389894 389889 0 22:11 ? 00:00:00 postgres: autovacuum launcherpostgres 389895 389889 0 22:11 ? 00:00:00 postgres: stats collectorpostgres 389896 389889 0 22:11 ? 00:00:00 postgres: logical replication launcher

可以看到PostgreSQL后端是由称为Postmaster(postgres)的主进程派生出来的进程的集合。
回到checkpoint
checkpoint的作用
checkpointer进程称为检查点进程,checkpoint操作会将某个时间点之前的脏数据都刷新到磁盘。
PostgreSQL在崩溃恢复时会以最近的checkpoint为基础,不断应用这之后的WAL日志。
简单来讲
我的数据库突然崩溃了,数据库重新启动的时候会去读取检查点,假定最近的检查点在10min前,则数据库会从该检查点开始应用检查点之后的wal日志进行数据恢复,假定最近的检查点在5min前,那数据库只需要重放数据库崩溃前5min的wal日志就能成功恢复数据了,这样做的目的是为了缩短数据库故障后的恢复时间
checkpoint的相关参数
postgresql.conf文件中的相关参数如下:
# - Checkpoints -#checkpoint_timeout = 5min # range 30s-1dmax_wal_size = 1GBmin_wal_size = 80MB#checkpoint_completion_target = 0.5 # checkpoint target duration, 0.0 - 1.0#checkpoint_flush_after = 256kB # measured in pages, 0 disables#checkpoint_warning = 30s # 0 disables
checkpoint的发生时机
超级用户(其他用户不可)执行CHECKPOINT命令
数据库shutdown
数据库recovery完成
XLOG日志量达到了触发checkpoint阈值
周期性地checkpoint
需要刷新所有脏页
如何查看checkpoint相关信息
可以通过pg_controldata进行查看
pg_controldata ../data---[postgres@iZbp1fpui5cmgd2buwhk5fZ bin]$ ./pg_controldata ../data/pg_control version number: 1300Catalog version number: 202007201Database system identifier: 6893496605411273979Database cluster state: in productionpg_control last modified: Tue 10 Nov 2020 11:32:32 PM CSTLatest checkpoint location: 0/155E200Latest checkpoint's REDO location: 0/155E1C8Latest checkpoint's REDO WAL file: 000000010000000000000001Latest checkpoint's TimeLineID: 1Latest checkpoint's PrevTimeLineID: 1Latest checkpoint's full_page_writes: onLatest checkpoint's NextXID: 0:486Latest checkpoint's NextOID: 24576Latest checkpoint's NextMultiXactId: 1Latest checkpoint's NextMultiOffset: 0Latest checkpoint's oldestXID: 478Latest checkpoint's oldestXID's DB: 1Latest checkpoint's oldestActiveXID: 486Latest checkpoint's oldestMultiXid: 1Latest checkpoint's oldestMulti's DB: 1Latest checkpoint's oldestCommitTsXid:0Latest checkpoint's newestCommitTsXid:0Time of latest checkpoint: Tue 10 Nov 2020 11:32:32 PM CSTFake LSN counter for unlogged rels: 0/3E8Minimum recovery ending location: 0/0Min recovery ending loc's timeline: 0Backup start location: 0/0Backup end location: 0/0End-of-backup record required: nowal_level setting: replicawal_log_hints setting: offmax_connections setting: 100max_worker_processes setting: 8max_wal_senders setting: 10max_prepared_xacts setting: 0max_locks_per_xact setting: 64track_commit_timestamp setting: offMaximum data alignment: 8Database block size: 8192Blocks per segment of large relation: 131072WAL block size: 8192Bytes per WAL segment: 16777216Maximum length of identifiers: 64Maximum columns in an index: 32Maximum size of a TOAST chunk: 1996Size of a large-object chunk: 2048Date/time type storage: 64-bit integersFloat8 argument passing: by valueData page checksum version: 0Mock authentication nonce: 947e012a07d79fb1072fe46c80a49cdb772cf39fdbf2fe47863ac82d1b0ef2c4

非学,无以致疑,非问,无以广识~
文章转载自北重楼,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




