当前位置:网站首页>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文件 |
边栏推荐
- Flir Blackfly S 工业相机:自动曝光配置及代码
- ROS learning (26) dynamic parameter configuration
- Lidar: introduction and usage of ouster OS
- Collection recommandée!! Quel plug - in de gestion d'état flutter est le plus fort? Regardez le classement des manons de l'île, s'il vous plaît!
- 红外相机:巨哥红外MAG32产品介绍
- Flir Blackfly S工业相机:颜色校正讲解及配置与代码设置方法
- 【论文阅读|深读】 GraphSAGE:Inductive Representation Learning on Large Graphs
- go swagger使用
- The foreground downloads network pictures without background processing
- 新一代云原生消息队列(一)
猜你喜欢

Centos8 install MySQL 8.0 using yum x

传感器:土壤湿度传感器(XH-M214)介绍及stm32驱动代码

CISP-PTE之命令注入篇

ROS learning (26) dynamic parameter configuration

企业中台建设新路径——低代码平台

ROS学习(十九)机器人SLAM功能包——cartographer

Integrated navigation: product description and interface description of zhonghaida inav2

【论文阅读|深读】ANRL: Attributed Network Representation Learning via Deep Neural Networks

Analyze "C language" [advanced] paid knowledge [II]

Lidar: introduction and usage of ouster OS
随机推荐
The mega version model of dall-e MINI has been released and is open for download
Decryption function calculates "task state and lifecycle management" of asynchronous task capability
Several classes and functions that must be clarified when using Ceres to slam
TiFlash 源码阅读(四)TiFlash DDL 模块设计及实现分析
Tiflash source code reading (IV) design and implementation analysis of tiflash DDL module
Ros Learning (23) Action Communication Mechanism
张平安:加快云上数字创新,共建产业智慧生态
张平安:加快云上数字创新,共建产业智慧生态
Recognition of C language array
ROS learning (25) rviz plugin
解密函数计算异步任务能力之「任务的状态及生命周期管理」
Introduction to FLIR blackfly s industrial camera
[unity] upgraded version · Excel data analysis, automatically create corresponding C classes, automatically create scriptableobject generation classes, and automatically serialize asset files
The foreground downloads network pictures without background processing
Lumion 11.0软件安装包下载及安装教程
CISP-PTE实操练习讲解(二)
猿桌派第三季开播在即,打开出海浪潮下的开发者新视野
The use of video in the wiper component causes full screen dislocation
The boss is quarantined
Flir Blackfly S工业相机:颜色校正讲解及配置与代码设置方法