网站首页 > 文章精选 正文
上一篇我们学习了PG的安装配置启动.这一篇学习理解PG的物理体系及逻辑体系还有权限体系.
1 PG的物理体系介绍
进入数据目录
[root@slowquery data]# pwd
/pgsql/data
查看PG数据目录下边的文件
[root@slowquery data]# ll
总用量 64
drwx------. 6 postgres postgres 54 7月 1 19:52 base
-rw-------. 1 postgres postgres 30 7月 1 00:00 current_logfiles
drwx------. 2 postgres postgres 4096 6月 30 20:21 global
drwx------. 2 postgres postgres 58 7月 1 00:00 log
drwx------. 2 postgres postgres 6 6月 30 20:08 pg_commit_ts
drwx------. 2 postgres postgres 6 6月 30 20:08 pg_dynshmem
-rw-------. 1 postgres postgres 4792 6月 30 20:20 pg_hba.conf
-rw-------. 1 postgres postgres 1636 6月 30 20:08 pg_ident.conf
drwx------. 4 postgres postgres 68 7月 1 19:57 pg_logical
drwx------. 4 postgres postgres 36 6月 30 20:08 pg_multixact
drwx------. 2 postgres postgres 18 6月 30 20:20 pg_notify
drwx------. 2 postgres postgres 6 6月 30 20:08 pg_replslot
drwx------. 2 postgres postgres 6 6月 30 20:08 pg_serial
drwx------. 2 postgres postgres 6 6月 30 20:08 pg_snapshots
drwx------. 2 postgres postgres 6 6月 30 20:20 pg_stat
drwx------. 2 postgres postgres 63 7月 1 19:59 pg_stat_tmp
drwx------. 2 postgres postgres 18 6月 30 20:08 pg_subtrans
drwx------. 2 postgres postgres 6 6月 30 20:08 pg_tblspc
drwx------. 2 postgres postgres 6 6月 30 20:08 pg_twophase
-rw-------. 1 postgres postgres 3 6月 30 20:08 PG_VERSION
drwx------. 3 postgres postgres 60 6月 30 20:08 pg_wal
drwx------. 2 postgres postgres 18 6月 30 20:08 pg_xact
-rw-------. 1 postgres postgres 88 6月 30 20:08 postgresql.auto.conf
-rw-------. 1 postgres postgres 26664 6月 30 20:18 postgresql.conf
-rw-------. 1 postgres postgres 47 6月 30 20:20 postmaster.opts
-rw-------. 1 postgres postgres 85 6月 30 20:20 postmaster.pid
主要文件理解:
drwx------. 6 postgres postgres 54 7月 1 19:52 base
base目录下边是什么呢?就是存放表数据的
我们现查看当前目录下边的内容
[root@slowquery data]# ll base/
总用量 48
drwx------. 2 postgres postgres 8192 6月 30 20:08 1
drwx------. 2 postgres postgres 8192 6月 30 20:08 14186
drwx------. 2 postgres postgres 8192 6月 30 20:21 14187
drwx------. 2 postgres postgres 8192 7月 1 19:52 16387
我们在数据库内创建一张表,然后查看表在数据库目录中的位置
postgres=# CREATE TABLE test (
postgres(# did integer PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY,
postgres(# name varchar(40) NOT NULL CHECK (name <> '')
postgres(# );
CREATE TABLE
postgres=# select pg_relation_filepath('test') ;
pg_relation_filepath
----------------------
base/14187/16390
同时由此我们可以看到PG的物理结构是:表空间--database--table 这么一个结构 对应到目录就是
base 14187(database) 16390(table)
其他文件解释:
-rw-------. 1 postgres postgres 30 7月 1 00:00 current_logfiles 当前使用的日志
drwx------. 2 postgres postgres 4096 6月 30 20:21 global 系统元数据信息
drwx------. 2 postgres postgres 58 7月 1 00:00 log 日志目录
drwx------. 2 postgres postgres 6 6月 30 20:08 pg_commit_ts 包含事务提交时间戳数据的子目录
-rw-------. 1 postgres postgres 4792 6月 30 20:20 pg_hba.conf 实例防火墙配置文件
drwx------. 3 postgres postgres 60 6月 30 20:08 pg_wal redolog目录
-rw-------. 1 postgres postgres 88 6月 30 20:08 postgresql.auto.conf 动态参数修改保存的文件(优先级高于配置文件)
-rw-------. 1 postgres postgres 26664 6月 30 20:18 postgresql.conf pg配置文件
2 PG的逻辑结构
PG的逻辑架构理解:
PG和其他关系型数据库不一样.比如MySQL MySQL就是实例---库--表
PG是实例---库---模式--表
PG的一个实例中可以有多个database 客户端连接的时候需要指定database
MySQL则不需要
PG的模式是介于database和table之间的一个逻辑分割
在PG中一个database可以有多个schema 默认情况下每个database下边都有一个public模式
postgres=# create database test;
CREATE DATABASE
postgres=# \c test
您现在已经连接到数据库 "test",用户 "postgres".
test=# \dn
架构模式列表
名称 | 拥有者
--------+----------
public | postgres
(1 行记录)
用户可以创建模式
test=# create schema test;
CREATE SCHEMA
查看test下的所有模式
test=# \dn
架构模式列表
名称 | 拥有者
--------+----------
lzm | postgres
public | postgres
test | postgres
(3 行记录)
在一个database下的不同模式中可以创建相同名字的表
test=# create table test.tt(id int8);
CREATE TABLE
test=# create table lzm.tt(id int8);
CREATE TABLE
查看对应的table时候需要加上database和模式名
test=# \dt test.lzm.tt;
关联列表
架构模式 | 名称 | 类型 | 拥有者
----------+------+--------+----------
lzm | tt | 数据表 | postgres
删除模式
test=# drop schema test cascade ;
注意: 递归删除 表 test.tt
DROP SCHEMA
PG的逻辑是一个多进程的.主要由一个postmaster监听其他进程工作
postmaster 所有数据库的进程的主进程(负责监听和fork子进程)
startup 主要用于数据库恢复的进程
syslogger 记录系统日志
pgstat 收集统计信息
pgarch 如果开启了归档那么postmaster就会fork一个归档进程
checkpointer 负责检查点的进程
bgwriter 负责把shared buffer中的脏数据写入磁盘的进程
autovacuum worker 负责回收垃圾数据的worker进程,是lanucher进程fork出来的
autovacuum lanucher 负责回收垃圾数据的进程,如果开启了autovacuum的话,那么postmaster会fork这个进程
bgworker 分为很多种worker,例如logical replication worker launcher.parallerl worker.replication worker等
wal sender 逻辑复制 流式物理复制的wal发送进程
wal receiver 逻辑复制 流式物理复制的wal 接收进程
work process 工作进程,东台fork 例如并行计算的进程
- 上一篇: 10分钟教你写一个数据库(数据库如何造数据)
- 下一篇: 数据库备份工具——mysqldump详解
猜你喜欢
- 2025-05-07 自定义代码生成器(上)(自动代码生成器下载)
- 2025-05-07 MySQL中的存储过程和函数(mysql存储过程与函数)
- 2025-05-07 Instagram架构的分片和ID的设计(ins的分类)
- 2025-05-07 对PostgreSQL中权限的理解(初学者必读)
- 2025-05-07 一文看懂MySQL如何判断InnoDB表是独立表空间还是共享表空间
- 2025-05-07 ArcGIS Pro遥感影像的监督分类(arcgis遥感影像处理教程)
- 2025-05-07 MySQL学到什么程度?才有可以在简历上写精通
- 2025-05-07 大数据时代:Apache Phoenix 的优雅操作实践
- 2025-05-07 go语言database/sql标准库(go语言gui库)
- 2025-05-07 centos7系统下postgresql15离线安装,卸载
- 最近发表
- 标签列表
-
- newcoder (56)
- 字符串的长度是指 (45)
- drawcontours()参数说明 (60)
- unsignedshortint (59)
- postman并发请求 (47)
- python列表删除 (50)
- 左程云什么水平 (56)
- 编程题 (64)
- postgresql默认端口 (66)
- 数据库的概念模型独立于 (48)
- 产生系统死锁的原因可能是由于 (51)
- 数据库中只存放视图的 (62)
- 在vi中退出不保存的命令是 (53)
- 哪个命令可以将普通用户转换成超级用户 (49)
- noscript标签的作用 (48)
- 联合利华网申 (49)
- swagger和postman (46)
- 结构化程序设计主要强调 (53)
- 172.1 (57)
- apipostwebsocket (47)
- 唯品会后台 (61)
- 简历助手 (56)
- offshow (61)
- mysql数据库面试题 (57)
- fmt.println (52)