Postgresql數(shù)據(jù)庫(kù)集蔟的數(shù)據(jù)目錄
文件 | 用途 |
---|---|
手工配置文件 | |
postgresql.conf | 參數(shù)文件 |
pg_hba.conf | 客戶端認(rèn)證控制文件(host-based access control ) |
pg_ident.conf | 用來(lái)配置哪些操作系統(tǒng)用戶可以映射為哪個(gè)數(shù)據(jù)庫(kù)用戶轧钓。 |
自動(dòng)配置文件 | |
postgresql.auto.conf | 參數(shù)文件光酣,只保存alter system 命令修改的參數(shù) |
postmaster.opts | 記錄服務(wù)器最后一次啟動(dòng)時(shí)使用的命令行參數(shù) |
postmaster.pid | 記錄進(jìn)程的信息 |
pg_version | pg數(shù)據(jù)庫(kù)主版本號(hào)文件 |
目錄 | 用途 |
---|---|
base | 每個(gè)數(shù)據(jù)庫(kù)對(duì)于的子目錄的子目錄 |
global | 包含集簇范圍的表的文件和全局控制信息等抹镊。 |
pg_commit_ts | 包含事務(wù)提交時(shí)間戳數(shù)據(jù)的子目錄 |
pg_dynshmem | 包含被動(dòng)態(tài)共享內(nèi)存子系統(tǒng)所使用文件的子目錄 |
pg_logical | 包含用于邏輯復(fù)制的狀態(tài)數(shù)據(jù)的子目錄 |
pg_multixact | 包含多事務(wù)狀態(tài)數(shù)據(jù)的子目錄(用戶共享的行鎖) |
pg_notify | 包含LISTEN/NOTIFY狀態(tài)數(shù)據(jù)的子目錄 |
pg_repslot | 包含復(fù)制槽數(shù)據(jù)的子目錄 |
pg_serial | 包含已提交的可序列化事務(wù)信息的子目錄 |
pg_snapshots | 包含到處的快照的子目錄 |
pg_stat | 包含用于統(tǒng)計(jì)子系統(tǒng)的永久文件的子目錄 |
pg_stat_tmp | 包含用于統(tǒng)計(jì)信息子系統(tǒng)臨時(shí)文件的子目錄 |
pg_subtrans | 包含子事務(wù)狀態(tài)數(shù)據(jù)的子目錄 |
pg_tblspc | 包含指向表空間的符號(hào)鏈接的子目錄 |
pg_twophase | 用于預(yù)備事務(wù)狀態(tài)文件的子目錄 |
pg_wal | 保存預(yù)寫(xiě)日志 |
pg_xact | 包含事務(wù)提交狀態(tài)數(shù)據(jù)的子目錄, 記錄事務(wù)提交狀態(tài)數(shù)據(jù) |
文件說(shuō)明
pg_ident.conf - 用戶映射配置文件
當(dāng)pg_hba.conf
使用ident認(rèn)證方式時(shí)知给,需要建立映射用戶或具備同名用戶辈灼。
ident是Linux下PostgreSQL默認(rèn)的local認(rèn)證方式帽蝶,
凡是能正確登錄服務(wù)器的操作系統(tǒng)用戶(注:不是數(shù)據(jù)庫(kù)用戶)就能使用本用戶映射的數(shù)據(jù)庫(kù)用戶不需密碼登錄數(shù)據(jù)庫(kù)则拷。
pg_ident.conf就是用來(lái)配置哪些操作系統(tǒng)用戶映射為哪些數(shù)據(jù)庫(kù)用戶的。
如果某操作系統(tǒng)用戶在本文件中沒(méi)有映射用戶甩牺,則默認(rèn)的映射數(shù)據(jù)庫(kù)用戶與操作系統(tǒng)用戶同名蘑志。
pg_hba.conf
的格式如下:
# MAPNAME SYSTEM-USERNAME PG-USERNAME
usermap username dbuser
-
usermap
為映射名,要在pg_hba.conf中用到,多個(gè)映射可以共用同一個(gè)映射名急但, -
username
為操作系統(tǒng)用戶名澎媒, -
dbuser
為映射到的數(shù)據(jù)庫(kù)用戶。
pg_hba.conf如下:
# TYPE DATABASE USER CIDR-ADDRESS METHOD
local all all ident map=mapzy
map
是pg_hba.conf
的auth-options
選項(xiàng)波桩,map=mapzy
指示該認(rèn)證條件使用mapzy
映射戒努。
指定映射后原本的同名操作系統(tǒng)用戶就不能連接數(shù)據(jù)庫(kù)了。
postgresql.auto.conf
postgresql.auto.conf
的優(yōu)先級(jí)高于postgresql.conf
镐躲,
如果一個(gè)參數(shù)同時(shí)存在postgresql.auto.conf
和postgresql.conf
里面储玫,系統(tǒng)會(huì)先讀postgresql.auto.conf
的參數(shù)配置。
使用alter system set
修改的是postgresql.auto.conf
文件的內(nèi)容萤皂,postgresql.conf
則是通過(guò)文本編輯方式修改撒穷。
比如執(zhí)行alter system set max_wal_size=default
將參數(shù)設(shè)回 default
時(shí),postgresql.auto.conf
文件里的max_wal_size
這項(xiàng)配置會(huì)被刪除裆熙,重新用回postgresql.conf
文件的設(shè)置端礼。
postgresql.conf
postgresql.conf
文件內(nèi)容太多, 詳細(xì)內(nèi)容另開(kāi)一篇文件來(lái)講。
postgresql.conf
文件的參數(shù)后面有# (change requires restart)入录,表示必須重啟才能生效蛤奥,使用select pg_reload_conf()
或pg_ctl reload
不行。
GUC - Grand Unified Configuration
直接理解為配置參數(shù)
或者GUC變量
就可以了, 大部分參數(shù)都可以在不同級(jí)別里設(shè)置, 低級(jí)別的優(yōu)先生效僚稿。
postmaster.pid
postgres@f91183551f40:~/data$ cat postmaster.pid
1 # 主進(jìn)程的PID凡桥。
/var/lib/postgresql/data # 數(shù)據(jù)目錄
1613284289
5432
/var/run/postgresql
*
5432001 0
ready
通過(guò)ipcs命令查看共享內(nèi)存的地址信息
可以看到shared memory segments中的key是0x0052e2c1
0x0052e2c1十六進(jìn)制轉(zhuǎn)換為十進(jìn)制為5432001,正好等于第一個(gè)數(shù)字蚀同,即為共享內(nèi)存的key缅刽。
第二個(gè)數(shù)字為shmid的值,即為共享內(nèi)存的id唤崭。
postmaster.opts
postgres@f91183551f40:~/data$ cat postmaster.opts
/usr/lib/postgresql/12/bin/postgres
可以看出來(lái)拷恨,這個(gè)是啟動(dòng)命令脖律。
global目錄
存儲(chǔ)全局的系統(tǒng)表信息和全局控制信息谢肾。
- pg_control
用于存儲(chǔ)全局控制信息 - pg_filenode.map
用于將當(dāng)前目錄下系統(tǒng)表的OID與具體文件名進(jìn)行硬編碼映射(每個(gè)用戶創(chuàng)建的數(shù)據(jù)庫(kù)目錄下也有同名文件)。 - pg_internal.init
用于緩存系統(tǒng)表小泉,加快系統(tǒng)表讀取速度(每個(gè)用戶創(chuàng)建的數(shù)據(jù)庫(kù)目錄下也有同名文件)芦疏。 - 全局系統(tǒng)表文件
數(shù)字命名的文件,用于存儲(chǔ)系統(tǒng)表的內(nèi)容微姊。
它們?cè)趐g_class里的relfilenode都為0酸茴,是靠pg_filenode.map將OID與文件硬編碼映射。
(注:不是所有的系統(tǒng)表的relfilenode都為0)
data
├── global # under global, all the filenode is hard-code(pg_class.oid)
│ ├── 1136 # pg_pltemplate
│ ├── 1137 # pg_pltemplate_name_index
│ ├── 1213 # pg_tablespace
│ ├── 1214 # pg_shdepend
│ ├── 1232 # pg_shdepend_depender_index
│ ├── 1233 # pg_shdepend_reference_index
│ ├── 1260 # pg_authid
│ ├── 1261 # pg_auth_members
│ ├── 1262 # pg_database
│ ├── 2396 # pg_shdescription
│ ├── 2397 # pg_shdescription_o_c_index
│ ├── 2671 # pg_database_datname_index
│ ├── 2672 # pg_database_oid_index
│ ├── 2676 # pg_authid_rolname_index
│ ├── 2677 # pg_authid_oid_index
│ ├── 2694 # pg_auth_members_role_member_index
│ ├── 2695 # pg_auth_members_member_role_index
│ ├── 2697 # pg_tablespace_oid_index
│ ├── 2698 # pg_tablespace_spcname_index
│ ├── 2846 # pg_toast_2396
│ ├── 2847 # pg_toast_2396_index
│ ├── 2964 # pg_db_role_setting
│ ├── 2965 # pg_db_role_setting_databaseid_rol_index
│ ├── 2966 # pg_toast_2964
│ ├── 2967 # pg_toast_2964_index
│ ├── 3592 # pg_shseclabel
│ ├── 3593 # pg_shseclabel_object_index
│ ├── 4060 # pg_toast_3592x
│ ├── 4061 # pg_toast_3592_index
│ ├── 6000 # pg_replication_origin
│ ├── 6001 # pg_replication_origin_roiident_index
│ ├── 6002 # pg_replication_origin_roname_index
│ ├── pg_control # global control file, use pgcheck -pc to see it.
│ ├── pg_filenode.map # system table (oid -> filenode) mapping file, use pgcheck -pm to see it.
│ └── pg_internal.init # system table cache file, use pgcheck -pr to see it.
用以下語(yǔ)句可以查詢OID對(duì)應(yīng)的表名/物理文件名
select oid, relname from pg_class where relfilenode=0 order by oid;
select pg_relation_filenode(:oid);
pg_control
對(duì)應(yīng)的是ControlFileData
結(jié)構(gòu)體
pg_filenode.map - 數(shù)據(jù)庫(kù)(數(shù)據(jù)庫(kù)集蔟里的一個(gè)數(shù)據(jù)庫(kù))的系統(tǒng)表
對(duì)應(yīng)RelMapFile
結(jié)構(gòu)體, 結(jié)構(gòu)體大小為:62*8+4*4=496+16=512
兢交。也就是說(shuō)這個(gè)文件最多存放62條系統(tǒng)catalog表的記錄薪捍。
hexdump pg_filenode.map
系統(tǒng)表文件 - 數(shù)據(jù)庫(kù)集蔟的硬編碼的系統(tǒng)表
- 純數(shù)字的是
主表數(shù)據(jù)文件
或索引數(shù)據(jù)文件
。 - 以“_fsm”后綴的就是Free Space Mapping文件。
- 以”vm”后綴的就是visibility map酪穿。
base目錄
base # use to store database file(SELECT oid, datname FROM pg_database;)
├── 1 # template database
├── 12406 # template0 database
├── 12407 # postgres database
└── 16384 # 用`create database`創(chuàng)建的數(shù)據(jù)庫(kù)
│ ├── 3600
│ ├── 3600_fsm
│ ├── 3600_vm
│ ├── 16385
│ ├── pg_filenode.map #
│ ├── pg_internal.init #
│ └── PG_VERSION #
- pg_filenode.map 是pg_class里relfilenode為0的系統(tǒng)表凳干,OID與文件的硬編碼映射。
- pg_internal.init 是系統(tǒng)表的cache文件被济,用于加快讀取救赐。默認(rèn)不存在,查詢系統(tǒng)表后自動(dòng)產(chǎn)生只磷。
- PG_VERSION 是當(dāng)前數(shù)據(jù)庫(kù)數(shù)據(jù)格式對(duì)應(yīng)的版本號(hào)
- 其它文件是需要到pg_class里根據(jù)OID查到對(duì)應(yīng)的relfilenode來(lái)與文件名匹配的经磅。