示例#1
0
def postgresql_conf_defaults():
    """Return the postgresql.conf defaults, which we parse from config.yaml"""
    # We load defaults from the extra_pg_conf default in config.yaml,
    # which ensures that they never get out of sync.
    raw = helpers.config_yaml()["options"]["extra_pg_conf"]["default"]
    defaults = postgresql.parse_config(raw)

    # And recalculate some defaults, which could get out of sync.
    # Settings with mandatory minimums like wal_senders are handled
    # later, in ensure_viable_postgresql_conf().
    ram = int(host.get_total_ram() / (1024 * 1024))  # Working in megabytes.

    # Default shared_buffers to 25% of ram, minimum 16MB, maximum 8GB,
    # per current best practice rules of thumb. Rest is cache.
    shared_buffers = max(min(math.ceil(ram * 0.25), 8192), 16)
    effective_cache_size = max(1, ram - shared_buffers)
    defaults["shared_buffers"] = "{} MB".format(shared_buffers)
    defaults["effective_cache_size"] = "{} MB".format(effective_cache_size)

    # PostgreSQL 10 introduces multiple password encryption methods.
    if postgresql.has_version("10"):
        # Change this to scram-sha-256 next LTS release, when we can
        # start assuming clients have libpq 10. The setting can of
        # course still be overridden in the config.
        defaults["password_encryption"] = "md5"
    else:
        defaults["password_encryption"] = True

    return defaults
示例#2
0
def postgresql_conf_deprecated_overrides():
    '''Overrides from deprecated service configuration options.

    There are far too many knobs in postgresql.conf for the charm
    to duplicate each one in config.yaml, and they can change between
    versions. The old options that did this have all been deprecated,
    and users can specify them in the extra_pg_conf option.

    One day this method and the deprecated options will go away.
    '''
    config = hookenv.config()

    # These deprecated options mapped directly to postgresql.conf settings.
    # As you can see, it was unmaintainably long.
    simple_options = frozenset(['max_connections', 'max_prepared_transactions',
                                'ssl', 'log_min_duration_statement',
                                'log_checkpoints', 'log_connections',
                                'log_disconnections', 'log_temp_files',
                                'log_line_prefix', 'log_lock_waits',
                                'log_timezone', 'log_autovacuum_min_duration',
                                'autovacuum', 'autovacuum_analyze_threshold',
                                'autovacuum_vacuum_scale_factor',
                                'autovacuum_analyze_scale_factor',
                                'autovacuum_vacuum_cost_delay', 'search_path',
                                'standard_conforming_strings', 'hot_standby',
                                'hot_standby_feedback', 'wal_level',
                                'max_wal_senders', 'wal_keep_segments',
                                'archive_mode', 'archive_command',
                                'work_mem', 'maintenance_work_mem',
                                'shared_buffers', 'effective_cache_size',
                                'default_statistics_target', 'temp_buffers',
                                'wal_buffers', 'checkpoint_segments',
                                'checkpoint_completion_target',
                                'checkpoint_timeout', 'fsync',
                                'synchronous_commit', 'full_page_writes',
                                'random_page_cost'])

    in_use = helpers.deprecated_config_in_use()

    # Some deprecated options no longer exist in more recent PostgreSQL rels.
    valid_options = set(postgresql.pg_settings_schema().keys())

    # The simple deprecated options map directly to postgresql.conf settings.
    # Strip the deprecated options that no longer exist at all here.
    settings = {k: config[k] for k in in_use
                if k in simple_options and k in valid_options}

    # The listen_port and collapse_limit options were special.
    config_yaml_options = helpers.config_yaml()['options']
    defaults = {k: config_yaml_options[k]['default']
                for k in config_yaml_options}
    if config['listen_port'] not in (-1, defaults['listen_port']):
        settings['port'] = config['listen_port']
    if config['collapse_limit'] != defaults['collapse_limit']:
        settings['from_collapse_limit'] = config['collapse_limit']
        settings['join_collapse_limit'] = config['collapse_limit']

    return settings
示例#3
0
def postgresql_conf_defaults():
    '''Return the postgresql.conf defaults, which we parse from config.yaml'''
    # We load defaults from the extra_pg_conf default in config.yaml,
    # which ensures that they never get out of sync.
    raw = helpers.config_yaml()['options']['extra_pg_conf']['default']
    defaults = postgresql.parse_config(raw)

    # And recalculate some defaults, which could get out of sync.
    # Settings with mandatory minimums like wal_senders are handled
    # later, in ensure_viable_postgresql_conf().
    ram = int(host.get_total_ram() / (1024 * 1024))  # Working in megabytes.

    # Default shared_buffers to 25% of ram, minimum 16MB, maximum 8GB,
    # per current best practice rules of thumb. Rest is cache.
    shared_buffers = max(min(math.ceil(ram * 0.25), 8192), 16)
    effective_cache_size = max(1, ram - shared_buffers)
    defaults['shared_buffers'] = '{} MB'.format(shared_buffers)
    defaults['effective_cache_size'] = '{} MB'.format(effective_cache_size)

    return defaults
示例#4
0
def postgresql_conf_deprecated_overrides():
    """Overrides from deprecated service configuration options.

    There are far too many knobs in postgresql.conf for the charm
    to duplicate each one in config.yaml, and they can change between
    versions. The old options that did this have all been deprecated,
    and users can specify them in the extra_pg_conf option.

    One day this method and the deprecated options will go away.
    """
    config = hookenv.config()

    # These deprecated options mapped directly to postgresql.conf settings.
    # As you can see, it was unmaintainably long.
    simple_options = frozenset(
        [
            "max_connections",
            "max_prepared_transactions",
            "ssl",
            "log_min_duration_statement",
            "log_checkpoints",
            "log_connections",
            "log_disconnections",
            "log_temp_files",
            "log_line_prefix",
            "log_lock_waits",
            "log_timezone",
            "log_autovacuum_min_duration",
            "autovacuum",
            "autovacuum_analyze_threshold",
            "autovacuum_vacuum_scale_factor",
            "autovacuum_analyze_scale_factor",
            "autovacuum_vacuum_cost_delay",
            "search_path",
            "standard_conforming_strings",
            "hot_standby",
            "hot_standby_feedback",
            "wal_level",
            "max_wal_senders",
            "wal_keep_segments",
            "archive_mode",
            "archive_command",
            "work_mem",
            "maintenance_work_mem",
            "shared_buffers",
            "effective_cache_size",
            "default_statistics_target",
            "temp_buffers",
            "wal_buffers",
            "checkpoint_segments",
            "checkpoint_completion_target",
            "checkpoint_timeout",
            "fsync",
            "synchronous_commit",
            "full_page_writes",
            "random_page_cost",
        ]
    )

    in_use = helpers.deprecated_config_in_use()

    # Some deprecated options no longer exist in more recent PostgreSQL rels.
    valid_options = set(postgresql.pg_settings_schema().keys())

    # The simple deprecated options map directly to postgresql.conf settings.
    # Strip the deprecated options that no longer exist at all here.
    settings = {k: config[k] for k in in_use if k in simple_options and k in valid_options}

    # The listen_port and collapse_limit options were special.
    config_yaml_options = helpers.config_yaml()["options"]
    defaults = {k: config_yaml_options[k]["default"] for k in config_yaml_options}
    if config["listen_port"] not in (-1, defaults["listen_port"]):
        settings["port"] = config["listen_port"]
    if config["collapse_limit"] != defaults["collapse_limit"]:
        settings["from_collapse_limit"] = config["collapse_limit"]
        settings["join_collapse_limit"] = config["collapse_limit"]

    return settings