Postgresql体系结构

Postgresql体系结构_第1张图片

client连接PostgreSQL过程:
1、客户端发起请求
2、主服务postmaster进程负责服务器是否接受客户端的host通信认证,服务器对客户端进行身份鉴别
3、主服务进程为该客户端单独fork一个客户端工作进程postgres
4、客户端与postgres进程建立通信连接,由postgres进程负责后续所有的客户端请求操作,直至客户端退出后

进程:
Postmaster进程是PG数据库的总控制进程,负责启动和关闭数据库实例,是第一个postgres进程。Postmaster的主进程,还会fork出一些辅助子进程。

BgWriter(后台写)进程
WaLWriter(预写式日志)进程
AutoVAcuum(系统自动清理)
SysLogger(系统日志)进程
PgArch(归档)进程
PgStat(统计数据收集)进程
CheckPoint(检查点)进程

内存:

共享内存区
shared_buffers —共享缓冲区,它表示数据缓冲区中的数据块的个数,每个数据块的大小是8KB。推荐值:1/4 主机物理内存

wal_buffers — 日志缓存区的大小 存放WAL数据的内存空间大小,系统默认值是64K

私有内存区

temp_buffers—临时缓冲区 用于存放数据库会话访问临时表数据,系统默认值为8M。
work_mem — 工作内存或者操作内存。其负责内部的sort和hash操作,合适的work_mem大小能够保证这些操作在内存中进行。
maintenance_work_mem —维护工作内存 主要是针对数据库的维护操作,主要针对VACUUM,CREATE INDEX,ALTER TABLE ADD FOREIGN KEY等操作。

PGDATA主要目录
drwx------ 6 postgres postgres 54 Mar 29 16:37 base
drwx------ 2 postgres postgres 4096 Mar 30 20:50 global
drwx------ 2 postgres postgres 6 Mar 26 11:26 pg_commit_ts
drwx------ 2 postgres postgres 6 Mar 26 11:26 pg_dynshmem
-rw------- 1 postgres postgres 4760 Mar 26 11:26 pg_hba.conf
-rw------- 1 postgres postgres 1636 Mar 26 11:26 pg_ident.conf
drwx------ 4 postgres postgres 68 Mar 31 16:13 pg_logical
drwx------ 4 postgres postgres 36 Mar 26 11:26 pg_multixact
drwx------ 2 postgres postgres 6 Mar 26 11:26 pg_notify
drwx------ 2 postgres postgres 6 Mar 26 11:26 pg_replslot
drwx------ 2 postgres postgres 6 Mar 26 11:26 pg_serial
drwx------ 2 postgres postgres 6 Mar 26 11:26 pg_snapshots
drwx------ 2 postgres postgres 6 Mar 29 14:29 pg_stat
drwx------ 2 postgres postgres 105 Apr 1 09:17 pg_stat_tmp
drwx------ 2 postgres postgres 18 Mar 26 11:26 pg_subtrans
drwx------ 2 postgres postgres 19 Mar 30 20:41 pg_tblspc
drwx------ 2 postgres postgres 6 Mar 26 11:26 pg_twophase
-rw------- 1 postgres postgres 3 Mar 26 11:26 PG_VERSION
drwx------ 3 postgres postgres 60 Mar 26 11:26 pg_wal
drwx------ 2 postgres postgres 18 Mar 26 11:26 pg_xact
-rw------- 1 postgres postgres 88 Mar 26 11:26 postgresql.auto.conf
-rw------- 1 postgres postgres 28011 Mar 26 11:26 postgresql.conf
-rw------- 1 postgres postgres 33 Mar 29 14:29 postmaster.opts
-rw------- 1 postgres postgres 91 Mar 29 14:29 postmaster.pid

ll base/
drwx------ 2 postgres postgres 8192 Mar 29 16:36 12723
drwx------ 2 postgres postgres 8192 Mar 29 16:37 16393

base:用于存放当前实例下所有的数据库,数字化命名的路径表示各个数据库,每个数字表示数据库的oid

oid2name 展示数据库对应的表空间信息
All databases:
Oid Database Name Tablespace

12723 postgres pg_default
16393 testdb pg_default

pg_commit_ts:事务提交时间戳信息;commit timestamp;
pg_dynshmem:共享内存使用的文件信息;dynamic shared memory;
pg_hba.conf:关于客户端如何访问数据库的配置文件 host based authentication;
pg_logical:数据库逻辑解码的状态数据;
pg_multixact:存放多事务状态数据,共享锁信息;multi transaction;
pg_notify:数据库配置订阅模式的LISTEN/NOTIFY状态数据;
pg_replslot:数据库复制槽信息;replication slot;
pg_serial:已提交的串行化事务信息;serializable;
pg_snapshots:导出的快照信息,内置pg_export_snapshot()函数导出;
pg_stat:统计子系统收集的统计信息;statistics;
pg_stat_tmp:统计子系统收集的临时统计信息;statistics temporary;
pg_subtrans:子事务的转态数据;sub-transactions;
pg_tblspc:表空间的映射,
pg_twophase:两阶段提交事务的状态信息;
PG_VERSION:存放数据库版本信息;
pg_wal:存放数据库的日志文件,类似于Oracle的redo log。write ahead log;
pg_xact:事务提交状态数据,用于控制事务的Multi Version Concurrent Contril;PostgreSQL事务有4种状态:IN_PROGRESS,COMMITED,ABORTED,SUB_COMMITTED;
postgresql.auto.conf:存放通过alter sytem命令修改的参数,
postgresql.conf:数据库配置的参数文件,类似于Oracle的参数文件spfile;
postmaster.opts:记录数据库启动时的选项,options;
postmaster.pid 主进程文件

逻辑结构
Postgresql体系结构_第2张图片
DataBase
tablespace
Schema
object

创建一个Database时,这个Database会创建一个名为public的默认Schema,每个Database可以有多个Schema,在这个数据库中创建其他数据库对象时,如果没有指定Schema,都会在public这个Schema中,Schema可以理解为一个数据库中的命名空间,在数据库中创建的所有对象都Schema中创建,一个用户可以从同一个客户端连接中访问不同的Schema,不同的Schema中可以有多个相同的名称的Table、Index、View、Sequence、Function等数据库对象。

你可能感兴趣的:(数据库,数据库)