diff --git a/postgresql/defaults/main.yml b/postgresql/defaults/main.yml new file mode 100644 index 00000000..229a9d25 --- /dev/null +++ b/postgresql/defaults/main.yml @@ -0,0 +1,9 @@ +--- +# Used to create specific Munin graphs. +databases: ['titi', 'toto'] + +# Tuning +shared_buffers: 4GB +work_mem: 8MB +random_page_cost: 1.5 +effective_cache_size: 14GB diff --git a/postgresql/handlers/main.yml b/postgresql/handlers/main.yml new file mode 100644 index 00000000..9b181cdd --- /dev/null +++ b/postgresql/handlers/main.yml @@ -0,0 +1,15 @@ +--- +- name: restart munin-node + service: + name: munin-node + state: restarted + +- name: restart nagios-nrpe-server + service: + name: nagios-nrpe-server + state: restarted + +- name: restart postgresql + service: + name: postgresql + state: restarted diff --git a/postgresql/tasks/config.yml b/postgresql/tasks/config.yml new file mode 100644 index 00000000..8cbcede6 --- /dev/null +++ b/postgresql/tasks/config.yml @@ -0,0 +1,23 @@ +--- +- name: Allow conf.d/*.conf files to be included in PostgreSQL configuration + lineinfile: + name: /etc/postgresql/9.4/main/postgresql.conf + line: include_dir = 'conf.d' + notify: restart postgresql + +- name: Create conf.d directory + file: + name: /etc/postgresql/9.4/main/conf.d/ + state: directory + owner: postgres + group: postgres + mode: 0755 + +- name: Copy PostgreSQL config file + template: + src: postgresql.conf + dest: /etc/postgresql/9.4/main/conf.d/evolinux.conf + owner: postgres + group: postgres + mode: 0644 + notify: restart postgresql diff --git a/postgresql/tasks/main.yml b/postgresql/tasks/main.yml new file mode 100644 index 00000000..e75f2607 --- /dev/null +++ b/postgresql/tasks/main.yml @@ -0,0 +1,6 @@ +--- + +- include: package.yml +- include: config.yml +- include: nrpe.yml +- include: munin.yml diff --git a/postgresql/tasks/munin.yml b/postgresql/tasks/munin.yml new file mode 100644 index 00000000..bc3fe5cf --- /dev/null +++ b/postgresql/tasks/munin.yml @@ -0,0 +1,23 @@ +--- +- name: Add Munin plugins for PostgreSQL + file: + state: link + src: '/usr/share/munin/plugins/{{item}}' + dest: '/etc/munin/plugins/{{item}}' + with_items: + - postgres_bgwriter + - postgres_checkpoints + - postgres_connections_db + - postgres_users + - postgres_xlog + notify: restart munin-node + +- name: Add Munin plugins for PostgreSQL (for specific databases) + file: + state: link + src: '/usr/share/munin/plugins/{{item[0]}}' + dest: '/etc/munin/plugins/{{item[0]}}{{item[1]}}' + with_nested: + - ['postgres_cache_', 'postgres_connections_', 'postgres_locks_', 'postgres_querylength_', 'postgres_scans_', 'postgres_size_', 'postgres_transactions_', 'postgres_tuples_'] + - '{{databases}}' + notify: restart munin-node diff --git a/postgresql/tasks/nrpe.yml b/postgresql/tasks/nrpe.yml new file mode 100644 index 00000000..31e19039 --- /dev/null +++ b/postgresql/tasks/nrpe.yml @@ -0,0 +1,20 @@ +--- +- name: Generate random password for nrpe user + shell: apg -n1 -m 12 -M SCNL + register: nrpe_password + changed_when: False + +- name: Create nrpe user + become_user: postgres + postgresql_user: + name: nrpe + password: '{{ nrpe_password.stdout }}' + no_password_changes: yes + register: create_nrpe_user + +- name: Add NRPE check + lineinfile: + name: /etc/nagios/nrpe.d/evolix.cfg + line: 'command[check_pgsql]=/usr/lib/nagios/plugins/check_pgsql -H localhost -l nrpe -p "{{nrpe_password.stdout}}"' + when: create_nrpe_user.changed + notify: restart nagios-nrpe-server diff --git a/postgresql/tasks/package.yml b/postgresql/tasks/package.yml new file mode 100644 index 00000000..9754f4bc --- /dev/null +++ b/postgresql/tasks/package.yml @@ -0,0 +1,6 @@ +--- + +- name: Install postgresql package + apt: + name: '{{item}}' + with_items: ['postgresql', 'ptop'] diff --git a/postgresql/templates/postgresql.conf b/postgresql/templates/postgresql.conf new file mode 100644 index 00000000..25b0bb2c --- /dev/null +++ b/postgresql/templates/postgresql.conf @@ -0,0 +1,25 @@ +# Tuning +shared_buffers = {{shared_buffers}} +work_mem = {{work_mem}} +#shared_preload_libraries = 'pg_stat_statements' +#synchronous_commit = off +checkpoint_segments = 30 +checkpoint_completion_target = 0.9 +random_page_cost = {{random_page_cost}} +effective_cache_size = {{effective_cache_size}} + +# Loging +log_min_duration_statement = 1s +log_checkpoints = on +log_lock_waits = on +log_temp_files = 5MB +log_autovacuum_min_duration = 1s + +# Locales +lc_monetary = 'fr_FR.UTF-8' +lc_numeric = 'fr_FR.UTF-8' +lc_time = 'fr_FR.UTF-8' +default_text_search_config = 'pg_catalog.french' + +#escape_string_warning = off +#standard_conforming_strings = off