首页 > 数据库 >PostgreSQL(四)存储结构

PostgreSQL(四)存储结构

时间:2023-01-27 15:03:37浏览次数:61  
标签:11 存储 PostgreSQL postgres oid base pg 结构


先上一张图:

PostgreSQL(四)存储结构_PostgreSQL

这是 PostgreSQL 的 DMS 管理方式,与 oracle 管理一样。

DMS(database management space)数据库管理空间,数据库中管理,容器是预分配的文件。

SMS(system management space)系统管理空间,操作系统管理,容器是操作系统文件空间中的目录。


查看当前数据库,可以把oid查询出来,oid标识每个对象的id。

testdb=# select oid, datname from pg_database order by oid;
oid | datname
-------+-----------
1 | template1
13211 | template0
13212 | postgres
16384 | demodb
16387 | testdb
(5 rows)


在数据库中,默认存储的位置为:/usr/local/pgsql/data/base

[root@hzc base]# pwd
/usr/local/pgsql/data/base
[root@hzc base]# ll
总用量 60
drwx------. 2 postgres postgres 8192 11月 7 11:23 1
drwx------. 2 postgres postgres 8192 11月 6 15:43 13211
drwx------. 2 postgres postgres 8192 11月 6 16:22 13212
drwx------. 2 postgres postgres 8192 11月 6 16:22 16384
drwx------. 2 postgres postgres 8192 11月 8 10:02 16387
[root@hzc base]#


可以看到,每个数据库对应的oid在操作系统中都一样,即数据库所在的存储位置。

同样,可以查询表的oid。

testdb=# select oid,relfilenode from pg_class where relname='weather';
oid | relfilenode
-------+-------------
16388 | 16388
(1 row)


对应的具体物理文件:

testdb=# select pg_relation_filepath('weather');
pg_relation_filepath
----------------------
base/16387/16388
(1 row)


当表数据存储大于 1GB 时,它将被划分到1个或多个GB大小的段(segment),如 filenode, filenode.1, filenode.2等。



其他:系统表,可查看系统相关信息

\dt pg_catalog.*



数据默认存储在8KB的数据页中,如果一行数据存储超过了8KB,PG会使用 TOAST(The Oversized-Attribute Storage Technique) 技术处理。但 TOAST 现在字段大小为1GB,如果太大,建议使用 ARRAY 或JSON 类型。 TOAST 参考:​https://www.postgresql.org/docs/current/static/storage-toast.html​

ctid 显示记录所在的数据页及位置:

testdb=# select ctid,* from weather;
ctid | city | temp_lo | temp_hi | prcp | date
-------+---------------+---------+---------+------+------------
(0,1) | San Francisco | 46 | 50 | 0.25 | 1994-11-27
(0,2) | Piter | 0 | 50 | 0.88 | 2016-02-22
(0,3) | San Abama | 50 | 22 | 0.02 | 2010-08-11
(3 rows)


【Free Space map】

每张表都有 free space map,它记录文件存储的可用空间情况。FSM 不是很准确,因为它以8KB来计算,并且不是实时更新的,它是由 VACUUM 更新的。在 MVCC 情况下,update 和 delete 后,旧的数据快照不会立即删除,VACUUM会释放空间以重用或还给操作系统。VACUUM 参考:​https://www.postgresql.org/docs/current/static/sql-vacuum.html​

查看表的可用空间:

SELECT * FROM pg_freespace('weather');


【Visibility map】

每张表都有一个 vm 用于跟踪哪个数据页可用于活动的事务,物理文件与表的存储位置相同,后缀为 "_vm"。vm 每个页存储 bit ,用于标识页中是否存在将被用于 VACUUM 的元祖。



Database Physical Storage:​​https://www.postgresql.org/docs/current/static/storage.html​​​
存储结构:​​http://rachbelaid.com/introduction-to-postgres-physical-storage/​
PostgreSQL数据库存储体系结构简介:​​https://searchdatabase.techtarget.com.cn/7-18253/​


标签:11,存储,PostgreSQL,postgres,oid,base,pg,结构
From: https://blog.51cto.com/hzc2012/6024100

相关文章

  • PostgreSQL(五)系统参数配置
    参数名称大小写不敏感,参数主要有5种类型:boolean,string,integer,floatingpoint,enumerated(enum). 配置文件路径:/usr/local/pgsql/data/postgresql.conf/usr/local/p......
  • 获取运行时类的完整结构
      ......
  • 树形结构学习笔记
    线段树引入假设有这样的问题:有\(n\)个数,\(m\)次操作,操作分为:修改某一个数或者查询一段区间的值。分析下,如果针对数组元素的修改可以是\(O(1)\)完成,求某个区间值需......
  • docker中使用postgresql数据库
    1.拉取默认最新运行容器由于最新版删减了东西,所以会报错参考感谢以下博主让我从爬出深坑~#拉取postgreshttps://www.hangge.com/blog/cache/detail_3073.html......
  • 「LOJ3673」简单数据结构
    题目点这里看题目。给定一个长度为\(n\)​的非负整数序列\(a\),有\(q\)次操作,每次操作类型为如下三种之一:给定\(v\),表示\(\forall1\lei\len\),令\(a_i\gets......
  • 数据结构
    二、数据结构1.单链表头插法建立链表,删除一个数,在指定位置插入一个数#include<iostream>usingnamespacestd;constintN=100010;inthead,e[N],ne[N],idx;//id......
  • 编写代码实现:求一个整数存储在内存中的二进制中1的个数
    目的:统计num的补码中有几个1法一#include<stdio.h>intmain(){intnum=0;intcount=0;scanf("%d",&num);//3--011//二进制:模2除2while(num)//因为二进制只有0和1,......
  • 如何在 Kubernetes 部署 PostgreSQL
    文章目录​​1.简介​​​​2.条件​​​​3.helm部署posgresql​​​​3.1添加Helm存储库​​​​3.2默认安装​​​​3.3选参安装​​​​3.4持久存储安装​​......
  • mysql存储过程和游标
    创建存储过程存储过程和定义函数相似,使用CREATEPROCEDURE 存储名(),BEGIN 和END之间为“函数体”。CREATETABLEBlog(authorVARCHAR(25),blogTEXT,......
  • MySQL高级【存储过程】
    1:存储过程1.1:介绍存储过程是事先经过编译并存储在数据库中的一段SQL语句的集合,调用存储过程可以简化应用开发人员的很多工作,减少数据在数据库和应用服务器之间的传输,对于......