语法说明: initdb [option...] [ --pgdata | -D ] directory 参数解析: -A authmethod --auth=authmethod 这个选项为本地用户指定在pg_hba.conf中使用的默
initdb [option...] [ --pgdata | -D ] directory
显示有关initdb命令行参数的帮助并退出。
postgresql-12.2srcininitdb文件夹中的initdb.c文件 main函数:
help和version直接解析并返回
getopt_long:从参数中获取有效值,进行基本信息填充
判断解析到的参数值是否有效
设置wal日志
setup_pgdata设置路径
setup_bin_path获取其他可执行文件路径
设置相关信息 …
initialize_data_directory初始化
显示成功,告诉用户怎么使用
在pg的源码src/backend/catalog/genbki.pl中包含了相关的脚本。在编译pg时,会执行这个脚本、生成一个postgres.bki文件(默认在/usr/local/pgsql/share目录下)
后端接口(BKI)是用一些特殊语言写的脚本,这些脚本是 PostgreSQL后端可以理解,以特殊的 "bootstrap" 模式执行. 这种模式允许在不存在系统表的零初始条件下执行数据库函数,而普通的SQL命令要求系统表必须存在。 因此BKI文件可以用于在第一时间创建数据库系统,并且除此以外可能也没有其它用处。 在创建一个新的数据库集群时,initdb 使用BKI文件 来完成部分工作。initdb使用的文件是作为编译 PostgreSQL的一部分,由一个叫genbki.pl的程序创建,这个程序读取源代码树木录的src/include/catalog/目录里的几个特殊C开头的文件。生成的BKI文件叫postgres.bki,并且通常安装在安装目录里的share子目录系统初始化的BKI文件的结构. open命令打开的表需要系统事先存在另外一些基本的表 ,在这些表存在并拥有数据之前,不能使用open命令。 这些最低限度必须存在的表是 pg_class, pg_attribute, pg_proc, and pg_type。 为了允许这些表自己被填充, 带bootstrap 选项的create 隐含打开所创建的表用于插入数据。 同样, declare index和declare toast 命令也不能在它们所需要的系统表创建并填充之前使用。 因此,postgres.bki文件的结构必须是这样的:
下面的命令将创建名为 test_table的表,它的OID是420,该表有两个字段cola和colb , 字段类型分别为int4和text, 然后向该表插入两行:
create test_table 420 (cola = int4, colb = text) open test_table insert OID=421 ( 1 "value1" ) insert OID=422 ( 2 null ) close test_table
为pg_database增加一个字段 datdummy,打开 /src/include/catalog/pg_database.h:
CATALOG(pg_database,1262) BKI_SHARED_RELATION BKI_ROWTYPE_OID(1248) BKI_SCHEMA_MacRO {
NameData datname;
#ifdef CATALOG_VARLEN
#endif
} FormData_pg_database;
typedef FormData_pg_database *Form_pg_database;
#define Natts_pg_database 13
#define Anum_pg_database_datname 1
#define Anum_pg_database_datdba 2
#define Anum_pg_database_encoding 3
#define Anum_pg_database_datcollate 4
#define Anum_pg_database_datctype 5
#define Anum_pg_database_datistemplate 6
#define Anum_pg_database_datallowconn 7
#define Anum_pg_database_datconnlimit 8
#define Anum_pg_database_datlastsysoid 9
#define Anum_pg_database_datfrozenxid 10
#define Anum_pg_database_datminmxid 11
#define Anum_pg_database_dattablespace 12
#define Anum_pg_database_datacl 13
int8 datdummy;
#define Natts_pg_database 14
#define Anum_pg_database_dattablespace 12
#define Anum_pg_database_datdummy 13
#define Anum_pg_database_datacl 14
[
{ oid => "1", oid_symbol => "TemplateDbOid",
descr => "default template for new databases",
datname => "template1", encoding => "ENCODING", datcollate => "LC_COLLATE",
datctype => "LC_CTYPE", datistemplate => "t", datallowconn => "t",
datconnlimit => "-1", datlastsysoid => "0", datfrozenxid => "0",
datminmxid => "1", dattablespace => "pg_default", datdummy => 111, datacl => "_null_" },
]
被脚本 genbki.pl 利用生成 postgresql.bki文件
insert OID = 1 ( template1 PGUID ENCODING "LC_COLLATE" "LC_CTYPE" t t -1 0 0 1 1663 111 null));
修改pg_proc
{ oid => "1242", descr => "I/O",
proname => "boolin", prorettype => "bool", proargtypes => "cstring",
prosrc => "boolin" , newvalue => "999"},
结果显示:
select * from pg_proc;
-[ RECORD 1 ]
-----------------------------------------------
oid | 1242
proname | boolin
pronamespace | 11
proowner | 10
prolang | 12
procost | 1
prorows | 0
provariadic | 0
prosupport | -
prokind | f
prosecdef | f
proleakproof | f
proisstrict | t
proretset | f
provolatile | i
proparallel | s
pronargs | 1
pronargdefaults | 0
prorettype | 16
proargtypes | 2275
proallargtypes |
proargmodes |
proargnames |
proargdefaults |
protrftypes |
prosrc | boolin
probin |
proconfig |
proacl |
newvalue |
注意:此处未增加相关命令的修改,实际修改时需要注意:
--结束END--
本文标题: postgres initdb 初始化
本文链接: https://www.lsjlt.com/news/6182.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-04-29
2024-04-29
2024-04-29
2024-04-29
2024-04-28
2024-04-28
2024-04-28
2024-04-28
2024-04-28
2024-04-28
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0