当前位置: 首页 > news >正文

PostgreSQL数据库内核(二):通过initdb传递guc参数

目录

增加guc参数

 initdb参数传递

 pg_ctl参数传递

参数验证


新增guc参数pg_test_parameter,支持从initdb和pg_ctl命令中传递/覆盖参数,使用场景是TDE透明加密指定算法或者某些定制化需求。

增加guc参数

        pg源码是这样描述guc参数的:它是全局配置管理模式(包括set命令、conf配置文件或其他方式指定参数),我们postgresql.conf文件中所有参数都在这里面,但它是conf文件超集,还有一些配置是不能对用户提供的。

* Support for grand unified configuration scheme, including SET
* command, configuration file, and command line options.
* See src/backend/utils/misc/README for more information.

比如postgresql.conf中定义wal段大小的参数:

		{"max_wal_size", PGC_SIGHUP, WAL_CHECKPOINTS,gettext_noop("Sets the WAL size that triggers a checkpoint."),NULL,GUC_UNIT_MB},

本次我们新增1个guc参数pg_test_parameter,直接仿照src/utils/misc/guc.c文件中的data_directory参数定义,这个参数指定后也是不允许修改的,并且在initdb和pg_ctl都需要指定,跟我们本次想实现的参数类似,但是两者的GucContext和config_group类型有差异;

		{"data_directory", PGC_POSTMASTER, FILE_LOCATIONS,gettext_noop("Sets the server's data directory."),NULL,GUC_SUPERUSER_ONLY | GUC_DISALLOW_IN_AUTO_FILE},&data_directory,NULL,NULL, NULL, NULL},{{"pg_test_parameter", PGC_INTERNAL, PRESET_OPTIONS,gettext_noop("Sets pg test parameter."),NULL,GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE},&pg_test_parameter,NULL,NULL, NULL, NULL},

定义后就会有pg_test_parameter这个全局参数了,但是定义参数要用起来。 

 initdb参数传递

支持initdb方式传递pg_test_parameter,需要接受参数输入,这里增加-p的参数读取与参数解析逻辑,在/src/bin/initdb/initdb.c中:

//增加-p参数printf(_("  -p, --pg-test-parameter                show pg_test_parameter settings\n"));
//在main函数中把它定义为必须传递的参数static struct option long_options[] = {// ...{"pg-test-parameter", required_argument, NULL, 'N'}// ...};
//增加参数解析while ((c = getopt_long(argc, argv, "A:dD:E:gkL:nNsST:U:WX:p:", long_options, &option_index)) != -1){switch (c){// ...case 'p':pg_test_parameter = pg_strdup(optarg);break;// ...}}
// 增加日志if (pg_test_parameter){printf(_("pg_test_parameter ok. \n"));}elseprintf(_("pg_test_parameter not ok..\n"));

这里完成initdb的参数传递,直接通过initdb -p abc方式将pg_test_parameter参数设置成abc。

 pg_ctl参数传递

这里传入后根据需要读取

// 增加参数读入while ((flag = getopt(argc, argv, "B:p:c:d:D:Fkr:x:X:-:")) != -1){switch (flag){// ...case 'p':pg_test_parameter = pstrdup(optarg);break;// ...
}
}

参数验证

initdb指定-p参数:

 ./initdb -D ~/data -p abc
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.The database cluster will be initialized with locale "en_US.UTF-8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".Data page checksums are disabled.creating directory /home/postgres/data ... ok
creating subdirectories ... ok
selecting dynamic shared memory implementation ... posix
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default time zone ... Asia/Shanghai
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok
pg_test_parameter ok.initdb: warning: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the option -A, or
--auth-local and --auth-host, the next time you run initdb.Success. You can now start the database server using:./pg_ctl -D /home/postgres/data -l logfile start

查看参数(调试中):


postgres=# show pg_test_parameter;pg_test_parameter
-------------------(1 row)

相关文章:

  • 北京网站建设多少钱?
  • 辽宁网页制作哪家好_网站建设
  • 高端品牌网站建设_汉中网站制作
  • [安洵杯 2019]easy_web1
  • 微信小程序接口实现语音转文字
  • 牛客周赛 Round 54 (c++题解)
  • 使用Echarts来实现数据可视化
  • python-查找元素3(赛氪OJ)
  • minio文件上传
  • 书籍去掉字符串中连续出现k个0的子串
  • Linux防火墙2
  • JS+H5美观的带搜索的博客文章列表(可搜索多个参数)
  • 数据可视化(王者英雄数据分析)
  • 系统架构师(每日一练14)
  • 【LeetCode】108. 将有序数组转换为二叉搜索树
  • mysql数据库迁移
  • Face2V人脸向量开发包
  • 使用python爬取今日头条热搜
  • python3.6+scrapy+mysql 爬虫实战
  • 《网管员必读——网络组建》(第2版)电子课件下载
  • 4月23日世界读书日 网络营销论坛推荐《正在爆发的营销革命》
  • Angular4 模板式表单用法以及验证
  • Git 使用集
  • hadoop集群管理系统搭建规划说明
  • IIS 10 PHP CGI 设置 PHP_INI_SCAN_DIR
  • maven工程打包jar以及java jar命令的classpath使用
  • MySQL几个简单SQL的优化
  • ng6--错误信息小结(持续更新)
  • TypeScript实现数据结构(一)栈,队列,链表
  • 第2章 网络文档
  • 浏览器缓存机制分析
  • 前嗅ForeSpider中数据浏览界面介绍
  • 如何抓住下一波零售风口?看RPA玩转零售自动化
  • 我从编程教室毕业
  • 原创:新手布局福音!微信小程序使用flex的一些基础样式属性(一)
  • 3月27日云栖精选夜读 | 从 “城市大脑”实践,瞭望未来城市源起 ...
  • 新年再起“裁员潮”,“钢铁侠”马斯克要一举裁掉SpaceX 600余名员工 ...
  • # 手柄编程_北通阿修罗3动手评:一款兼具功能、操控性的电竞手柄
  • #### golang中【堆】的使用及底层 ####
  • #HarmonyOS:软件安装window和mac预览Hello World
  • #laravel部署安装报错loadFactoriesFrom是undefined method #
  • $$$$GB2312-80区位编码表$$$$
  • (11)工业界推荐系统-小红书推荐场景及内部实践【粗排三塔模型】
  • (12)Hive调优——count distinct去重优化
  • (9)目标检测_SSD的原理
  • (初研) Sentence-embedding fine-tune notebook
  • (七)Activiti-modeler中文支持
  • (顺序)容器的好伴侣 --- 容器适配器
  • (转)原始图像数据和PDF中的图像数据
  • ..thread“main“ com.fasterxml.jackson.databind.JsonMappingException: Jackson version is too old 2.3.1
  • .dat文件写入byte类型数组_用Python从Abaqus导出txt、dat数据
  • .net core 3.0 linux,.NET Core 3.0 的新增功能
  • .NET CORE使用Redis分布式锁续命(续期)问题
  • .NET 程序如何获取图片的宽高(框架自带多种方法的不同性能)
  • .NET 指南:抽象化实现的基类
  • .NET(C#、VB)APP开发——Smobiler平台控件介绍:Bluetooth组件
  • /ThinkPHP/Library/Think/Storage/Driver/File.class.php  LINE: 48
  • @staticmethod和@classmethod的作用与区别