ICode9

精准搜索请尝试: 精确搜索
首页 > 数据库> 文章详细

PostgreSQL数据库集簇初始化——initdb初始化数据库(测试平台相关配置设置)

2021-11-13 12:30:57  阅读:205  来源: 互联网

标签:初始化 PostgreSQL 数据库 dynamic connections memory test shared buffers


static void test_config_settings(void) {
	/* This macro defines the minimum shared_buffers we want for a given max_connections value. The arrays show the settings to try. */
#define MIN_BUFS_FOR_CONNS(nconns)	((nconns) * 10)
	static const int trial_conns[] = {100, 50, 40, 30, 20};
	static const int trial_bufs[] = {16384, 8192, 4096, 3584, 3072, 2560, 2048, 1536,1000, 900, 800, 700, 600, 500,400, 300, 200, 100, 50};

	char		cmd[MAXPGPATH];
	const int	connslen = sizeof(trial_conns) / sizeof(int);
	const int	bufslen = sizeof(trial_bufs) / sizeof(int);
	int			i,status,test_conns,test_buffs,ok_buffers = 0;

    // 测试平台最佳得DSM动态共享内存实现方式
	/* Need to determine working DSM implementation first so that subsequent tests don't fail because DSM setting doesn't work. */
	printf(_("selecting dynamic shared memory implementation ... ")); fflush(stdout);
	dynamic_shared_memory_type = choose_dsm_implementation();
	printf("%s\n", dynamic_shared_memory_type);

	/* Probe for max_connections before shared_buffers, since it is subject to more constraints than shared_buffers. */
	printf(_("selecting default max_connections ... "));
	fflush(stdout);

	for (i = 0; i < connslen; i++) {
		test_conns = trial_conns[i];
		test_buffs = MIN_BUFS_FOR_CONNS(test_conns);
		snprintf(cmd, sizeof(cmd),"\"%s\" --boot -x0 %s -c max_connections=%d -c shared_buffers=%d -c dynamic_shared_memory_type=%s < \"%s\" > \"%s\" 2>&1",backend_exec, boot_options,test_conns, test_buffs,dynamic_shared_memory_type,DEVNULL, DEVNULL);
		status = system(cmd);
		if (status == 0) {
			ok_buffers = test_buffs;
			break;
		}
	}
	if (i >= connslen) i = connslen - 1;
	n_connections = trial_conns[i];
	printf("%d\n", n_connections);

调用postgres --boot -x0 -F -c max_connections=test_conns -c shared_buffers=test_buffs -c dynamic_shared_memory_type=dynamic_shared_memory_type < DEVNULL > DEVNULL 2>&1 进行测试max_connections大小

	printf(_("selecting default shared_buffers ... "));
	fflush(stdout);
	for (i = 0; i < bufslen; i++){
		/* Use same amount of memory, independent of BLCKSZ */
		test_buffs = (trial_bufs[i] * 8192) / BLCKSZ;
		if (test_buffs <= ok_buffers){
			test_buffs = ok_buffers;
			break;
		}

		snprintf(cmd, sizeof(cmd),"\"%s\" --boot -x0 %s -c max_connections=%d -c shared_buffers=%d -c dynamic_shared_memory_type=%s < \"%s\" > \"%s\" 2>&1", backend_exec, boot_options, n_connections, test_buffs, dynamic_shared_memory_type, DEVNULL, DEVNULL);
		status = system(cmd);
		if (status == 0) break;
	}
	n_buffers = test_buffs;
	if ((n_buffers * (BLCKSZ / 1024)) % 1024 == 0) printf("%dMB\n", (n_buffers * (BLCKSZ / 1024)) / 1024);
	else printf("%dkB\n", n_buffers * (BLCKSZ / 1024));
	printf(_("selecting default time zone ... "));
	fflush(stdout);
	default_timezone = select_default_timezone(share_path);
	printf("%s\n", default_timezone ? default_timezone : "GMT");
}

调用postgres --boot -x0 -F -c max_connections=n_connections -c shared_buffers=test_buffs -c dynamic_shared_memory_type=dynamic_shared_memory_type < DEVNULL > DEVNULL 2>&1 进行测试shared_buffers大小

标签:初始化,PostgreSQL,数据库,dynamic,connections,memory,test,shared,buffers
来源: https://blog.csdn.net/asmartkiller/article/details/121302570

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有