博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
PostgreSQL建表动作分析
阅读量:6292 次
发布时间:2019-06-22

本文共 8423 字,大约阅读时间需要 28 分钟。

首先,建立表:

pgsql=# create table tab10(id integer);CREATE TABLEpgsql=# select 147525::regclass; regclass ---------- tab10(1 row)pgsql=#

查看此时的文件信息:

[pgsql@localhost 16384]$ pwd/home/pgsql/DemoDir/base/16384[pgsql@localhost 16384]$ ls -l 147525-rw------- 1 pgsql pgsql 0 Jul  4 13:45 147525[pgsql@localhost 16384]$

此时,文件刚刚建立好,还是一个空文件

同时,可以看到,因为建立了一个表,所以数据字典中有很多系统表被更新:

例如:pg_type。

这个确实有点超乎想象,因为我并未增加任何的新type。

 

pgsql=# select count(*) from pg_type; count -------   313(1 row)pgsql=# create table tab10(id integer);CREATE TABLEpgsql=# select count(*) from pg_type; count -------   315(1 row)

看看增加了什么:

pgsql=# \xExpanded display is on.pgsql=# select * from pg_type where typname='tab10';-[ RECORD 1 ]--+------------typname        | tab10typnamespace   | 2200typowner       | 10typlen         | -1typbyval       | ftyptype        | ctypcategory    | Ctypispreferred | ftypisdefined   | ttypdelim       | ,typrelid       | 188542typelem        | 0typarray       | 188543typinput       | record_intypoutput      | record_outtypreceive     | record_recvtypsend        | record_sendtypmodin       | -typmodout      | -typanalyze     | -typalign       | dtypstorage     | xtypnotnull     | ftypbasetype    | 0typtypmod      | -1typndims       | 0typcollation   | 0typdefaultbin  | typdefault     | pgsql=#
pgsql=# select * from pg_type where typname='_tab10';-[ RECORD 1 ]--+-----------typname        | _tab10typnamespace   | 2200typowner       | 10typlen         | -1typbyval       | ftyptype        | btypcategory    | Atypispreferred | ftypisdefined   | ttypdelim       | ,typrelid       | 0typelem        | 188544typarray       | 0typinput       | array_intypoutput      | array_outtypreceive     | array_recvtypsend        | array_sendtypmodin       | -typmodout      | -typanalyze     | -typalign       | dtypstorage     | xtypnotnull     | ftypbasetype    | 0typtypmod      | -1typndims       | 0typcollation   | 0typdefaultbin  | typdefault     | pgsql=#

创建一个表达式后,对其他的系统表的写入,也有很多

再看和pg_depend之间的关联:

pgsql=# drop table tab10;DROP TABLEpgsql=# pgsql=# SELECT classid::regclass AS "depender object class",    CASE classid        WHEN 'pg_class'::regclass THEN objid::regclass::text        WHEN 'pg_type'::regclass THEN objid::regtype::text        WHEN 'pg_proc'::regclass THEN objid::regprocedure::text        ELSE objid::text     END AS "depender object identity",    objsubid,    refclassid::regclass AS "referenced object class",    CASE refclassid        WHEN 'pg_class'::regclass THEN refobjid::regclass::text        WHEN 'pg_type'::regclass THEN refobjid::regtype::text        WHEN 'pg_proc'::regclass THEN refobjid::regprocedure::text        ELSE refobjid::text    END AS "referenced object identity",    refobjsubid,    CASE deptype        WHEN 'p' THEN 'pinned'        WHEN 'i' THEN 'internal'        WHEN 'a' THEN 'automatic'        WHEN 'n' THEN 'normal'    END AS "dependency type"FROM pg_catalog.pg_depend WHERE objid >= 16384 OR refobjid >= 16384;(No rows)pgsql=# pgsql=# create table tab10(id integer);CREATE TABLEpgsql=# SELECT classid::regclass AS "depender object class",    CASE classid        WHEN 'pg_class'::regclass THEN objid::regclass::text        WHEN 'pg_type'::regclass THEN objid::regtype::text        WHEN 'pg_proc'::regclass THEN objid::regprocedure::text        ELSE objid::text     END AS "depender object identity",    objsubid,    refclassid::regclass AS "referenced object class",    CASE refclassid        WHEN 'pg_class'::regclass THEN refobjid::regclass::text        WHEN 'pg_type'::regclass THEN refobjid::regtype::text        WHEN 'pg_proc'::regclass THEN refobjid::regprocedure::text        ELSE refobjid::text    END AS "referenced object identity",    refobjsubid,    CASE deptype        WHEN 'p' THEN 'pinned'        WHEN 'i' THEN 'internal'        WHEN 'a' THEN 'automatic'        WHEN 'n' THEN 'normal'    END AS "dependency type"FROM pg_catalog.pg_depend WHERE objid >= 16384 OR refobjid >= 16384;-[ RECORD 1 ]--------------+-------------depender object class      | pg_typedepender object identity   | tab10objsubid                   | 0referenced object class    | pg_classreferenced object identity | tab10refobjsubid                | 0dependency type            | internal-[ RECORD 2 ]--------------+-------------depender object class      | pg_typedepender object identity   | tab10[]objsubid                   | 0referenced object class    | pg_typereferenced object identity | tab10refobjsubid                | 0dependency type            | internal-[ RECORD 3 ]--------------+-------------depender object class      | pg_classdepender object identity   | tab10objsubid                   | 0referenced object class    | pg_namespacereferenced object identity | 2200refobjsubid                | 0dependency type            | normalpgsql=#

再看对pg_class的影响:

pgsql=# drop table tab10;DROP TABLEpgsql=# create table tab10(id integer);CREATE TABLEpgsql=# \xExpanded display is on.pgsql=# select * from pg_class where relname='tab10';-[ RECORD 1 ]--+-------relname        | tab10relnamespace   | 2200reltype        | 188562reloftype      | 0relowner       | 10relam          | 0relfilenode    | 188560reltablespace  | 0relpages       | 0reltuples      | 0reltoastrelid  | 0reltoastidxid  | 0relhasindex    | frelisshared    | frelpersistence | prelkind        | rrelnatts       | 1relchecks      | 0relhasoids     | frelhaspkey     | frelhasrules    | frelhastriggers | frelhassubclass | frelfrozenxid   | 2017relacl         | reloptions     | pgsql=#

 再看对 pg_attribute的影响,生成表之后:

pgsql=# select 188563::regclass; regclass ---------- tab10(1 row)pgsql=# \xExpanded display is on.pgsql=# select * from pg_attribute where attrelid = (select max(attrelid) from pg_attribute);-[ RECORD 1 ]-+---------attrelid      | 188563attname       | tableoidatttypid      | 26attstattarget | 0attlen        | 4attnum        | -7attndims      | 0attcacheoff   | -1atttypmod     | -1attbyval      | tattstorage    | pattalign      | iattnotnull    | tatthasdef     | fattisdropped  | fattislocal    | tattinhcount   | 0attcollation  | 0attacl        | attoptions    | -[ RECORD 2 ]-+---------attrelid      | 188563attname       | cmaxatttypid      | 29attstattarget | 0attlen        | 4attnum        | -6attndims      | 0attcacheoff   | -1atttypmod     | -1attbyval      | tattstorage    | pattalign      | iattnotnull    | tatthasdef     | fattisdropped  | fattislocal    | tattinhcount   | 0attcollation  | 0attacl        | attoptions    | -[ RECORD 3 ]-+---------attrelid      | 188563attname       | xmaxatttypid      | 28attstattarget | 0attlen        | 4attnum        | -5attndims      | 0attcacheoff   | -1atttypmod     | -1attbyval      | tattstorage    | pattalign      | iattnotnull    | tatthasdef     | fattisdropped  | fattislocal    | tattinhcount   | 0attcollation  | 0attacl        | attoptions    | -[ RECORD 4 ]-+---------attrelid      | 188563attname       | cminatttypid      | 29attstattarget | 0attlen        | 4attnum        | -4attndims      | 0attcacheoff   | -1atttypmod     | -1attbyval      | tattstorage    | pattalign      | iattnotnull    | tatthasdef     | fattisdropped  | fattislocal    | tattinhcount   | 0attcollation  | 0attacl        | attoptions    | -[ RECORD 5 ]-+---------attrelid      | 188563attname       | xminatttypid      | 28attstattarget | 0attlen        | 4attnum        | -3attndims      | 0attcacheoff   | -1atttypmod     | -1attbyval      | tattstorage    | pattalign      | iattnotnull    | tatthasdef     | fattisdropped  | fattislocal    | tattinhcount   | 0attcollation  | 0attacl        | attoptions    | -[ RECORD 6 ]-+---------attrelid      | 188563attname       | ctidatttypid      | 27attstattarget | 0attlen        | 6attnum        | -1attndims      | 0attcacheoff   | -1atttypmod     | -1attbyval      | fattstorage    | pattalign      | sattnotnull    | tatthasdef     | fattisdropped  | fattislocal    | tattinhcount   | 0attcollation  | 0attacl        | attoptions    | -[ RECORD 7 ]-+---------attrelid      | 188563attname       | idatttypid      | 23attstattarget | -1attlen        | 4attnum        | 1attndims      | 0attcacheoff   | -1atttypmod     | -1attbyval      | tattstorage    | pattalign      | iattnotnull    | fatthasdef     | fattisdropped  | fattislocal    | tattinhcount   | 0attcollation  | 0attacl        | attoptions    | pgsql=#

基本就是这些了。

本文转自健哥的数据花园博客园博客,原文链接:http://www.cnblogs.com/gaojian/p/3171433.html,如需转载请自行联系原作者

你可能感兴趣的文章
Python 数据类型
查看>>
iOS--环信集成并修改头像和昵称(需要自己的服务器)
查看>>
PHP版微信权限验证配置,音频文件下载,FFmpeg转码,上传OSS和删除转存服务器本地文件...
查看>>
教程前言 - 回归宣言
查看>>
PHP 7.1是否支持操作符重载?
查看>>
Vue.js 中v-for和v-if一起使用,来判断select中的option为选中项
查看>>
Java中AES加密解密以及签名校验
查看>>
定义内部类 继承 AsyncTask 来实现异步网络请求
查看>>
VC中怎么读取.txt文件
查看>>
如何清理mac系统垃圾
查看>>
企业中最佳虚拟机软件应用程序—Parallels Deskto
查看>>
Nginx配置文件详细说明
查看>>
怎么用Navicat Premium图标编辑器创建表
查看>>
Spring配置文件(2)配置方式
查看>>
MariaDB/Mysql 批量插入 批量更新
查看>>
ItelliJ IDEA开发工具使用—创建一个web项目
查看>>
solr-4.10.4部署到tomcat6
查看>>
切片键(Shard Keys)
查看>>
淘宝API-类目
查看>>
virtualbox 笔记
查看>>