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 ...
随机推荐
- 零基础学通C语言,福利来啦!!!!zfhl.ke.qq.com
- jQuery live与bind的区别
平时在使用jQuery进行AJAX操作的时候,新生成的元素事件会失效,有时候不得不重新绑定一下事件,但是这样做很麻烦.例如评论分页后对评论内容的JS验证会失效等.在jQuery1.3之前有一个插件会解 ...
- Android自定义的webView——可实现的网页文本的复制
package com.example.customlinearlayout.view; import android.app.ProgressDialog; import android.conte ...
- 【转】使用 Auto Layout 的典型痛点和技巧
layoutIfNeeded()强制立刻更新布局 原文网址:http://www.jianshu.com/p/0f031606e5f2 官方文档:Auto Layout Guide 加上去年WWDC上 ...
- Jquery插件写法及extentd函数
JQuery插件写法 JQuery插件又分为类扩展方法和对象扩展方法两种,类插件是定义在JQuery命令空间的全局函数,直接通过可调用,如可调用,如可调用,如.ajax():对象插件是扩展JQuery ...
- hdu 5407 CRB and Candies(组合数+最小公倍数+素数表+逆元)2015 Multi-University Training Contest 10
题意: 输入n,求c(n,0)到c(n,n)的所有组合数的最小公倍数. 输入: 首行输入整数t,表示共有t组测试样例. 每组测试样例包含一个正整数n(1<=n<=1e6). 输出: 输出结 ...
- hdu 3172 Virtual Friends(并查集)University of Waterloo Local Contest 2008.09
题目比较简单,但作为长久不写题之后的热身题还是不错的. 统计每组朋友的朋友圈的大小. 如果a和b是朋友,这个朋友圈的大小为2,如果b和c也是朋友,那么a和c也是朋友,此时这个朋友圈的大小为3. 输入t ...
- 反转链表 --剑指offer
题目:定义一个函数,输入一个链表的头结点,反转该链表并输出反正后链表的头结点. #include<stdio.h> #include<malloc.h> typedef str ...
- Object类介绍
一.Object类介绍
- HDU 3853-loop(概率dp入门)
题意: r*c个方格,从(1,1)开始在每个方格可释放魔法(消耗能量2)以知,释放魔法后可能在原地.可能到达相邻的下面格子或右面格子,给出三者的概率 求要到达(R,C)格子,要消耗能量的期望值. 分析 ...