
写

读

postgres> pstree -p 9687
-+= 00001 root /sbin/launchd
\-+- 09687 postgres /usr/local/pgsql/bin/postgres -D /usr/local/pgsql/data
|--= 09688 postgres postgres: logger process
|--= 09690 postgres postgres: checkpointer process
|--= 09691 postgres postgres: writer process
|--= 09692 postgres postgres: wal writer process
|--= 09693 postgres postgres: autovacuum launcher process
|--= 09694 postgres postgres: archiver process
|--= 09695 postgres postgres: stats collector process
|--= 09697 postgres postgres: postgres sampledb 192.168.1.100(54924) idle
\--= 09717 postgres postgres: postgres sampledb 192.168.1.100(54964) idle in transaction 
Local Memory Area
Each backend process allocates a local memory area for query processing; each area is divided into several sub-areas – whose sizes are either fixed or variable. Table 2.2 shows a list of the major sub-areas. The details will be described in the following chapters.
sub-area | description |
|---|---|
work_mem | Executor uses this area for sorting tuples by ORDER BY and DISTINCT operations, and for joining tables by merge-join and hash-join operations. |
maintenance_work_mem | Some kinds of maintenance operations (e.g., VACUUM, REINDEX) use this area. |
temp_buffers | Executor uses this area for storing temporary tables. |
Shared Memory Area
sub-area | description |
|---|---|
shared buffer pool | PostgreSQL loads pages within tables and indexes from a persistent storage to here, and operates them directly. |
WAL buffer | To ensure that no data has been lost by server failures, PostgreSQL supports the WAL mechanism. WAL data (also referred to as XLOG records) are transaction log in PostgreSQL; and WAL buffer is a buffering area of the WAL data before writing to a persistent storage. |
commit log | Commit Log(CLOG) keeps the states of all transactions (e.g., in_progress,committed,aborted) for Concurrency Control (CC) mechanism. |

SQL解析成语法树,只检查语法错误
testdb=# SELECT id, data FROM tbl_a WHERE id < 300 ORDER BY data;
对由解析器生成的语法树进行语义分析,并生成查询树。

展开子查询的视图、一些常量函数等

查询树--->查询计划树

21亿之前的都是能看到的

tuple内部

insert

delete

update

事务快照
testdb=# SELECT txid_current_snapshot();
txid_current_snapshot
-----------------------
100:104:100,102
(1 row)事务快照真实情况:

事务快照在不同隔离级别下的使用方法:

PG用一个计算距离的算法来计算两个事务的差值,用差值计算决定两个事务的先后关系。
这个差值保存在一个21亿的变量里面,如果超了,就会溢出了得出相反的结果。
lazy_mode
freezeLimit_txid=(OldestXmin−vacuum_freeze_min_age)

Eager Mode
pg_database.datfrozenxid<(OldestXmin−vacuum_freeze_table_age)


fsm大根堆,父节点保存字节点中最大的空间,叶子节点指向数据页面,一个FSM页应该可以指向4000个数据页

full_page_write

xlog结构
