当前位置:网站首页>postgresql 之 数据目录内部结构 简介
postgresql 之 数据目录内部结构 简介
2022-07-06 18:39:00 【happytree001】
一、一切皆为Oid
在Linux中一切皆为文件,在postgresql中一切皆为Oid。
1.1 什么是Oid
Object identifier(Oid), 对象标识符。 在postgresql内部,所有的数据库对象都是通过相应的Oid进行管理。
typedef unsigned int Oid;
Oid在代码中是一个4字节的无符号的整数。
1.2 数据库Oid
[email protected]:~$ /usr/local/pgsql/bin/psql
psql (14.2)
Type "help" for help.
postgres=# select datname,oid from pg_database where datname='test';
datname | oid
---------+-------
test | 16384
(1 row)
postgres=#
[email protected]:~$ ls /usr/local/pgsql/data/base/ -l
total 24
drwx------ 2 postgres postgres 4096 Jun 6 14:38 1
drwx------ 2 postgres postgres 4096 Jun 6 14:38 12971
drwx------ 2 postgres postgres 4096 Jul 4 12:50 12972
drwx------ 2 postgres postgres 4096 Jun 7 12:19 16384
drwx------ 2 postgres postgres 4096 Jun 11 02:01 24577
drwx------ 2 postgres postgres 4096 Jul 4 12:50 40960
1.3 表Oid
[email protected]:~$ /usr/local/pgsql/bin/psql test
psql (14.2)
Type "help" for help.
test=# create table stu (name varchar(32), age int, sex char(2));
CREATE TABLE
test=# \dS+ stu
Table "public.stu"
Column | Type | Collation | Nullable | Default | Storage | Compression | Stats target | Description
--------+-----------------------+-----------+----------+---------+----------+-------------+--------------+-------------
name | character varying(32) | | | | extended | | |
age | integer | | | | plain | | |
sex | character(2) | | | | extended | | |
Access method: heap
test=# select oid,relname from pg_class where relname = 'stu';
oid | relname
-------+---------
49152 | stu
(1 row)
test=#
[email protected]:~$ ls /usr/local/pgsql/data/base/16384/49152 -hal
-rw------- 1 postgres postgres 0 Jul 4 12:57 /usr/local/pgsql/data/base/16384/49152
二、和MySQL对比
| 数据库 | 数据库存储 | 表存储 | 编码影响 |
|---|---|---|---|
| postgresql | 目录名为对应的Oid(数字) | 文件名为对应的Oid (数字) | 只是一个数值,不受影响 |
| mysql | 目录名为数据库名(字符串) | 文件名为表名 (字符串) | 受影响 |
postgresql和mysql都是将数据库作为目录,对应的表则在对应的目录下,方便查找以及管理。
三、 数据目录结构
[email protected]:/# tree /usr/local/pgsql/data/ -L 1
/usr/local/pgsql/data/
|-- PG_VERSION
|-- base
|-- global
|-- pg_commit_ts
|-- pg_dynshmem
|-- pg_hba.conf
|-- pg_ident.conf
|-- pg_logical
|-- pg_multixact
|-- pg_notify
|-- pg_replslot
|-- pg_serial
|-- pg_snapshots
|-- pg_stat
|-- pg_stat_tmp
|-- pg_subtrans
|-- pg_tblspc
|-- pg_twophase
|-- pg_wal
|-- pg_xact
|-- postgresql.auto.conf
|-- postgresql.conf
|-- postmaster.opts
`-- postmaster.pid
17 directories, 7 files
| 名称 | 描述 |
|---|---|
| PG_VERSION | pg服务器主版本号文件 |
| base/ | 数据库目录都在此目录下 |
| global/ | 数据库集簇范围的表(比如pg_database, 类似mysql的performance_schema) |
| pg_commit_ts/ | 事物提交的时间戳数据 |
| pg_dynshmem/ | 动态共享内存子系统中使用的文件 |
| pg_hba.conf | 控制pg客户端认证配置的文件 |
| pg_ident.conf | pg用户映射文件 |
| pg_logical/ | 逻辑解码的状态数据 |
| pg_multixact/ | 多事务状态数据 |
| pg_notify/ | Listen/Notify状态数据 |
| pg_replslot/ | 复制槽数据 |
| pg_serial/ | 已提交的可串行化事务相关信息 |
| pg_snapshots/ | 快照信息 |
| pg_stat/ | 统计子系统的永久文件 |
| pg_stat_tmp/ | 统计子系统的临时文件 |
| pg_subtrans/ | 子事务状态数据 |
| pg_tblspc/ | 指向表空间的符号链接 |
| pg_twophase/ | 两阶段事务的状态文件 |
| pg_wal/ | WAL文件 |
| pg_xact/ | 事务提交状态数据 |
| postgresql.auto.conf | 存储使用alter system修改的配置 |
| postgresql.conf | 配置文件 |
| postmaster.opts | 记录服务器上一次启动的命令行选项 |
| postmaster.pid | 服务器pid文件 |
边栏推荐
- BigDecimal 的正确使用方式
- Stm32f4 --- PWM output
- Tiflash source code reading (IV) design and implementation analysis of tiflash DDL module
- Web开发小妙招:巧用ThreadLocal规避层层传值
- Jacob Steinhardt, assistant professor of UC Berkeley, predicts AI benchmark performance: AI has made faster progress in fields such as mathematics than expected, but the progress of robustness benchma
- @Before, @after, @around, @afterreturning execution sequence
- 3D激光SLAM:Livox激光雷达硬件时间同步
- argo workflows源码解析
- 强化学习如何用于医学影像?埃默里大学最新《强化学习医学影像分析》综述,阐述最新RL医学影像分析概念、应用、挑战与未来方向
- 建议收藏!!Flutter状态管理插件哪家强?请看岛上码农的排行榜!
猜你喜欢

How did partydao turn a tweet into a $200million product Dao in one year

建议收藏!!Flutter状态管理插件哪家强?请看岛上码农的排行榜!

BigDecimal 的正确使用方式

解密函数计算异步任务能力之「任务的状态及生命周期管理」

The last line of defense of cloud primary mixing department: node waterline design

Ros Learning (23) Action Communication Mechanism

centos8安装mysql报错:The GPG keys listed for the “MySQL 8.0 Community Server“ repository are already ins

机器人队伍学习方法,实现8.8倍的人力回报

Zhang Ping'an: accelerate cloud digital innovation and jointly build an industrial smart ecosystem

Errors made in the development of merging the quantity of data in the set according to attributes
随机推荐
[server data recovery] data recovery case of a Dell server crash caused by raid damage
阿里云中间件开源往事
传感器:DS1302时钟芯片及驱动代码
Schedulx v1.4.0 and SaaS versions are released, and you can experience the advanced functions of cost reduction and efficiency increase for free!
Chang'an chain learning notes - certificate model of certificate research
纽约大学 CITIES 研究中心招聘理学硕士和博士后
Unicode string converted to Chinese character decodeunicode utils (tool class II)
张平安:加快云上数字创新,共建产业智慧生态
centos8安裝mysql報錯:The GPG keys listed for the “MySQL 8.0 Community Server“ repository are already ins
FLIR blackfly s industrial camera: synchronous shooting of multiple cameras through external trigger
The empirical asset pricing package (EAP) can be installed through pypi
机器人队伍学习方法,实现8.8倍的人力回报
Big guys gather | nextarch foundation cloud development meetup is coming!
UC伯克利助理教授Jacob Steinhardt预测AI基准性能:AI在数学等领域的进展比预想要快,但鲁棒性基准性能进展较慢
TiFlash 源码阅读(四)TiFlash DDL 模块设计及实现分析
开发中对集合里面的数据根据属性进行合并数量时犯的错误
Time synchronization of livox lidar hardware -- PPS method
解密函数计算异步任务能力之「任务的状态及生命周期管理」
SchedulX V1.4.0及SaaS版发布,免费体验降本增效高级功能!
微服务架构介绍