当前位置:网站首页>If you want to understand PostgreSQL, you must first brush the architecture

If you want to understand PostgreSQL, you must first brush the architecture

2022-06-23 04:33:00 It bond


hello ! Hello everyone , I am a 【IT bond 】, Jianghu people jeames007,10 year DBA Work experience
A highly motivated 【 Bloggers in big data field 】!
China DBA union (ACDU) member , Currently engaged in DBA And program programming ,B Station and Tencent classroom lecturer , Live broadcast volume breaking 10W
Good at mainstream data Oracle、MySQL、PG Operations and development , Backup recovery , Installation migration , performance optimization 、 Fault emergency treatment, etc .
If there is a pair of 【 database 】 Interested in 【 Cutie 】, Welcome to your attention 【IT bond 】
️️️ Thank you, big and small !️️️

Preface

This paper deals with PostgreSQL The architecture of , I hope that's helpful

️ 1. Physical structure

 Insert picture description here
 Insert picture description here

1.1 Directory description

postgresql.conf: Parameter file
pg_hba.conf: Black and white list
PG_VERSION:PG Large version number file
postgresql.auto.conf:alter system Set the configuration parameters
postmaster.pid: Database process 、 root directory 、 Port number and other information
global: Data dictionary information file
pg_wal: Online log directory
pg_log: Alarm log

1.2 Alarm file (pg_log)

effect : The running log of the database is recorded , Alarm log , Error log
Off by default , If you want to configure, you need to postgresql.conf Middle configuration

## Parameter file configuration
logging_collector = on
log_directory = ‘pg_log’
log_filename = ‘postgresql-%a.log’
log_truncate_on_rotation = on
## Modify online log format
postgres=# alter system set log_filename = ‘postgresql-%Y-%m-%d_%H%M%S.log’;
notes : Need to restart the database
pg_ctl stop
pg_ctl start
postgres=# select name from pg_settings where name
in (‘log_filename’,‘log_directory’,‘logging_collector’);

 Insert picture description here

1.3 Online log (pg_wal)

stay $PGDATA/pg_wal, A single file is 16M, Internal unreadable , Unable to close , During physical backup , To back up this file

## The way of cutting logs 
postgres=# select pg_switch_wal();
 pg_switch_wal 
---------------
 0/15679F0
(1 row)

postgres=# show archive_timeout;
jmedb=# select * from pg_ls_waldir();
 Position in :cd $PGDATA/pg_wal

 Insert picture description here

1.4 Transaction commit log (pg_xact)

Transaction commit log , Record Metadata ; Directory in $PGDATA/pg_xact

1.5 Control documents

/postgresql/pgdata/global/pg_control
View control file information
[[email protected] ~]$ pg_controldata

 Insert picture description here

️ 2. Memory structure

2.1 classification

Local memory area (Local mermory area): Each back-end process is allocated for its own use ( Customer service )
Shared memory area (Shared mermory area): All processes on the server use

 Insert picture description here

2.2 Shared memory

The shared memory area consists of PostgreSQL The server allocates at startup . This area is also divided into several sub areas of fixed size .

 Insert picture description here

a.shared buffer pool
The data of the disk is loaded into this memory , Operate them directly , Reduce the disk of IO
Fast access to data
Many users can access shared memory
Solve the problem of frequent access to disk
b.WAL buffer
Changing data blocks are cached in this area , Later, the database writes online logs , It ensures that the data will not be lost due to server failure
c.CommitLog
Save the state of all transactions , Later used for concurrency control
Submission state :committed; Status not submitted :in_progress

2.2 Local memory

 Insert picture description here

work_mem: Sort table , Or table connection (hash join/merge join)
temp_buffers: Store temporary tables , Users can access the buffered data in this area
maintenance_work_mem: Do some maintenance work related to the table ( Rebuild index 、 Add foreign keys 、 Collect statistics )
Need to use this memory

️ 3.PG Learning Guide

 Insert picture description here

1. Recommended reading 《PostgreSQL The nine story pagoda of learning 》:
https://mp.weixin.qq.com/s/i7b6FvY3PYC2JENCgiVxjQ
2. Can learn and read independently PG Basic documents of application management ,
This part is mainly about China PG Branch training certification PGCA Excerpts from the course ,
Related links :http://www.postgresqlchina.com/tecdoc
3.PG The main site of learning
PG The international community :https://www.postgresql.org/

1)PG Summary :https://www.postgresql.org/about/
2)PG Online help documentation ( English version , many PG edition ):
https://www.postgresql.org/docs/
3) Can also pass PG Consult and learn Chinese manuals , Access address :
http://www.postgres.cn/docs/10/;
http://www.postgres.cn/docs/11/
4) Installation media download address :
https://www.postgresql.org/download/
There are mainly binary 、 There are two ways to compile and install the source code , Binary installation media correspond to different operating systems .
There is also an exception based on PG Installation of product release version ,
The installation media and installation methods can be obtained through the company's official website of the product ,
For example, Ali POLARDB、 Yaxin ANTDB、 tencent TBase、 Huawei GaussDB、 Hangao HGDB etc. .
5) Online learning resources
https://www.postgresql.org/docs/online-resources/
Contains rich tutorials 、 Hands on practice resources

原网站

版权声明
本文为[It bond]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202211734002928.html