PostgreSQL建表动作分析
首先,建立表:
pgsql=# create table tab10(id integer);
CREATE TABLE
pgsql=# select 147525::regclass;
regclass
----------
tab10
(1 row) pgsql=#
查看此时的文件信息:
[pgsql@localhost ]$ pwd
/home/pgsql/DemoDir/base/[pgsql@localhost ]$ ls -l
-rw------- pgsql pgsql Jul :
[pgsql@localhost ]$
此时,文件刚刚建立好,还是一个空文件
同时,可以看到,因为建立了一个表,所以数据字典中有很多系统表被更新:
例如:pg_type。
这个确实有点超乎想象,因为我并未增加任何的新type。
pgsql=# select count(*) from pg_type;
count
-------
313
(1 row) pgsql=# create table tab10(id integer);
CREATE TABLE pgsql=# select count(*) from pg_type;
count
-------
315
(1 row)
看看增加了什么:
pgsql=# \x
Expanded display is on.
pgsql=# select * from pg_type where typname='tab10';
-[ RECORD 1 ]--+------------
typname | tab10
typnamespace | 2200
typowner | 10
typlen | -1
typbyval | f
typtype | c
typcategory | C
typispreferred | f
typisdefined | t
typdelim | ,
typrelid | 188542
typelem | 0
typarray | 188543
typinput | record_in
typoutput | record_out
typreceive | record_recv
typsend | record_send
typmodin | -
typmodout | -
typanalyze | -
typalign | d
typstorage | x
typnotnull | f
typbasetype | 0
typtypmod | -1
typndims | 0
typcollation | 0
typdefaultbin |
typdefault | pgsql=#
pgsql=# select * from pg_type where typname='_tab10';
-[ RECORD 1 ]--+-----------
typname | _tab10
typnamespace | 2200
typowner | 10
typlen | -1
typbyval | f
typtype | b
typcategory | A
typispreferred | f
typisdefined | t
typdelim | ,
typrelid | 0
typelem | 188544
typarray | 0
typinput | array_in
typoutput | array_out
typreceive | array_recv
typsend | array_send
typmodin | -
typmodout | -
typanalyze | -
typalign | d
typstorage | x
typnotnull | f
typbasetype | 0
typtypmod | -1
typndims | 0
typcollation | 0
typdefaultbin |
typdefault | pgsql=#
创建一个表达式后,对其他的系统表的写入,也有很多
再看和pg_depend之间的关联:
pgsql=# drop table tab10;
DROP TABLE
pgsql=#
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 TABLE
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;
-[ RECORD 1 ]--------------+-------------
depender object class | pg_type
depender object identity | tab10
objsubid | 0
referenced object class | pg_class
referenced object identity | tab10
refobjsubid | 0
dependency type | internal
-[ RECORD 2 ]--------------+-------------
depender object class | pg_type
depender object identity | tab10[]
objsubid | 0
referenced object class | pg_type
referenced object identity | tab10
refobjsubid | 0
dependency type | internal
-[ RECORD 3 ]--------------+-------------
depender object class | pg_class
depender object identity | tab10
objsubid | 0
referenced object class | pg_namespace
referenced object identity | 2200
refobjsubid | 0
dependency type | normal pgsql=#
再看对pg_class的影响:
pgsql=# drop table tab10;
DROP TABLEpgsql=# create table tab10(id integer);
CREATE TABLEpgsql=# \x
Expanded display is on.
pgsql=# select * from pg_class where relname='tab10';
-[ RECORD 1 ]--+-------
relname | tab10
relnamespace | 2200
reltype | 188562
reloftype | 0
relowner | 10
relam | 0
relfilenode | 188560
reltablespace | 0
relpages | 0
reltuples | 0
reltoastrelid | 0
reltoastidxid | 0
relhasindex | f
relisshared | f
relpersistence | p
relkind | r
relnatts | 1
relchecks | 0
relhasoids | f
relhaspkey | f
relhasrules | f
relhastriggers | f
relhassubclass | f
relfrozenxid | 2017
relacl |
reloptions | pgsql=#
再看对 pg_attribute的影响,生成表之后:
pgsql=# select 188563::regclass;
regclass
----------
tab10
(1 row) pgsql=# \x
Expanded display is on.
pgsql=# select * from pg_attribute where attrelid = (select max(attrelid) from pg_attribute);
-[ RECORD 1 ]-+---------
attrelid | 188563
attname | tableoid
atttypid | 26
attstattarget | 0
attlen | 4
attnum | -7
attndims | 0
attcacheoff | -1
atttypmod | -1
attbyval | t
attstorage | p
attalign | i
attnotnull | t
atthasdef | f
attisdropped | f
attislocal | t
attinhcount | 0
attcollation | 0
attacl |
attoptions |
-[ RECORD 2 ]-+---------
attrelid | 188563
attname | cmax
atttypid | 29
attstattarget | 0
attlen | 4
attnum | -6
attndims | 0
attcacheoff | -1
atttypmod | -1
attbyval | t
attstorage | p
attalign | i
attnotnull | t
atthasdef | f
attisdropped | f
attislocal | t
attinhcount | 0
attcollation | 0
attacl |
attoptions |
-[ RECORD 3 ]-+---------
attrelid | 188563
attname | xmax
atttypid | 28
attstattarget | 0
attlen | 4
attnum | -5
attndims | 0
attcacheoff | -1
atttypmod | -1
attbyval | t
attstorage | p
attalign | i
attnotnull | t
atthasdef | f
attisdropped | f
attislocal | t
attinhcount | 0
attcollation | 0
attacl |
attoptions |
-[ RECORD 4 ]-+---------
attrelid | 188563
attname | cmin
atttypid | 29
attstattarget | 0
attlen | 4
attnum | -4
attndims | 0
attcacheoff | -1
atttypmod | -1
attbyval | t
attstorage | p
attalign | i
attnotnull | t
atthasdef | f
attisdropped | f
attislocal | t
attinhcount | 0
attcollation | 0
attacl |
attoptions |
-[ RECORD 5 ]-+---------
attrelid | 188563
attname | xmin
atttypid | 28
attstattarget | 0
attlen | 4
attnum | -3
attndims | 0
attcacheoff | -1
atttypmod | -1
attbyval | t
attstorage | p
attalign | i
attnotnull | t
atthasdef | f
attisdropped | f
attislocal | t
attinhcount | 0
attcollation | 0
attacl |
attoptions |
-[ RECORD 6 ]-+---------
attrelid | 188563
attname | ctid
atttypid | 27
attstattarget | 0
attlen | 6
attnum | -1
attndims | 0
attcacheoff | -1
atttypmod | -1
attbyval | f
attstorage | p
attalign | s
attnotnull | t
atthasdef | f
attisdropped | f
attislocal | t
attinhcount | 0
attcollation | 0
attacl |
attoptions |
-[ RECORD 7 ]-+---------
attrelid | 188563
attname | id
atttypid | 23
attstattarget | -1
attlen | 4
attnum | 1
attndims | 0
attcacheoff | -1
atttypmod | -1
attbyval | t
attstorage | p
attalign | i
attnotnull | f
atthasdef | f
attisdropped | f
attislocal | t
attinhcount | 0
attcollation | 0
attacl |
attoptions | pgsql=#
基本就是这些了。
PostgreSQL建表动作分析的更多相关文章
- PostgreSQL建表SQL语句写法
DROP TABLE IF EXISTS bus; CREATE TABLE bus( id SERIAL PRIMARY KEY, mac ) NOT NULL UNIQUE, route int ...
- Activiti+oracle 启动项目时不能自动建表或更新表的问题分析及解决办法
现象描述:按照正常配置,第一次启动时不能自动建表 关键配置片段如下: <bean id="processEngineConfiguration" class="or ...
- postgreSQL生成建表语句
参考博文:https://blog.csdn.net/xiaofengtoo/article/details/84395199 修复了其函数中的bug,支持生成包含:字段(支持数组类型字段).约束.索 ...
- [转]Hibernate不能自动建表解决办法及Hibernate不同数据库的连接及SQL方言
最近开始学Hibernate,看的是李刚的那本<轻量级java ee企业应用实战>.头一个hibernate程序,我原原本本的按照书上例子写下来,同时只是改动了些mysql的连接参数,并且 ...
- PostgreSQL的基础数据类型分析记录-转
src:http://www.codeweblog.com/postgresql%E7%9A%84%E5%9F%BA%E7%A1%80%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E ...
- 建表过程-列名&列类型&修改表B
怎么建表? 主键 名称 重量 价格 生产日期 保质期 产地 种类 分析:我们只要把第一行的表头建好后,这张表也就完成了. 术语:建表的过程就是声明字段过程 ...
- Hibernate不能自动建表解决办法
最近开始学Hibernate,看的是李刚的那本<轻量级java ee企业应用实战>.头一个hibernate程序,我原原本本的按照书上例子写下来,同时只是改动了些mysql的连接参数,并且 ...
- hive建表没使用LZO存储格式,可是数据是LZO格式时遇到的问题
今天微博大数据平台发邮件来说.他们有一个hql执行失败.可是从gateway上面的日志看不出来是什么原因导致的,我帮忙看了一下.最后找到了问题的解决办法,下面是分析过程: 1.执行失败的hql: IN ...
- [04] 利用注解生成实体类对应的建表sql语句
1.实现功能 我们已经对注解有了基本的认识,知道了如何自定义注解,如何使用和最基本的处理注解. 本篇主要介绍,如何使用运行时级别的注解,配合反射来自动生成建表的sql语句.如下例: 我们有实体类Stu ...
随机推荐
- DirectX截图黑屏的解决办法
好久没有更新博客了,今天开始继续耕耘. 生活要继续 工作要继续 梦想也一定要继续! 之前写过一篇关于DirectX截屏的文章,其中有网友留言提到了截图黑屏的问题,于是这些日子研究了一下,与大家一同分享 ...
- 为redis分配一个新的端口
为redis分配一个8888端口,操作步骤如下:1.$REDIS_HOME/redis.conf重新复制一份,重命名为redis8888.conf.2.打开redis8888.conf配置文件,找到p ...
- Android应用程序版本号管理(官方文档中文版)
在应用程序的 升级/维护 策略中, 版本是一个关键的组成部分. 用户需要了解在他们的设备上所安装的应用程序的版本的特定信息, 以及已安装程序的升级版本可用的情况. 其他应用程序 - 作为同一个套件中发 ...
- [视频监控]用状态机图展示Layout切换关系
监控系统通常会提供多种Layout给用户,用于满足不同需求,如:高清显示单路视频或者同时观察多路监控情况. 文中系统只提供了单路.2x2(2行2列共4路).8路(4行4列布局,从左上角算起,有个核心显 ...
- Cutting Sticks
题意: l长的木棒,给出n个切割点,每切一次的费用为切得木棒的长度,完成切割的最小费用. 分析: 区间dp入门,区间dp的特点,一个大区间的解可以转换成小区间的解组合起来,每个切割点的标号代表边界. ...
- cocos2d CCLayer 触摸相关
要让一个 CCLayer 能够接受触摸输入 需要进行如下设置: [selfsetTouchEnabled:YES]; cocos2d-x提供了两种触摸事件处理机制, 分别是CCStandardTo ...
- ASP.NET中常用的字符串分割函数
asp.net字符串分割函数用法 先来看个简单的实例 但是其数组长度却是25,而不是3.下面这种方法是先将“[111cn.net]”替换成一个特殊字符,比如$,在根据这个字符执行Split 例如下面我 ...
- 对象指针与this指针
对象指针分为三大类 [1]指向对象的指针 [2]指向对象成员的指针(数据类) [3]指向对象成员的指针(函数类) #include<iostream> using namespace st ...
- 简易nagios安装
这段时间一直在进行nagios安装的实验,进行了很多的实验,现在也就是将这些进行一些基础的记录. 本篇主要讲述的是进行nagios的简易安装,在安装完成之后,能够在web页面上看到本地的监控图像, n ...
- css样式表中的样式覆盖顺序
刚才写zenktodo的时候,通过动态添加class的方式修改一个div的样式,总是不起作用. #navigator { height: 100%; width: 200; position: abs ...