def test_create_postgresql_config_wal_with_replication_max_override(self): """ When postgresql is in C{replicated} mode, and participates in a C{replication} relation, C{hot_standby} will be set to C{on}, C{wal_level} will be enabled as C{hot_standby}. The written value for C{max_wal_senders} will be the maximum of replication slave count and the configuration value for C{max_wal_senders}. The written value of C{wal_keep_segments} will be the maximum of the configuration C{wal_keep_segments} and C{replicated_wal_keep_segments}. """ self.addCleanup(setattr, hooks.hookenv, "_relation_ids", ()) hooks.hookenv._relation_ids = { "replication/0": "db-admin:5", "replication/1": "db-admin:6" } hooks.hookenv._config["max_wal_senders"] = "3" hooks.hookenv._config["wal_keep_segments"] = 1000 hooks.hookenv._config["replicated_wal_keep_segments"] = 999 config_outfile = self.makeFile() _run_sysctl = self.mocker.replace(hooks._run_sysctl) _run_sysctl(hooks.postgresql_sysctl) self.mocker.result(True) self.mocker.replay() hooks.create_postgresql_config(config_outfile) self.assertFileContains(config_outfile, [ "hot_standby = True", "wal_level = hot_standby", "max_wal_senders = 3", "wal_keep_segments = 1000" ])
def test_create_postgresql_config_wal_with_replication_max_override(self): """ When postgresql is in C{replicated} mode, and participates in a C{replication} relation, C{hot_standby} will be set to C{on}, C{wal_level} will be enabled as C{hot_standby}. The written value for C{max_wal_senders} will be the maximum of replication slave count and the configuration value for C{max_wal_senders}. The written value of C{wal_keep_segments} will be the maximum of the configuration C{wal_keep_segments} and C{replicated_wal_keep_segments}. """ self.addCleanup( setattr, hooks.hookenv, "_relation_ids", ()) hooks.hookenv._relation_ids = { "replication/0": "db-admin:5", "replication/1": "db-admin:6"} hooks.hookenv._config["max_wal_senders"] = "3" hooks.hookenv._config["wal_keep_segments"] = 1000 hooks.hookenv._config["replicated_wal_keep_segments"] = 999 config_outfile = self.makeFile() _run_sysctl = self.mocker.replace(hooks._run_sysctl) _run_sysctl(hooks.postgresql_sysctl) self.mocker.result(True) self.mocker.replay() hooks.create_postgresql_config(config_outfile) self.assertFileContains( config_outfile, ["hot_standby = True", "wal_level = hot_standby", "max_wal_senders = 3", "wal_keep_segments = 1000"])
def test_auto_tuned_kernel_settings(self): """ Kernel settings are automatically set to max RAM values """ config_outfile = self.makeFile() _run_sysctl = self.mocker.replace(hooks._run_sysctl) _run_sysctl(hooks.postgresql_sysctl) self.mocker.result(True) self.mocker.replay() hooks.create_postgresql_config(config_outfile) self.assertFileContains( hooks.postgresql_sysctl, ["kernel.shmall = 1025\nkernel.shmmax = 1073742848"])
def test_auto_tuned_postgresql_config(self): """ When automatic performance tuning is specified, pgtune will modify postgresql.conf. Automatic performance tuning is the default. """ config_outfile = self.makeFile() _run_sysctl = self.mocker.replace(hooks._run_sysctl) _run_sysctl(hooks.postgresql_sysctl) self.mocker.result(True) self.mocker.replay() hooks.create_postgresql_config(config_outfile) raw_config = open(config_outfile, 'r').read() self.assert_('# pgtune wizard' in raw_config)
def test_create_postgresql_config_wal_no_replication(self): """ When postgresql is in C{standalone} mode, and participates in no C{replication} relations, default wal settings will be present. """ config_outfile = self.makeFile() _run_sysctl = self.mocker.replace(hooks._run_sysctl) _run_sysctl(hooks.postgresql_sysctl) self.mocker.result(True) self.mocker.replay() hooks.create_postgresql_config(config_outfile) self.assertFileContains( config_outfile, ["wal_level = minimal", "max_wal_senders = 0", "wal_keep_segments = 0"])
def test_create_postgresql_config_wal_no_replication(self): """ When postgresql is in C{standalone} mode, and participates in no C{replication} relations, default wal settings will be present. """ config_outfile = self.makeFile() _run_sysctl = self.mocker.replace(hooks._run_sysctl) _run_sysctl(hooks.postgresql_sysctl) self.mocker.result(True) self.mocker.replay() hooks.create_postgresql_config(config_outfile) self.assertFileContains(config_outfile, [ "wal_level = minimal", "max_wal_senders = 0", "wal_keep_segments = 0" ])
def test_auto_tuning_preserves_max_connections(self): """ pgtune with choose max_connections unless you tell it not too """ # Note that the charm does not yet make use of automatic # max_connections. We may want to change the default # max_connections to null and autotune then. hooks.hookenv._config["max_connections"] = 42 config_outfile = self.makeFile() _run_sysctl = self.mocker.replace(hooks._run_sysctl) _run_sysctl(hooks.postgresql_sysctl) self.mocker.result(True) self.mocker.replay() hooks.create_postgresql_config(config_outfile) raw_config = open(config_outfile, 'r').read() self.assert_('\nmax_connections = 42\n' in raw_config)
def test_create_postgresql_config_wal_with_replication(self): """ When postgresql is in C{replicated} mode, and participates in a C{replication} relation, C{hot_standby} will be set to C{on}, C{wal_level} will be enabled as C{hot_standby} and the C{max_wall_senders} will match the count of replication relations. The value of C{wal_keep_segments} will be the maximum of the configured C{wal_keep_segments} and C{replicated_wal_keep_segments}. """ self.addCleanup( setattr, hooks.hookenv, "_relation_ids", {}) hooks.hookenv._relation_ids = { "replication/0": "db-admin:5", "replication/1": "db-admin:6"} config_outfile = self.makeFile() _run_sysctl = self.mocker.replace(hooks._run_sysctl) _run_sysctl(hooks.postgresql_sysctl) self.mocker.result(True) self.mocker.replay() hooks.create_postgresql_config(config_outfile) self.assertFileContains( config_outfile, ["hot_standby = True", "wal_level = hot_standby", "max_wal_senders = 2", "wal_keep_segments = 5000"])
def test_create_postgresql_config_wal_with_replication(self): """ When postgresql is in C{replicated} mode, and participates in a C{replication} relation, C{hot_standby} will be set to C{on}, C{wal_level} will be enabled as C{hot_standby} and the C{max_wall_senders} will match the count of replication relations. The value of C{wal_keep_segments} will be the maximum of the configured C{wal_keep_segments} and C{replicated_wal_keep_segments}. """ self.addCleanup(setattr, hooks.hookenv, "_relation_ids", {}) hooks.hookenv._relation_ids = { "replication/0": "db-admin:5", "replication/1": "db-admin:6" } config_outfile = self.makeFile() _run_sysctl = self.mocker.replace(hooks._run_sysctl) _run_sysctl(hooks.postgresql_sysctl) self.mocker.result(True) self.mocker.replay() hooks.create_postgresql_config(config_outfile) self.assertFileContains(config_outfile, [ "hot_standby = True", "wal_level = hot_standby", "max_wal_senders = 2", "wal_keep_segments = 5000" ])