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

2021/11/13 19:15:39

本文主要是介绍PostgreSQL数据库集簇初始化——initdb初始化数据库(测试平台相关配置设置),对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

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数据库集簇初始化——initdb初始化数据库(测试平台相关配置设置)的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程