From 7d9b24174a74a385322351a1a63ceb5ed5e7f214 Mon Sep 17 00:00:00 2001 From: Andrea Dell'Amico Date: Wed, 23 Aug 2017 14:06:58 +0200 Subject: [PATCH] postgresql: Use different tasks to configure the logging system and the autovacuum. --- postgresql/defaults/main.yml | 28 ++++++++++++++++++++++++++ postgresql/tasks/postgresql-config.yml | 20 +++++++++++++++++- 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/postgresql/defaults/main.yml b/postgresql/defaults/main.yml index 3e45a7e1..3e4edb68 100644 --- a/postgresql/defaults/main.yml +++ b/postgresql/defaults/main.yml @@ -31,6 +31,34 @@ psql_conf_parameters: - { name: 'max_stack_depth', value: '2MB', set: 'False' } - { name: 'max_files_per_process', value: '1000', set: 'False' } +# logging configuration. Important: the parameters that need a restart must be listed in psql_conf_parameters +psql_log_configuration: + - { name: 'log_destination', value: 'stderr', set: 'True' } + - { name: 'logging_collector', value: 'off', set: 'False' } + - { name: 'log_directory', value: '{{ psql_log_dir }}', set: 'True' } + - { name: 'log_rotation_age', value: '1d', set: 'True' } + - { name: 'log_rotation_size', value: '10MB', set: 'True' } + - { name: 'client_min_messages', value: 'notice', set: 'True' } + - { name: 'log_min_messages', value: 'warning', set: 'True' } + - { name: 'log_min_error_statement', value: 'error', set: 'True' } + - { name: 'log_min_duration_statement', value: '-1', set: 'True' } + - { name: 'log_checkpoints', value: 'off', set: 'True' } + - { name: 'log_connections', value: 'on', set: 'True' } + - { name: 'log_disconnections', value: 'off', set: 'True' } + - { name: 'log_duration', value: 'off', set: 'True' } + - { name: 'log_error_verbosity', value: 'default', set: 'True' } + - { name: 'log_hostname', value: 'on', set: 'True' } + +# Treat vacuum separately. Important: the parameters that need a restart must be listed in psql_conf_parameters +psql_autovacuum_configuration: + - { name: 'track_counts', value: 'on', set: 'True' } + - { name: 'autovacuum', value: 'on', set: 'True' } + - { name: 'log_autovacuum_min_duration', value: '-1', set: 'True' } + - { name: 'autovacuum_vacuum_threshold', value: '50', set: 'True' } + - { name: 'autovacuum_analyze_threshold', value: '50', set: 'True' } + - { name: 'autovacuum_vacuum_scale_factor', value: '0.2', set: 'True' } + - { name: 'autovacuum_vacuum_cost_limit', value: '1000', set: 'True' } + # SSL as a special case psql_enable_ssl: False psql_force_ssl_client_connection: False diff --git a/postgresql/tasks/postgresql-config.yml b/postgresql/tasks/postgresql-config.yml index 30083471..fa17baf9 100644 --- a/postgresql/tasks/postgresql-config.yml +++ b/postgresql/tasks/postgresql-config.yml @@ -12,7 +12,7 @@ when: psql_use_alternate_data_dir tags: [ 'postgresql', 'postgres', 'pg_conf' ] -- name: Set some postgresql configuration parameters +- name: Set some postgresql configuration parameters that require a db restart become: True become_user: postgres action: configfile path={{ psql_conf_dir }}/postgresql.conf key={{ item.name }} value="{{ item.value }}" @@ -21,3 +21,21 @@ notify: Restart postgresql tags: [ 'postgresql', 'postgres', 'pg_conf' ] +- name: Set the postgresql logging configuration parameters + become: True + become_user: postgres + action: configfile path={{ psql_conf_dir }}/postgresql.conf key={{ item.name }} value="{{ item.value }}" + with_items: '{{ psql_log_parameters }}' + when: item.set == 'True' + notify: Reload postgresql + tags: [ 'postgresql', 'postgres', 'pg_conf', 'pg_conf_log' ] + +- name: Set the postgresql autovacuum configuration parameters + become: True + become_user: postgres + action: configfile path={{ psql_conf_dir }}/postgresql.conf key={{ item.name }} value="{{ item.value }}" + with_items: '{{ psql_autovacuum_parameters }}' + when: item.set == 'True' + notify: Reload postgresql + tags: [ 'postgresql', 'postgres', 'pg_conf', 'pg_autovacuum_log' ] +