diff --git a/core/src/epicli/data/common/ansible/playbooks/roles/backup/tasks/postgresql.yml b/core/src/epicli/data/common/ansible/playbooks/roles/backup/tasks/postgresql.yml index d4bd207245..8ba1acf0d6 100644 --- a/core/src/epicli/data/common/ansible/playbooks/roles/backup/tasks/postgresql.yml +++ b/core/src/epicli/data/common/ansible/playbooks/roles/backup/tasks/postgresql.yml @@ -10,7 +10,7 @@ - name: Check if database is running on node0 database server become: true become_user: postgres - command: "{{ repmgr.pg_bindir[ansible_os_family] }}/pg_isready" + command: "{{ pg.bindir[ansible_os_family] }}/pg_isready" register: node0 ignore_errors: True when: groups['postgresql'][0] == inventory_hostname diff --git a/core/src/epicli/data/common/ansible/playbooks/roles/postgresql/defaults/main.yml b/core/src/epicli/data/common/ansible/playbooks/roles/postgresql/defaults/main.yml index f9f32b1149..b0b8edf4e2 100644 --- a/core/src/epicli/data/common/ansible/playbooks/roles/postgresql/defaults/main.yml +++ b/core/src/epicli/data/common/ansible/playbooks/roles/postgresql/defaults/main.yml @@ -4,31 +4,31 @@ pg: Debian: /var/lib/postgresql RedHat: /var/lib/pgsql bin_dir: - Debian: /usr/lib/postgresql/10/bin - RedHat: /usr/pgsql-10/bin + Debian: /usr/lib/postgresql/13/bin + RedHat: /usr/pgsql-13/bin config_dir: - Debian: /etc/postgresql/10/main - RedHat: /var/lib/pgsql/10/data + Debian: /etc/postgresql/13/main + RedHat: /var/lib/pgsql/13/data data_dir: - Debian: /var/lib/postgresql/10/main - RedHat: /var/lib/pgsql/10/data + Debian: /var/lib/postgresql/13/main + RedHat: /var/lib/pgsql/13/data instantiated_service_name: - Debian: postgresql@10-main + Debian: postgresql@13-main RedHat: null service_name: Debian: postgresql - RedHat: postgresql-10 + RedHat: postgresql-13 repmgr: bin_dir: Debian: /usr/bin - RedHat: /usr/pgsql-10/bin + RedHat: /usr/pgsql-13/bin config_dir: - Debian: /etc/postgresql/10/main - RedHat: /etc/repmgr/10 + Debian: /etc/postgresql/13/main + RedHat: /etc/repmgr/13 service_name: Debian: repmgrd - RedHat: repmgr10 + RedHat: repmgr13 version: Debian: "5.2.1" RedHat: "5.2.1" diff --git a/core/src/epicli/data/common/ansible/playbooks/roles/postgresql/molecule/README.md b/core/src/epicli/data/common/ansible/playbooks/roles/postgresql/molecule/README.md new file mode 100644 index 0000000000..aebec936dd --- /dev/null +++ b/core/src/epicli/data/common/ansible/playbooks/roles/postgresql/molecule/README.md @@ -0,0 +1,32 @@ +# Installation guide + +## Requirements + +- Internet connection +- Molecule [dependencies](https://molecule.readthedocs.io/en/latest/installation.html) +- Docker +- ansible-lint + +## Installation + +```bash +pip install 'molecule[docker]' +pip install ansible-lint +``` + +## Execution + +### General + +```bash +molecule test -s +``` + +### Separate steps + +```bash +molecule lint -s +molecule converge -s +molecule idempotence -s +molecule verify -s +``` diff --git a/core/src/epicli/data/common/ansible/playbooks/roles/postgresql/molecule/add-repos-debian.sh b/core/src/epicli/data/common/ansible/playbooks/roles/postgresql/molecule/add-repos-debian.sh new file mode 100644 index 0000000000..a6104ea62c --- /dev/null +++ b/core/src/epicli/data/common/ansible/playbooks/roles/postgresql/molecule/add-repos-debian.sh @@ -0,0 +1,11 @@ +#!/bin/bash -eu + +apt update && apt -y install wget gpg-agent + +wget -qO - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add - +echo "deb http://apt.postgresql.org/pub/repos/apt bionic-pgdg main" | tee /etc/apt/sources.list.d/pgdg.list + +wget -qO - https://dl.2ndquadrant.com/gpg-key.asc | apt-key add - +echo "deb https://dl.2ndquadrant.com/default/release/apt bionic-2ndquadrant main" | tee /etc/apt/sources.list.d/2ndquadrant-dl-default-release.list + +apt update diff --git a/core/src/epicli/data/common/ansible/playbooks/roles/postgresql/molecule/add-repos-redhat.sh b/core/src/epicli/data/common/ansible/playbooks/roles/postgresql/molecule/add-repos-redhat.sh new file mode 100644 index 0000000000..a3e4e51021 --- /dev/null +++ b/core/src/epicli/data/common/ansible/playbooks/roles/postgresql/molecule/add-repos-redhat.sh @@ -0,0 +1,143 @@ +#!/usr/bin/env bash + +set -euo pipefail + +CREATE_LOGFILE='no' + +# params: +add_repo_as_file() { + local repo_id="$1" + local config_file_content="$2" + local config_file_name="$repo_id.repo" + + if ! is_repo_enabled "$repo_id"; then + echol "Adding repository: $repo_id" + cat <<<"$config_file_content" >"/etc/yum.repos.d/$config_file_name" || + exit_with_error "Function add_repo_as_file failed for repo: $repo_id" + local -a gpg_key_urls + IFS=" " read -r -a gpg_key_urls \ + <<<"$(grep -i --only-matching --perl-regexp '(?<=^gpgkey=)http[^#\n]+' <<<"$config_file_content")" + if ((${#gpg_key_urls[@]} > 0)); then + import_repo_gpg_keys "${gpg_key_urls[@]}" 3 + fi + # to accept import of repo's GPG key (for repo_gpgcheck=1) + yum -y repolist >/dev/null || exit_with_error "Command failed: yum -y repolist" + fi +} + +# params: +add_repo_from_script() { + local script_url="$1" + + echol "Running: curl $script_url | bash" + curl $script_url | bash +} + +# params: +disable_repo() { + local repo_id="$1" + + if yum repolist enabled | grep --quiet "$repo_id"; then + echol "Disabling repository: $repo_id" + yum-config-manager --disable "$repo_id" || + exit_with_error "Command failed: yum-config-manager --disable \"$repo_id\"" + fi +} + +echol() { + echo -e "$@" + if [[ $CREATE_LOGFILE == 'yes' ]]; then + local timestamp=$(date +"%b %e %H:%M:%S") + echo -e "${timestamp}: $@" >>"$LOG_FILE_PATH" + fi +} + +# params: +import_repo_gpg_keys() { + local retries=${!#} # get last arg + local urls=("${@:1:$#-1}") # remove last arg + + for url in "${urls[@]}"; do + run_cmd_with_retries rpm --import "$url" "$retries" + done +} + +# params: +is_repo_enabled() { + local repo_id="$1" + + if yum repolist | grep --quiet "$repo_id"; then + echol "Repository $repo_id already enabled" + return 0 + else + return 1 + fi +} + +# Runs command as array with printing it, doesn't support commands with shell operators (such as pipe or redirection) +# params: [--no-exit-on-error] +run_cmd() { + local cmd_arr=("$@") + + local exit_on_error=1 + if [[ ${cmd_arr[-1]} == '--no-exit-on-error' ]]; then + exit_on_error=0 + cmd_arr=("${cmd_arr[@]:0:$#-1}") # remove last item + fi + + local escaped_string return_code + escaped_string=$(_print_array_as_shell_escaped_string "${cmd_arr[@]}") + echol "Executing: ${escaped_string}" + "${cmd_arr[@]}" + return_code=$? + if ((return_code != 0)) && ((exit_on_error)); then + exit_with_error "Command failed: ${escaped_string}" + else + return $return_code + fi +} + +# Runs command with retries, doesn't support commands with shell operators (such as pipe or redirection) +# params: +run_cmd_with_retries() { + # pop 'retries' argument + local retries=${!#} # get last arg (indirect expansion) + set -- "${@:1:$#-1}" # set new "$@" + + local cmd_arr=("$@") + (# sub-shell is used to limit scope for 'set +e' + set +e + trap - ERR # disable global trap locally + for ((i = 0; i <= retries; i++)); do + run_cmd "${cmd_arr[@]}" '--no-exit-on-error' + return_code=$? + if ((return_code == 0)); then + break + elif ((i < retries)); then + sleep 1 + echol "retrying ($((i + 1))/${retries})" + else + echol "ERROR: all attempts failed" + local escaped_string + escaped_string=$(_print_array_as_shell_escaped_string "${cmd_arr[@]}") + exit_with_error "Command failed: ${escaped_string}" + fi + done + return $return_code + ) +} + +POSTGRESQL_REPO_CONF=$( + cat <<'EOF' +[pgdg13] +name=PostgreSQL 13 for RHEL/CentOS $releasever - $basearch +baseurl=https://download.postgresql.org/pub/repos/yum/13/redhat/rhel-$releasever-$basearch +enabled=1 +gpgcheck=1 +gpgkey=https://download.postgresql.org/pub/repos/yum/RPM-GPG-KEY-PGDG +EOF +) + +add_repo_as_file 'postgresql-13' "$POSTGRESQL_REPO_CONF" +add_repo_from_script 'https://dl.2ndquadrant.com/default/release/get/13/rpm' # for repmgr +disable_repo '2ndquadrant-dl-default-release-pg13-debug' # script adds 2 repositories, only 1 is required diff --git a/core/src/epicli/data/common/ansible/playbooks/roles/postgresql/molecule/debian-repmgr/converge.yml b/core/src/epicli/data/common/ansible/playbooks/roles/postgresql/molecule/debian-repmgr/converge.yml new file mode 100644 index 0000000000..9ba579eb42 --- /dev/null +++ b/core/src/epicli/data/common/ansible/playbooks/roles/postgresql/molecule/debian-repmgr/converge.yml @@ -0,0 +1,19 @@ +--- +- name: Converge + hosts: postgresql + become: true + become_method: sudo + module_defaults: + shell: + executable: /bin/bash + tasks: + - name: Include 'configuration/postgresql' variables + include_vars: + file: ../vars-repmgr.yml + + - name: Include postgresql role + include_role: + name: postgresql + vars: + yum_lock_timeout: 300 # https://github.com/ansible/ansible/issues/57189 + roles_with_generated_vars: [ ] # don't execute PgPool related tasks diff --git a/core/src/epicli/data/common/ansible/playbooks/roles/postgresql/molecule/debian-repmgr/molecule.yml b/core/src/epicli/data/common/ansible/playbooks/roles/postgresql/molecule/debian-repmgr/molecule.yml new file mode 100644 index 0000000000..36b2ca9f92 --- /dev/null +++ b/core/src/epicli/data/common/ansible/playbooks/roles/postgresql/molecule/debian-repmgr/molecule.yml @@ -0,0 +1,46 @@ +--- +dependency: + enabled: false +# linter's project dir is changed to avoid issues with include_tasks +lint: ansible-lint --project-dir=../.. roles/postgresql --exclude roles/postgresql/molecule +driver: + name: docker +platforms: + - name: instance-1 + groups: + - postgresql + image: geerlingguy/docker-ubuntu1804-ansible:python2 + pre_build_image: true + capabilities: + - SYS_ADMIN + command: /lib/systemd/systemd + tmpfs: + - /run + - /tmp + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:ro + - name: instance-2 + groups: + - postgresql + image: geerlingguy/docker-ubuntu1804-ansible:python2 + pre_build_image: true + capabilities: + - SYS_ADMIN + command: /lib/systemd/systemd + tmpfs: + - /run + - /tmp + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:ro +provisioner: + name: ansible + playbooks: + prepare: prepare.yml + converge: converge.yml + verify: ../verify-repmgr.yml + inventory: + group_vars: + postgresql: + ansible_python_interpreter: /usr/bin/python2 +verifier: + name: ansible diff --git a/core/src/epicli/data/common/ansible/playbooks/roles/postgresql/molecule/debian-repmgr/prepare.yml b/core/src/epicli/data/common/ansible/playbooks/roles/postgresql/molecule/debian-repmgr/prepare.yml new file mode 100644 index 0000000000..7352ac8f91 --- /dev/null +++ b/core/src/epicli/data/common/ansible/playbooks/roles/postgresql/molecule/debian-repmgr/prepare.yml @@ -0,0 +1,6 @@ +--- +- name: Prepare + hosts: postgresql + tasks: + - name: Add repositories for downloading dependencies + script: ../add-repos-debian.sh diff --git a/core/src/epicli/data/common/ansible/playbooks/roles/postgresql/molecule/debian-single-node/converge.yml b/core/src/epicli/data/common/ansible/playbooks/roles/postgresql/molecule/debian-single-node/converge.yml new file mode 100644 index 0000000000..c3d366c48e --- /dev/null +++ b/core/src/epicli/data/common/ansible/playbooks/roles/postgresql/molecule/debian-single-node/converge.yml @@ -0,0 +1,19 @@ +--- +- name: Converge + hosts: postgresql + become: true + become_method: sudo + module_defaults: + shell: + executable: /bin/bash + tasks: + - name: Include 'configuration/postgresql' variables + include_vars: + file: ../vars-single-node.yml + + - name: Include postgresql role + include_role: + name: postgresql + vars: + yum_lock_timeout: 300 # https://github.com/ansible/ansible/issues/57189 + roles_with_generated_vars: [ ] # don't execute PgPool related tasks diff --git a/core/src/epicli/data/common/ansible/playbooks/roles/postgresql/molecule/debian-single-node/molecule.yml b/core/src/epicli/data/common/ansible/playbooks/roles/postgresql/molecule/debian-single-node/molecule.yml new file mode 100644 index 0000000000..8904a163d3 --- /dev/null +++ b/core/src/epicli/data/common/ansible/playbooks/roles/postgresql/molecule/debian-single-node/molecule.yml @@ -0,0 +1,46 @@ +--- +dependency: + enabled: false +# linter's project dir is changed to avoid issues with include_tasks +lint: ansible-lint --project-dir=../.. roles/postgresql --exclude roles/postgresql/molecule +driver: + name: docker +platforms: + - name: instance-1 + groups: + - postgresql + image: geerlingguy/docker-ubuntu1804-ansible:python2 + pre_build_image: true + capabilities: + - SYS_ADMIN + command: /lib/systemd/systemd + tmpfs: + - /run + - /tmp + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:ro + - name: instance-2 + groups: + - postgresql + image: geerlingguy/docker-ubuntu1804-ansible:python2 + pre_build_image: true + capabilities: + - SYS_ADMIN + command: /lib/systemd/systemd + tmpfs: + - /run + - /tmp + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:ro +provisioner: + name: ansible + playbooks: + prepare: prepare.yml + converge: converge.yml + verify: ../verify-single-node.yml + inventory: + group_vars: + postgresql: + ansible_python_interpreter: /usr/bin/python2 +verifier: + name: ansible diff --git a/core/src/epicli/data/common/ansible/playbooks/roles/postgresql/molecule/debian-single-node/prepare.yml b/core/src/epicli/data/common/ansible/playbooks/roles/postgresql/molecule/debian-single-node/prepare.yml new file mode 100644 index 0000000000..7352ac8f91 --- /dev/null +++ b/core/src/epicli/data/common/ansible/playbooks/roles/postgresql/molecule/debian-single-node/prepare.yml @@ -0,0 +1,6 @@ +--- +- name: Prepare + hosts: postgresql + tasks: + - name: Add repositories for downloading dependencies + script: ../add-repos-debian.sh diff --git a/core/src/epicli/data/common/ansible/playbooks/roles/postgresql/molecule/redhat-repmgr/converge.yml b/core/src/epicli/data/common/ansible/playbooks/roles/postgresql/molecule/redhat-repmgr/converge.yml new file mode 100644 index 0000000000..92c97d6f34 --- /dev/null +++ b/core/src/epicli/data/common/ansible/playbooks/roles/postgresql/molecule/redhat-repmgr/converge.yml @@ -0,0 +1,16 @@ +--- +- name: Converge + hosts: postgresql + become: true + become_method: sudo + tasks: + - name: Include 'configuration/postgresql' variables + include_vars: + file: ../vars-repmgr.yml + + - name: Include postgresql role + include_role: + name: postgresql + vars: + yum_lock_timeout: 300 # https://github.com/ansible/ansible/issues/57189 + roles_with_generated_vars: [ ] # don't execute PgPool related tasks diff --git a/core/src/epicli/data/common/ansible/playbooks/roles/postgresql/molecule/redhat-repmgr/molecule.yml b/core/src/epicli/data/common/ansible/playbooks/roles/postgresql/molecule/redhat-repmgr/molecule.yml new file mode 100644 index 0000000000..0fcb63b83c --- /dev/null +++ b/core/src/epicli/data/common/ansible/playbooks/roles/postgresql/molecule/redhat-repmgr/molecule.yml @@ -0,0 +1,42 @@ +--- +dependency: + enabled: false +# linter's project dir is changed to avoid issues with include_tasks +lint: ansible-lint --project-dir=../.. roles/postgresql --exclude roles/postgresql/molecule +driver: + name: docker +platforms: + - name: instance-1 + groups: + - postgresql + image: geerlingguy/docker-centos7-ansible + pre_build_image: true + capabilities: + - SYS_ADMIN + command: /lib/systemd/systemd + tmpfs: + - /run + - /tmp + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:ro + - name: instance-2 + groups: + - postgresql + image: geerlingguy/docker-centos7-ansible + pre_build_image: true + capabilities: + - SYS_ADMIN + command: /lib/systemd/systemd + tmpfs: + - /run + - /tmp + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:ro +provisioner: + name: ansible + playbooks: + prepare: prepare.yml + converge: converge.yml + verify: ../verify-repmgr.yml +verifier: + name: ansible diff --git a/core/src/epicli/data/common/ansible/playbooks/roles/postgresql/molecule/redhat-repmgr/prepare.yml b/core/src/epicli/data/common/ansible/playbooks/roles/postgresql/molecule/redhat-repmgr/prepare.yml new file mode 100644 index 0000000000..94e9319c18 --- /dev/null +++ b/core/src/epicli/data/common/ansible/playbooks/roles/postgresql/molecule/redhat-repmgr/prepare.yml @@ -0,0 +1,6 @@ +--- +- name: Prepare + hosts: postgresql + tasks: + - name: Add repositories for downloading dependencies + script: ../add-repos-redhat.sh diff --git a/core/src/epicli/data/common/ansible/playbooks/roles/postgresql/molecule/redhat-single-node/converge.yml b/core/src/epicli/data/common/ansible/playbooks/roles/postgresql/molecule/redhat-single-node/converge.yml new file mode 100644 index 0000000000..5977feecce --- /dev/null +++ b/core/src/epicli/data/common/ansible/playbooks/roles/postgresql/molecule/redhat-single-node/converge.yml @@ -0,0 +1,16 @@ +--- +- name: Converge + hosts: postgresql + become: true + become_method: sudo + tasks: + - name: Include 'configuration/postgresql' variables + include_vars: + file: ../vars-single-node.yml + + - name: Include postgresql role + include_role: + name: postgresql + vars: + yum_lock_timeout: 300 # https://github.com/ansible/ansible/issues/57189 + roles_with_generated_vars: [ ] # don't execute PgPool related tasks diff --git a/core/src/epicli/data/common/ansible/playbooks/roles/postgresql/molecule/redhat-single-node/molecule.yml b/core/src/epicli/data/common/ansible/playbooks/roles/postgresql/molecule/redhat-single-node/molecule.yml new file mode 100644 index 0000000000..6ee967a8c0 --- /dev/null +++ b/core/src/epicli/data/common/ansible/playbooks/roles/postgresql/molecule/redhat-single-node/molecule.yml @@ -0,0 +1,29 @@ +--- +dependency: + enabled: false +# linter's project dir is changed to avoid issues with include_tasks +lint: ansible-lint --project-dir=../.. roles/postgresql --exclude roles/postgresql/molecule +driver: + name: docker +platforms: + - name: instance-1 + groups: + - postgresql + image: geerlingguy/docker-centos7-ansible + pre_build_image: true + capabilities: + - SYS_ADMIN + command: /lib/systemd/systemd + tmpfs: + - /run + - /tmp + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:ro +provisioner: + name: ansible + playbooks: + prepare: prepare.yml + converge: converge.yml + verify: ../verify-single-node.yml +verifier: + name: ansible diff --git a/core/src/epicli/data/common/ansible/playbooks/roles/postgresql/molecule/redhat-single-node/prepare.yml b/core/src/epicli/data/common/ansible/playbooks/roles/postgresql/molecule/redhat-single-node/prepare.yml new file mode 100644 index 0000000000..94e9319c18 --- /dev/null +++ b/core/src/epicli/data/common/ansible/playbooks/roles/postgresql/molecule/redhat-single-node/prepare.yml @@ -0,0 +1,6 @@ +--- +- name: Prepare + hosts: postgresql + tasks: + - name: Add repositories for downloading dependencies + script: ../add-repos-redhat.sh diff --git a/core/src/epicli/data/common/ansible/playbooks/roles/postgresql/molecule/vars-repmgr.yml b/core/src/epicli/data/common/ansible/playbooks/roles/postgresql/molecule/vars-repmgr.yml new file mode 100644 index 0000000000..a85446a3fb --- /dev/null +++ b/core/src/epicli/data/common/ansible/playbooks/roles/postgresql/molecule/vars-repmgr.yml @@ -0,0 +1,115 @@ +--- +kind: configuration/postgresql +title: PostgreSQL +specification: + config_file: + parameter_groups: + - name: CONNECTIONS AND AUTHENTICATION + subgroups: + - name: Connection Settings + parameters: + - name: listen_addresses + value: "'*'" + comment: listen on all addresses + - name: Security and Authentication + parameters: + - name: ssl + value: off + comment: to have the default value also on Ubuntu + - name: RESOURCE USAGE (except WAL) + subgroups: + - name: Kernel Resource Usage + parameters: + - name: shared_preload_libraries + value: AUTOCONFIGURED + comment: set by automation + - name: ERROR REPORTING AND LOGGING + subgroups: + - name: Where to Log + parameters: + - name: log_directory + value: "'/var/log/postgresql'" + comment: to have standard location for Filebeat and logrotate + - name: log_filename + value: "'postgresql.log'" + comment: to use logrotate with common configuration + - name: WRITE AHEAD LOG + subgroups: + - name: Settings + parameters: + - name: wal_level + value: replica + when: replication + - name: Archiving + parameters: + - name: archive_mode + value: on + when: replication + - name: archive_command + value: "'/bin/true'" + when: replication + - name: REPLICATION + subgroups: + - name: Sending Server(s) + parameters: + - name: max_wal_senders + value: 10 + comment: maximum number of simultaneously running WAL sender processes + when: replication + - name: wal_keep_size + value: 500 + comment: the size of WAL files held for standby servers (MB) + when: replication + - name: Standby Servers + parameters: + - name: hot_standby + value: on + comment: must be 'on' for repmgr needs, ignored on primary but recommended + in case primary becomes standby + when: replication + extensions: + pgaudit: + enabled: true + shared_preload_libraries: + - pgaudit + config_file_parameters: + log_connections: off + log_disconnections: off + log_statement: none + log_line_prefix: "'%m [%p] %q%u@%d,host=%h '" + pgaudit.log: "'write, function, role, ddl, misc_set'" + pgaudit.log_catalog: 'off # to reduce overhead of logging' + pgaudit.log_relation: 'on # separate log entry for each relation' + pgaudit.log_statement_once: off + pgaudit.log_parameter: on + pgbouncer: + enabled: false + replication: + enabled: true + replication_user_name: epi_repmgr + replication_user_password: PASSWORD_TO_CHANGE + privileged_user_name: epi_repmgr_admin + privileged_user_password: PASSWORD_TO_CHANGE + repmgr_database: epi_repmgr + shared_preload_libraries: + - repmgr + logrotate: + pgbouncer: + period: weekly + rotations: 5 + postgresql: |- + /var/log/postgresql/postgresql*.log { + maxsize 10M + daily + rotate 6 + copytruncate + # delaycompress is for Filebeat + delaycompress + compress + notifempty + missingok + su root root + nomail + # to have multiple unique filenames per day when dateext option is set + dateformat -%Y%m%dH%H + } diff --git a/core/src/epicli/data/common/ansible/playbooks/roles/postgresql/molecule/vars-single-node.yml b/core/src/epicli/data/common/ansible/playbooks/roles/postgresql/molecule/vars-single-node.yml new file mode 100644 index 0000000000..a331ce8cfb --- /dev/null +++ b/core/src/epicli/data/common/ansible/playbooks/roles/postgresql/molecule/vars-single-node.yml @@ -0,0 +1,115 @@ +--- +kind: configuration/postgresql +title: PostgreSQL +specification: + config_file: + parameter_groups: + - name: CONNECTIONS AND AUTHENTICATION + subgroups: + - name: Connection Settings + parameters: + - name: listen_addresses + value: "'*'" + comment: listen on all addresses + - name: Security and Authentication + parameters: + - name: ssl + value: off + comment: to have the default value also on Ubuntu + - name: RESOURCE USAGE (except WAL) + subgroups: + - name: Kernel Resource Usage + parameters: + - name: shared_preload_libraries + value: AUTOCONFIGURED + comment: set by automation + - name: ERROR REPORTING AND LOGGING + subgroups: + - name: Where to Log + parameters: + - name: log_directory + value: "'/var/log/postgresql'" + comment: to have standard location for Filebeat and logrotate + - name: log_filename + value: "'postgresql.log'" + comment: to use logrotate with common configuration + - name: WRITE AHEAD LOG + subgroups: + - name: Settings + parameters: + - name: wal_level + value: replica + when: replication + - name: Archiving + parameters: + - name: archive_mode + value: on + when: replication + - name: archive_command + value: "'/bin/true'" + when: replication + - name: REPLICATION + subgroups: + - name: Sending Server(s) + parameters: + - name: max_wal_senders + value: 10 + comment: maximum number of simultaneously running WAL sender processes + when: replication + - name: wal_keep_size + value: 500 + comment: the size of WAL files held for standby servers (MB) + when: replication + - name: Standby Servers + parameters: + - name: hot_standby + value: on + comment: must be 'on' for repmgr needs, ignored on primary but recommended + in case primary becomes standby + when: replication + extensions: + pgaudit: + enabled: true + shared_preload_libraries: + - pgaudit + config_file_parameters: + log_connections: off + log_disconnections: off + log_statement: none + log_line_prefix: "'%m [%p] %q%u@%d,host=%h '" + pgaudit.log: "'write, function, role, ddl, misc_set'" + pgaudit.log_catalog: 'off # to reduce overhead of logging' + pgaudit.log_relation: 'on # separate log entry for each relation' + pgaudit.log_statement_once: off + pgaudit.log_parameter: on + pgbouncer: + enabled: false + replication: + enabled: false + replication_user_name: epi_repmgr + replication_user_password: PASSWORD_TO_CHANGE + privileged_user_name: epi_repmgr_admin + privileged_user_password: PASSWORD_TO_CHANGE + repmgr_database: epi_repmgr + shared_preload_libraries: + - repmgr + logrotate: + pgbouncer: + period: weekly + rotations: 5 + postgresql: |- + /var/log/postgresql/postgresql*.log { + maxsize 10M + daily + rotate 6 + copytruncate + # delaycompress is for Filebeat + delaycompress + compress + notifempty + missingok + su root root + nomail + # to have multiple unique filenames per day when dateext option is set + dateformat -%Y%m%dH%H + } diff --git a/core/src/epicli/data/common/ansible/playbooks/roles/postgresql/molecule/verify-common.yml b/core/src/epicli/data/common/ansible/playbooks/roles/postgresql/molecule/verify-common.yml new file mode 100644 index 0000000000..85b2872f44 --- /dev/null +++ b/core/src/epicli/data/common/ansible/playbooks/roles/postgresql/molecule/verify-common.yml @@ -0,0 +1,31 @@ +--- +- name: Gather facts on services + service_facts: + +# status is reported as 'unknown', so not checked +- name: Verify that PostgreSQL service exists and is running + vars: + _services: + Debian: postgresql@13-main.service + RedHat: postgresql-13.service + assert: + that: + - "{{ _services[ansible_os_family] in ansible_facts.services }}" + - "{{ ansible_facts.services[_services[ansible_os_family]].state == 'running' }}" + +# required for 'listen_ports_facts' module +- name: Ensure net-tools package is installed + package: + name: net-tools + state: present + +- name: Gather facts on listening ports + listen_ports_facts: + +- name: Verify PostgreSQL port + assert: + that: + - "{{ ansible_facts.tcp_listen + | selectattr('port', 'equalto', 5432) + | selectattr('address', 'equalto', '0.0.0.0') + | length == 1 }}" diff --git a/core/src/epicli/data/common/ansible/playbooks/roles/postgresql/molecule/verify-repmgr.yml b/core/src/epicli/data/common/ansible/playbooks/roles/postgresql/molecule/verify-repmgr.yml new file mode 100644 index 0000000000..66fa67b3a2 --- /dev/null +++ b/core/src/epicli/data/common/ansible/playbooks/roles/postgresql/molecule/verify-repmgr.yml @@ -0,0 +1,18 @@ +--- +- name: Verify + hosts: postgresql + gather_facts: true + tasks: + - name: Include common tasks + include_tasks: verify-common.yml + + # status is reported as 'unknown', so not checked + - name: Verify that Repmgr service exists and is running + vars: + _services: + Debian: repmgrd.service + RedHat: repmgr13.service + assert: + that: + - "{{ _services[ansible_os_family] in ansible_facts.services }}" + - "{{ ansible_facts.services[_services[ansible_os_family]].state == 'running' }}" diff --git a/core/src/epicli/data/common/ansible/playbooks/roles/postgresql/molecule/verify-single-node.yml b/core/src/epicli/data/common/ansible/playbooks/roles/postgresql/molecule/verify-single-node.yml new file mode 100644 index 0000000000..0af8a10db9 --- /dev/null +++ b/core/src/epicli/data/common/ansible/playbooks/roles/postgresql/molecule/verify-single-node.yml @@ -0,0 +1,7 @@ +--- +- name: Verify + hosts: postgresql + gather_facts: true + tasks: + - name: Include common tasks + include_tasks: verify-common.yml diff --git a/core/src/epicli/data/common/ansible/playbooks/roles/postgresql/tasks/extensions/pgaudit/packages.yml b/core/src/epicli/data/common/ansible/playbooks/roles/postgresql/tasks/extensions/pgaudit/packages.yml index 051d0853b6..72d0d4b938 100644 --- a/core/src/epicli/data/common/ansible/playbooks/roles/postgresql/tasks/extensions/pgaudit/packages.yml +++ b/core/src/epicli/data/common/ansible/playbooks/roles/postgresql/tasks/extensions/pgaudit/packages.yml @@ -6,8 +6,8 @@ vars: _packages: Debian: - - postgresql-10-pgaudit + - postgresql-13-pgaudit RedHat: - - pgaudit12_10 + - pgaudit15_13 module_defaults: yum: { lock_timeout: "{{ yum_lock_timeout }}" } diff --git a/core/src/epicli/data/common/ansible/playbooks/roles/postgresql/tasks/extensions/pgbouncer/extension.yml b/core/src/epicli/data/common/ansible/playbooks/roles/postgresql/tasks/extensions/pgbouncer/extension.yml index dfcb3df49b..70b04a2046 100644 --- a/core/src/epicli/data/common/ansible/playbooks/roles/postgresql/tasks/extensions/pgbouncer/extension.yml +++ b/core/src/epicli/data/common/ansible/playbooks/roles/postgresql/tasks/extensions/pgbouncer/extension.yml @@ -20,6 +20,7 @@ path: /etc/pgbouncer/userlist.txt line: '"postgres" "*"' create: true + mode: u=rw,g=,o= backup: true - name: Extensions | PgBouncer | Create pgbouncer logrotate configuration file diff --git a/core/src/epicli/data/common/ansible/playbooks/roles/postgresql/tasks/extensions/replication/extension.yml b/core/src/epicli/data/common/ansible/playbooks/roles/postgresql/tasks/extensions/replication/extension.yml index b0aed2a5a1..5415ca6516 100644 --- a/core/src/epicli/data/common/ansible/playbooks/roles/postgresql/tasks/extensions/replication/extension.yml +++ b/core/src/epicli/data/common/ansible/playbooks/roles/postgresql/tasks/extensions/replication/extension.yml @@ -21,19 +21,23 @@ /bin/systemctl stop {{ repmgr.service_name[ansible_os_family] }} validate: 'visudo -cf %s' -- name: Extensions | repmgr | Create super user in postgresql - become_user: postgres - postgresql_user: - user: "{{ specification.extensions.replication.privileged_user_name }}" - password: "{{ specification.extensions.replication.privileged_user_password }}" - role_attr_flags: LOGIN,SUPERUSER -- name: Extensions | repmgr | Create replication user in postgresql +- name: Extensions | repmgr | Create super user and replication user in PostgreSQL become_user: postgres + vars: + _users: + - user: "{{ specification.extensions.replication.privileged_user_name }}" + password: "{{ specification.extensions.replication.privileged_user_password }}" + role_attr_flags: LOGIN,SUPERUSER + - user: "{{ specification.extensions.replication.replication_user_name }}" + password: "{{ specification.extensions.replication.replication_user_password }}" + role_attr_flags: LOGIN,REPLICATION postgresql_user: - user: "{{ specification.extensions.replication.replication_user_name }}" - password: "{{ specification.extensions.replication.replication_user_password }}" - role_attr_flags: LOGIN,REPLICATION + user: "{{ item.user }}" + password: "{{ item.password }}" + role_attr_flags: "{{ item.role_attr_flags }}" + no_log: true + loop: "{{ _users }}" - name: Extensions | repmgr | Create pgpass file template: @@ -43,19 +47,7 @@ group: postgres mode: u=rw,g=,o= -- name: Extensions | repmgr | Add replication user to pg_hba.conf - lineinfile: - path: "{{ pg.config_dir[ansible_os_family] }}/pg_hba.conf" - line: "host replication {{ specification.extensions.replication.replication_user_name }} 0.0.0.0/0 md5" - register: modify_pg_hba_conf - -- name: Extensions | repmgr | Restart postgresql service - systemd: - name: "{{ pg.service_name[ansible_os_family] }}" - state: restarted - when: modify_pg_hba_conf.changed - - # --- Configure repmgr --- +# --- Configure repmgr --- - name: Extensions | repmgr | Create database for repmgr become_user: postgres @@ -113,50 +105,39 @@ regexp: ^[#]?REPMGRD_OPTS= line: REPMGRD_OPTS="--daemonize=false" -# --- Configure primary node --- - -- name: Extensions | repmgr | Tasks to run only on primary node - when: groups.postgresql[0] == inventory_hostname +- name: Extensions | repmgr | Get cluster status + become_user: postgres + command: "{{ repmgr.bin_dir[ansible_os_family] }}/repmgr cluster show --csv" + register: pg_cluster_status + changed_when: false + failed_when: + # rc = 25 means that there is an error with at least one registered node + - pg_cluster_status.rc not in [0, 25] + # do not fail when repmgr is not initialized yet + - pg_cluster_status.stderr is not search("relation \"repmgr.nodes\" does not exist") + +# 1. There is a preflight check that no more than 2 cluster nodes are supported +# 2. rc = 25 means that there is an error with at least one registered node +# sometimes 'repmgr cluster show' returns 25 code with empty stderr and no explanation +- name: Extensions | repmgr | Set 'pg_is_clustered' fact + set_fact: + pg_is_clustered: "{{ pg_cluster_status.rc in [0, 25] and pg_cluster_status.stdout_lines | length > 1 }}" + +- name: Extensions | repmgr | Configure PostgreSQL cluster + when: not pg_is_clustered + vars: + pg_node_primary: "{{ groups.postgresql[0] }}" # the first node in the group is primary block: - - name: Extensions | repmgr | Check if primary node is already registered in repmgr cluster - become_user: postgres - shell: >- - set -o pipefail && - {{ repmgr.bin_dir[ansible_os_family] }}/repmgr cluster show | grep -iw {{ inventory_hostname }} | grep -vw standby - changed_when: false - register: is_primary_already_registered - failed_when: is_primary_already_registered.rc not in [0, 1] - - name: Extensions | repmgr | Register primary node - when: is_primary_already_registered.stdout == "" - block: - - name: Register primary node - become_user: postgres - command: >- - {{ repmgr.bin_dir[ansible_os_family] }}/repmgr primary register - --superuser={{ specification.extensions.replication.privileged_user_name }} --force - - - name: Extensions | repmgr | Restart repmgrd service - service: - name: "{{ repmgr.service_name[ansible_os_family] }}" - state: restarted - -# --- Configure standby node --- - -- name: Extensions | repmgr | Tasks to run only on standby node - when: groups.postgresql[1] == inventory_hostname - block: - - name: Extensions | repmgr | Check if node is already registered in repmgr cluster + when: pg_node_primary == inventory_hostname become_user: postgres - shell: >- - set -o pipefail && - {{ repmgr.bin_dir[ansible_os_family] }}/repmgr cluster show | grep -iw {{ inventory_hostname }} - changed_when: false - register: is_node_already_registered - failed_when: is_node_already_registered.rc not in [0, 1] + command: >- + {{ repmgr.bin_dir[ansible_os_family] }}/repmgr primary register + --superuser={{ specification.extensions.replication.privileged_user_name }} + --force - - name: Extensions | repmgr | Clone node from primary and register - when: is_node_already_registered.stdout == "" + - name: Extensions | repmgr | Clone standby node from primary and register + when: pg_node_primary != inventory_hostname block: # Ubuntu specific: there are two systemd unit files: postgresql.service (service for managing all clusters # on system) and postgresql@.service (service template for clusters). The latter is 'PartOf' the former. @@ -164,7 +145,7 @@ # from 'repmgr standby clone'. - name: Extensions | repmgr | Stop postgresql service systemd: - name: "{{ item }}" + name: "{{ service_name }}" state: stopped vars: _services: @@ -173,17 +154,19 @@ - "{{ pg.instantiated_service_name['Debian'] }}" RedHat: - "{{ pg.service_name['RedHat'] }}" + loop_control: + loop_var: service_name loop: "{{ _services[ansible_os_family] }}" - - name: Extensions | repmgr | Clone node with repmgr + - name: Extensions | repmgr | Clone standby node with repmgr become_user: postgres command: >- {{ repmgr.bin_dir[ansible_os_family] }}/repmgr standby clone - -h {{ hostvars[groups.postgresql[0]].ansible_default_ipv4.address }} - -U {{ specification.extensions.replication.privileged_user_name }} - -d {{ specification.extensions.replication.repmgr_database }} -p 5432 --force + -h {{ hostvars[groups.postgresql[0]].ansible_default_ipv4.address }} + -U {{ specification.extensions.replication.privileged_user_name }} + -d {{ specification.extensions.replication.repmgr_database }} -p 5432 --force - - name: Extensions | repmgr | Start postgresql service + - name: Extensions | repmgr | Start PostgreSQL service systemd: name: "{{ pg.service_name[ansible_os_family] }}" state: started @@ -192,37 +175,42 @@ become_user: postgres command: >- {{ repmgr.bin_dir[ansible_os_family] }}/repmgr standby register --force - -f {{ repmgr.config_dir[ansible_os_family] }}/repmgr.conf --upstream-conninfo='host={{ hostvars[groups['postgresql'][0]]['ansible_default_ipv4']['address'] }}, - user={{ specification.extensions.replication.replication_user_name }}, - dbname={{ specification.extensions.replication.repmgr_database }}, - connect_timeout=2' + user={{ specification.extensions.replication.replication_user_name }}, + dbname={{ specification.extensions.replication.repmgr_database }}, + connect_timeout=2' --upstream-node-id 1 - - name: Extensions | repmgr | Restart repmgrd service - systemd: - name: "{{ repmgr.service_name[ansible_os_family] }}" - state: restarted + - name: Extensions | repmgr | Restart and enable repmgr service + systemd: + name: "{{ repmgr.service_name[ansible_os_family] }}" + state: restarted + enabled: true - - name: Extensions | repmgr | Check if node is not attached to repmgr +- name: Extensions | repmgr | Check already configured cluster + when: pg_is_clustered + block: + - name: Extensions | repmgr | Search for a primary node become_user: postgres - shell: >- - set -o pipefail && - {{ repmgr.bin_dir[ansible_os_family] }}/repmgr cluster show | grep -i 'not attached to its upstream node' + shell: |- + set -o pipefail && \ + {{ repmgr.bin_dir[ansible_os_family] }}/repmgr cluster show \ + | awk 'BEGIN{FS="|"} {gsub(/ /,""); if ($3 == "primary") print $2}' changed_when: false - register: is_node_not_attached - failed_when: is_node_not_attached.rc not in [0, 1] + register: pg_node_primary_found + failed_when: pg_node_primary_found.rc != 0 or pg_node_primary_found.stdout == "" - - name: Extensions | repmgr | Attach active standby to current primary node - become: true - become_user: postgres - become_method: sudo - command: "{{ repmgr.bin_dir[ansible_os_family] }}/repmgr standby follow" - when: - - is_node_not_attached.stdout | length > 0 - -- name: Extensions | repmgr | Restart repmgr service - service: - name: "{{ repmgr.service_name[ansible_os_family] }}" - state: restarted - enabled: true + - name: Extensions | repmgr | Tasks to run only on standby node + when: pg_node_primary_found.stdout != inventory_hostname + block: + - name: Extensions | repmgr | Check if node is not attached to repmgr + become_user: postgres + command: "{{ repmgr.bin_dir[ansible_os_family] }}/repmgr cluster show" + changed_when: false + register: pg_cluster_status + failed_when: pg_cluster_status.rc not in [0, 25] + + - name: Extensions | repmgr | Attach active standby to current primary node + when: "'not attached to its upstream node' in pg_cluster_status.stdout|lower" + become_user: postgres + command: "{{ repmgr.bin_dir[ansible_os_family] }}/repmgr standby follow" diff --git a/core/src/epicli/data/common/ansible/playbooks/roles/postgresql/tasks/extensions/replication/packages.yml b/core/src/epicli/data/common/ansible/playbooks/roles/postgresql/tasks/extensions/replication/packages.yml index 2e227aaae3..9f97d357f5 100644 --- a/core/src/epicli/data/common/ansible/playbooks/roles/postgresql/tasks/extensions/replication/packages.yml +++ b/core/src/epicli/data/common/ansible/playbooks/roles/postgresql/tasks/extensions/replication/packages.yml @@ -6,9 +6,9 @@ vars: _packages: Debian: - - postgresql-10-repmgr={{ repmgr.version.Debian + '-*' }} + - postgresql-13-repmgr={{ repmgr.version.Debian + '-*' }} - repmgr-common={{ repmgr.version.Debian + '-*' }} RedHat: - - repmgr10-{{ repmgr.version.RedHat }} + - repmgr13-{{ repmgr.version.RedHat }} module_defaults: yum: { lock_timeout: "{{ yum_lock_timeout }}" } diff --git a/core/src/epicli/data/common/ansible/playbooks/roles/postgresql/tasks/main.yml b/core/src/epicli/data/common/ansible/playbooks/roles/postgresql/tasks/main.yml index abe9a5731e..8674729a3e 100644 --- a/core/src/epicli/data/common/ansible/playbooks/roles/postgresql/tasks/main.yml +++ b/core/src/epicli/data/common/ansible/playbooks/roles/postgresql/tasks/main.yml @@ -1,20 +1,41 @@ --- -- name: Set facts +- name: Set 'enabled_extensions' fact set_fact: enabled_extensions: >- - {{ (_defined_extensions | selectattr('config.enabled') | list) + _undefined_extensions }} + {{ _defined_enabled_extensions + _undefined_extensions }} vars: - _defined_extensions: >- + _defined_enabled_extensions: >- {{ specification.extensions | dict2items(key_name='name', value_name='config') | selectattr('config.enabled', 'defined') + | selectattr('config.enabled') + | map(attribute='name') | list }} _undefined_extensions: >- {{ specification.extensions | dict2items(key_name='name', value_name='config') | selectattr('config.enabled', 'undefined') + | map(attribute='name') | list }} +- name: Check if repmgr.conf exists + stat: + path: "{{ repmgr.config_dir[ansible_os_family] }}/repmgr.conf" + register: repmgr_conf + +- name: Get node id + when: repmgr_conf.stat.exists + command: >- + grep -Po '(?<=^node_id=)\d+' "{{ repmgr.config_dir[ansible_os_family] }}/repmgr.conf" + register: repmgr_pg_node_id + changed_when: false + +# Node id is a constant value independent on order in Ansible host group +- name: Set 'pg_node_id' fact + set_fact: + pg_node_id: >- + {{ repmgr_conf.stat.exists | ternary(repmgr_pg_node_id.stdout, groups.postgresql.index(inventory_hostname) + 1) }} + - name: Install OS-specific packages package: name: "{{ _packages[ansible_os_family] }}" @@ -22,112 +43,109 @@ vars: _packages: Debian: - - postgresql-10 - - postgresql-contrib-10 - - python-psycopg2 # required for postgresql ansible management + - postgresql-client-common + - postgresql-common + - postgresql-client-13 + - postgresql-13 + - python-psycopg2 # required for PostgreSQL ansible management RedHat: - - postgresql10-server - - python-psycopg2 # required for postgresql ansible management + - postgresql13-server + - python-psycopg2 # required for PostgreSQL ansible management module_defaults: yum: { lock_timeout: "{{ yum_lock_timeout }}" } # Extension packages need to be installed first to be able to process PostgreSQL config - name: Install extension packages - include_tasks: extensions/{{ data.name }}/packages.yml + include_tasks: extensions/{{ extension }}/packages.yml loop_control: - loop_var: data + loop_var: extension loop: "{{ enabled_extensions }}" -- name: Create directory /var/log/postgresql - # The same permissions as for PG installed on RHEL from Software Collections (different on Ubuntu) +- name: Create directories and ensure correct permissions file: - path: /var/log/postgresql + path: "{{ path }}" state: directory owner: postgres group: postgres mode: u=rwx,g=,o= + loop_control: + loop_var: path + loop: + - /var/log/postgresql + - "{{ pg.data_dir[ansible_os_family] }}" # Permissions should be u=rwx (0700) or u=rwx,g=rx (0750) - name: RedHat | Initialize database + when: ansible_os_family == 'RedHat' block: - - name: Check initialization status (RedHat) + - name: RedHat | Check initialization status stat: path: "{{ pg.config_dir[ansible_os_family] }}/pg_hba.conf" register: pg_hba_conf_stat - - name: Initialize database (RedHat) - command: /usr/pgsql-10/bin/postgresql-10-setup initdb {{ pg.service_name[ansible_os_family] }} - when: - - not pg_hba_conf_stat.stat.exists - when: - - ansible_os_family == 'RedHat' + - name: RedHat | Initialize database + become_user: postgres + when: not pg_hba_conf_stat.stat.exists + command: "{{ pg.bin_dir[ansible_os_family] }}/initdb" + environment: + PGDATA: "{{ pg.data_dir[ansible_os_family] }}" -- name: Change pg_hba.conf - replace: - path: "{{ pg.config_dir[ansible_os_family] }}/pg_hba.conf" - regexp: '^host\s+all\s+all\s+127\.0\.0\.1/32\s+(?:ident|md5)$' - replace: 'host all all 0.0.0.0/0 md5' - backup: true - register: change_pg_hba_conf +- name: Start and enable PostgreSQL service + block: + - name: Start and enable PostgreSQL service + systemd: + name: "{{ pg.service_name[ansible_os_family] }}" + state: started + enabled: true + + - &ensure-debian-child-service-started + name: Debian | Ensure that instantiated service started + when: ansible_os_family == 'Debian' + systemd: + name: "{{ pg.instantiated_service_name[ansible_os_family] }}" + state: started # Used in postgresql-epiphany.conf.j2 - name: Set runtime_shared_preload_libraries fact block: - - name: Collect facts about system services - service_facts: - register: services_state - - name: Get PostgreSQL settings - become: true become_user: postgres - vars: - _service: "{{ pg.service_name[ansible_os_family] }}.service" - _state: "{{ ansible_facts.services[_service] }}" postgresql_info: filter: settings register: postgresql_info - when: - - "_service|string in ansible_facts.services" - - "_state|string == 'started'" - name: Set runtime_shared_preload_libraries fact set_fact: runtime_shared_preload_libraries: "{{ postgresql_info.settings.shared_preload_libraries.setting }}" - when: - - postgresql_info.settings is defined -- name: Create Epiphany managed configuration sub-file +- name: Copy PostgreSQL configuration files + vars: + _files: + - pg_hba.conf + - postgresql-epiphany.conf + - postgresql.conf template: - src: postgresql-epiphany.conf.j2 - dest: "{{ pg.config_dir[ansible_os_family] }}/postgresql-epiphany.conf" + src: "{{ file_name }}.j2" + dest: "{{ pg.config_dir[ansible_os_family] }}/{{ file_name }}" owner: postgres group: postgres mode: u=rw,g=,o= - register: change_postgresql_epiphany_conf - -- name: Change postgresql.conf - lineinfile: - path: "{{ pg.config_dir[ansible_os_family] }}/postgresql.conf" - line: "include = 'postgresql-epiphany.conf' # Epiphany managed configuration that overrides above settings" - insertafter: '^#include ' # insert line after the last 'include' to override all settings - firstmatch: false backup: true - register: change_postgresql_conf - -- name: Restart postgresql service if configuration changed - systemd: - name: "{{ pg.service_name[ansible_os_family] }}" - state: restarted - when: change_pg_hba_conf - or change_postgresql_epiphany_conf - or change_postgresql_conf - -# This is a separate task as service restart runs not each time -- name: Enable postgresql service - systemd: - name: "{{ pg.service_name[ansible_os_family] }}" - enabled: true - -- name: Configure postgresql logrotate + loop_control: + loop_var: file_name + loop: "{{ _files }}" + register: change_pg_config + +- name: Restart PostgreSQL service if configuration changed + block: + - name: Restart PostgreSQL service if configuration changed + systemd: + name: "{{ pg.service_name[ansible_os_family] }}" + state: restarted + + - *ensure-debian-child-service-started + when: (change_pg_config.results | map(attribute='changed') | list) is any + +- name: Configure PostgreSQL logrotate block: - name: Remove logrotate configuration provided by 'postgresql-common' package file: @@ -135,7 +153,7 @@ state: absent when: ansible_os_family == 'Debian' - - name: Create postgresql logrotate configuration file + - name: Create PostgreSQL logrotate configuration file template: src: logrotate-postgresql.conf.j2 dest: /etc/logrotate.d/postgresql @@ -144,32 +162,41 @@ mode: u=rw,g=r,o=r - name: Include extensions - include_tasks: extensions/{{ data.name }}/extension.yml + include_tasks: extensions/{{ extension }}/extension.yml loop_control: - loop_var: data + loop_var: extension loop: "{{ enabled_extensions }}" # PgPool is configured only if such K8s application is enabled - name: Extensions | Set up PgPool block: - - name: Extensions | Include PgPool vars from applications role - include_vars: - file: roles/applications/vars/main.yml - name: applications_role_config - when: - - "'applications' in roles_with_generated_vars" - - - name: Extensions | Include PgPool setup tasks - include_tasks: extensions/pgpool/extension.yml - vars: - pgpool: >- - {{ applications_role_config.specification.applications | default([]) - | selectattr("name", "equalto", "pgpool") - | selectattr('enabled') - | map(attribute='pgpool') - | list - | first - | default({}) }} + - name: Extensions | Set up PgPool | Determine primary node + become_user: postgres + postgresql_info: + filter: in_recovery + register: in_recovery_state + + - name: Extensions | Set up PgPool | Create configuration + block: + - name: Extensions | Include PgPool vars from applications role + include_vars: + file: roles/applications/vars/main.yml + name: applications_role_config + when: + - "'applications' in roles_with_generated_vars" + + - name: Extensions | Include PgPool setup tasks + include_tasks: extensions/pgpool/extension.yml + vars: + pgpool: >- + {{ applications_role_config.specification.applications | default([]) + | selectattr("name", "equalto", "pgpool") + | selectattr('enabled') + | map(attribute='pgpool') + | list + | first + | default({}) }} when: - - pgpool.env is defined - - groups['postgresql'][0] == inventory_hostname + - not in_recovery_state.in_recovery + when: + - pgpool.env is defined diff --git a/core/src/epicli/data/common/ansible/playbooks/roles/postgresql/tasks/upgrade/extensions/replication/repmgr-main.yml b/core/src/epicli/data/common/ansible/playbooks/roles/postgresql/tasks/upgrade/extensions/replication/repmgr-main.yml index a4f1a4afb1..5dd873338f 100644 --- a/core/src/epicli/data/common/ansible/playbooks/roles/postgresql/tasks/upgrade/extensions/replication/repmgr-main.yml +++ b/core/src/epicli/data/common/ansible/playbooks/roles/postgresql/tasks/upgrade/extensions/replication/repmgr-main.yml @@ -32,6 +32,6 @@ register: stat_upgrade_state_file - name: repmgr for PG {{ pg_version }} | Upgrade repmgr - include_tasks: upgrade/extensions/replication/repmgr-upgrade.yml + include_tasks: roles/postgresql/tasks/upgrade/extensions/replication/repmgr-upgrade.yml when: target_version is version(installed_version, '>') or stat_upgrade_state_file.stat.exists diff --git a/core/src/epicli/data/common/ansible/playbooks/roles/postgresql/templates/pg_hba.conf.j2 b/core/src/epicli/data/common/ansible/playbooks/roles/postgresql/templates/pg_hba.conf.j2 new file mode 100755 index 0000000000..877a04a32d --- /dev/null +++ b/core/src/epicli/data/common/ansible/playbooks/roles/postgresql/templates/pg_hba.conf.j2 @@ -0,0 +1,99 @@ +# {{ ansible_managed }} +# =================================================== +# PostgreSQL Client Authentication Configuration File +# =================================================== +# +# Refer to the "Client Authentication" section in the PostgreSQL +# documentation for a complete description of this file. A short +# synopsis follows. +# +# This file controls: which hosts are allowed to connect, how clients +# are authenticated, which PostgreSQL user names they can use, which +# databases they can access. Records take one of these forms: +# +# local DATABASE USER METHOD [OPTIONS] +# host DATABASE USER ADDRESS METHOD [OPTIONS] +# hostssl DATABASE USER ADDRESS METHOD [OPTIONS] +# hostnossl DATABASE USER ADDRESS METHOD [OPTIONS] +# hostgssenc DATABASE USER ADDRESS METHOD [OPTIONS] +# hostnogssenc DATABASE USER ADDRESS METHOD [OPTIONS] +# +# (The uppercase items must be replaced by actual values.) +# +# The first field is the connection type: "local" is a Unix-domain +# socket, "host" is either a plain or SSL-encrypted TCP/IP socket, +# "hostssl" is an SSL-encrypted TCP/IP socket, and "hostnossl" is a +# non-SSL TCP/IP socket. Similarly, "hostgssenc" uses a +# GSSAPI-encrypted TCP/IP socket, while "hostnogssenc" uses a +# non-GSSAPI socket. +# +# DATABASE can be "all", "sameuser", "samerole", "replication", a +# database name, or a comma-separated list thereof. The "all" +# keyword does not match "replication". Access to replication +# must be enabled in a separate record (see example below). +# +# USER can be "all", a user name, a group name prefixed with "+", or a +# comma-separated list thereof. In both the DATABASE and USER fields +# you can also write a file name prefixed with "@" to include names +# from a separate file. +# +# ADDRESS specifies the set of hosts the record matches. It can be a +# host name, or it is made up of an IP address and a CIDR mask that is +# an integer (between 0 and 32 (IPv4) or 128 (IPv6) inclusive) that +# specifies the number of significant bits in the mask. A host name +# that starts with a dot (.) matches a suffix of the actual host name. +# Alternatively, you can write an IP address and netmask in separate +# columns to specify the set of hosts. Instead of a CIDR-address, you +# can write "samehost" to match any of the server's own IP addresses, +# or "samenet" to match any address in any subnet that the server is +# directly connected to. +# +# METHOD can be "trust", "reject", "md5", "password", "scram-sha-256", +# "gss", "sspi", "ident", "peer", "pam", "ldap", "radius" or "cert". +# Note that "password" sends passwords in clear text; "md5" or +# "scram-sha-256" are preferred since they send encrypted passwords. +# +# OPTIONS are a set of options for the authentication in the format +# NAME=VALUE. The available options depend on the different +# authentication methods -- refer to the "Client Authentication" +# section in the documentation for a list of which options are +# available for which authentication methods. +# +# Database and user names containing spaces, commas, quotes and other +# special characters must be quoted. Quoting one of the keywords +# "all", "sameuser", "samerole" or "replication" makes the name lose +# its special character, and just match a database or username with +# that name. +# +# This file is read on server startup and when the server receives a +# SIGHUP signal. If you edit the file on a running system, you have to +# SIGHUP the server for the changes to take effect, run "pg_ctl reload", +# or execute "SELECT pg_reload_conf()". +# +# Put your actual configuration here +# ---------------------------------- +# +# If you want to allow non-local connections, you need to add more +# "host" records. In that case you will also need to make PostgreSQL +# listen on a non-local interface via the listen_addresses +# configuration parameter, or via the -i or -h command line switches. + + + +# TYPE DATABASE USER ADDRESS METHOD + +# "local" is for Unix domain socket connections only +local all all peer +# IPv4 connections: +host all all 0.0.0.0/0 scram-sha-256 +# IPv6 local connections: +host all all ::1/128 scram-sha-256 +# Allow replication connections from localhost, by a user with the +# replication privilege. +local replication all peer +host replication all 127.0.0.1/32 scram-sha-256 +host replication all ::1/128 scram-sha-256 + +{% if specification.extensions.replication.enabled | default(false) %} +host replication {{ specification.extensions.replication.replication_user_name }} 0.0.0.0/0 scram-sha-256 +{% endif %} diff --git a/core/src/epicli/data/common/ansible/playbooks/roles/postgresql/templates/pgpass-repmgr.j2 b/core/src/epicli/data/common/ansible/playbooks/roles/postgresql/templates/pgpass-repmgr.j2 index e6009a74e6..1bd621a623 100644 --- a/core/src/epicli/data/common/ansible/playbooks/roles/postgresql/templates/pgpass-repmgr.j2 +++ b/core/src/epicli/data/common/ansible/playbooks/roles/postgresql/templates/pgpass-repmgr.j2 @@ -1,2 +1,4 @@ +# {{ ansible_managed }} + *:*:*:{{ specification.extensions.replication.replication_user_name }}:{{ specification.extensions.replication.replication_user_password }} *:*:*:{{ specification.extensions.replication.privileged_user_name }}:{{ specification.extensions.replication.privileged_user_password }} diff --git a/core/src/epicli/data/common/ansible/playbooks/roles/postgresql/templates/postgresql.conf.j2 b/core/src/epicli/data/common/ansible/playbooks/roles/postgresql/templates/postgresql.conf.j2 new file mode 100755 index 0000000000..58723ba70c --- /dev/null +++ b/core/src/epicli/data/common/ansible/playbooks/roles/postgresql/templates/postgresql.conf.j2 @@ -0,0 +1,781 @@ +# {{ ansible_managed }} +# ----------------------------- +# PostgreSQL configuration file +# ----------------------------- +# +# This file consists of lines of the form: +# +# name = value +# +# (The "=" is optional.) Whitespace may be used. Comments are introduced with +# "#" anywhere on a line. The complete list of parameter names and allowed +# values can be found in the PostgreSQL documentation. +# +# The commented-out settings shown in this file represent the default values. +# Re-commenting a setting is NOT sufficient to revert it to the default value; +# you need to reload the server. +# +# This file is read on server startup and when the server receives a SIGHUP +# signal. If you edit the file on a running system, you have to SIGHUP the +# server for the changes to take effect, run "pg_ctl reload", or execute +# "SELECT pg_reload_conf()". Some parameters, which are marked below, +# require a server shutdown and restart to take effect. +# +# Any parameter can also be given as a command-line option to the server, e.g., +# "postgres -c log_connections=on". Some parameters can be changed at run time +# with the "SET" SQL command. +# +# Memory units: kB = kilobytes Time units: ms = milliseconds +# MB = megabytes s = seconds +# GB = gigabytes min = minutes +# TB = terabytes h = hours +# d = days + + +#------------------------------------------------------------------------------ +# FILE LOCATIONS +#------------------------------------------------------------------------------ + +# The default values of these variables are driven from the -D command-line +# option or PGDATA environment variable, represented here as ConfigDir. + +data_directory = '{{ pg.data_dir[ansible_os_family] }}' # use data in another directory + # (change requires restart) +#hba_file = 'ConfigDir/pg_hba.conf' # host-based authentication file + # (change requires restart) +#ident_file = 'ConfigDir/pg_ident.conf' # ident configuration file + # (change requires restart) + +# If external_pid_file is not explicitly set, no extra PID file is written. +#external_pid_file = '' # write an extra PID file + # (change requires restart) + + +#------------------------------------------------------------------------------ +# CONNECTIONS AND AUTHENTICATION +#------------------------------------------------------------------------------ + +# - Connection Settings - + +listen_addresses = '*' # what IP address(es) to listen on; + # comma-separated list of addresses; + # defaults to 'localhost'; use '*' for all + # (change requires restart) +#port = 5432 # (change requires restart) +max_connections = 100 # (change requires restart) +#superuser_reserved_connections = 3 # (change requires restart) +#unix_socket_directories = '/var/run/postgresql, /tmp' # comma-separated list of directories + # (change requires restart) +#unix_socket_group = '' # (change requires restart) +#unix_socket_permissions = 0777 # begin with 0 to use octal notation + # (change requires restart) +#bonjour = off # advertise server via Bonjour + # (change requires restart) +#bonjour_name = '' # defaults to the computer name + # (change requires restart) + +# - TCP settings - +# see "man tcp" for details + +#tcp_keepalives_idle = 0 # TCP_KEEPIDLE, in seconds; + # 0 selects the system default +#tcp_keepalives_interval = 0 # TCP_KEEPINTVL, in seconds; + # 0 selects the system default +#tcp_keepalives_count = 0 # TCP_KEEPCNT; + # 0 selects the system default +#tcp_user_timeout = 0 # TCP_USER_TIMEOUT, in milliseconds; + # 0 selects the system default + +# - Authentication - + +#authentication_timeout = 1min # 1s-600s +password_encryption = scram-sha-256 # md5 or scram-sha-256 +#db_user_namespace = off + +# GSSAPI using Kerberos +#krb_server_keyfile = 'FILE:${sysconfdir}/krb5.keytab' +#krb_caseins_users = off + +# - SSL - + +#ssl = off +#ssl_ca_file = '' +#ssl_cert_file = 'server.crt' +#ssl_crl_file = '' +#ssl_key_file = 'server.key' +#ssl_ciphers = 'HIGH:MEDIUM:+3DES:!aNULL' # allowed SSL ciphers +#ssl_prefer_server_ciphers = on +#ssl_ecdh_curve = 'prime256v1' +#ssl_min_protocol_version = 'TLSv1.2' +#ssl_max_protocol_version = '' +#ssl_dh_params_file = '' +#ssl_passphrase_command = '' +#ssl_passphrase_command_supports_reload = off + + +#------------------------------------------------------------------------------ +# RESOURCE USAGE (except WAL) +#------------------------------------------------------------------------------ + +# - Memory - + +shared_buffers = 128MB # min 128kB + # (change requires restart) +#huge_pages = try # on, off, or try + # (change requires restart) +#temp_buffers = 8MB # min 800kB +#max_prepared_transactions = 0 # zero disables the feature + # (change requires restart) +# Caution: it is not advisable to set max_prepared_transactions nonzero unless +# you actively intend to use prepared transactions. +#work_mem = 4MB # min 64kB +#hash_mem_multiplier = 1.0 # 1-1000.0 multiplier on hash table work_mem +#maintenance_work_mem = 64MB # min 1MB +#autovacuum_work_mem = -1 # min 1MB, or -1 to use maintenance_work_mem +#logical_decoding_work_mem = 64MB # min 64kB +#max_stack_depth = 2MB # min 100kB +#shared_memory_type = mmap # the default is the first option + # supported by the operating system: + # mmap + # sysv + # windows + # (change requires restart) +dynamic_shared_memory_type = posix # the default is the first option + # supported by the operating system: + # posix + # sysv + # windows + # mmap + # (change requires restart) + +# - Disk - + +#temp_file_limit = -1 # limits per-process temp file space + # in kilobytes, or -1 for no limit + +# - Kernel Resources - + +#max_files_per_process = 1000 # min 64 + # (change requires restart) + +# - Cost-Based Vacuum Delay - + +#vacuum_cost_delay = 0 # 0-100 milliseconds (0 disables) +#vacuum_cost_page_hit = 1 # 0-10000 credits +#vacuum_cost_page_miss = 10 # 0-10000 credits +#vacuum_cost_page_dirty = 20 # 0-10000 credits +#vacuum_cost_limit = 200 # 1-10000 credits + +# - Background Writer - + +#bgwriter_delay = 200ms # 10-10000ms between rounds +#bgwriter_lru_maxpages = 100 # max buffers written/round, 0 disables +#bgwriter_lru_multiplier = 2.0 # 0-10.0 multiplier on buffers scanned/round +#bgwriter_flush_after = 512kB # measured in pages, 0 disables + +# - Asynchronous Behavior - + +#effective_io_concurrency = 1 # 1-1000; 0 disables prefetching +#maintenance_io_concurrency = 10 # 1-1000; 0 disables prefetching +#max_worker_processes = 8 # (change requires restart) +#max_parallel_maintenance_workers = 2 # taken from max_parallel_workers +#max_parallel_workers_per_gather = 2 # taken from max_parallel_workers +#parallel_leader_participation = on +#max_parallel_workers = 8 # maximum number of max_worker_processes that + # can be used in parallel operations +#old_snapshot_threshold = -1 # 1min-60d; -1 disables; 0 is immediate + # (change requires restart) +#backend_flush_after = 0 # measured in pages, 0 disables + + +#------------------------------------------------------------------------------ +# WRITE-AHEAD LOG +#------------------------------------------------------------------------------ + +# - Settings - + +#wal_level = replica # minimal, replica, or logical + # (change requires restart) +#fsync = on # flush data to disk for crash safety + # (turning this off can cause + # unrecoverable data corruption) +#synchronous_commit = on # synchronization level; + # off, local, remote_write, remote_apply, or on +#wal_sync_method = fsync # the default is the first option + # supported by the operating system: + # open_datasync + # fdatasync (default on Linux and FreeBSD) + # fsync + # fsync_writethrough + # open_sync +#full_page_writes = on # recover from partial page writes +#wal_compression = off # enable compression of full-page writes +#wal_log_hints = off # also do full page writes of non-critical updates + # (change requires restart) +#wal_init_zero = on # zero-fill new WAL files +#wal_recycle = on # recycle WAL files +#wal_buffers = -1 # min 32kB, -1 sets based on shared_buffers + # (change requires restart) +#wal_writer_delay = 200ms # 1-10000 milliseconds +#wal_writer_flush_after = 1MB # measured in pages, 0 disables +#wal_skip_threshold = 2MB + +#commit_delay = 0 # range 0-100000, in microseconds +#commit_siblings = 5 # range 1-1000 + +# - Checkpoints - + +#checkpoint_timeout = 5min # range 30s-1d +max_wal_size = 1GB +min_wal_size = 80MB +#checkpoint_completion_target = 0.5 # checkpoint target duration, 0.0 - 1.0 +#checkpoint_flush_after = 256kB # measured in pages, 0 disables +#checkpoint_warning = 30s # 0 disables + +# - Archiving - + +#archive_mode = off # enables archiving; off, on, or always + # (change requires restart) +#archive_command = '' # command to use to archive a logfile segment + # placeholders: %p = path of file to archive + # %f = file name only + # e.g. 'test ! -f /mnt/server/archivedir/%f && cp %p /mnt/server/archivedir/%f' +#archive_timeout = 0 # force a logfile segment switch after this + # number of seconds; 0 disables + +# - Archive Recovery - + +# These are only used in recovery mode. + +#restore_command = '' # command to use to restore an archived logfile segment + # placeholders: %p = path of file to restore + # %f = file name only + # e.g. 'cp /mnt/server/archivedir/%f %p' + # (change requires restart) +#archive_cleanup_command = '' # command to execute at every restartpoint +#recovery_end_command = '' # command to execute at completion of recovery + +# - Recovery Target - + +# Set these only when performing a targeted recovery. + +#recovery_target = '' # 'immediate' to end recovery as soon as a + # consistent state is reached + # (change requires restart) +#recovery_target_name = '' # the named restore point to which recovery will proceed + # (change requires restart) +#recovery_target_time = '' # the time stamp up to which recovery will proceed + # (change requires restart) +#recovery_target_xid = '' # the transaction ID up to which recovery will proceed + # (change requires restart) +#recovery_target_lsn = '' # the WAL LSN up to which recovery will proceed + # (change requires restart) +#recovery_target_inclusive = on # Specifies whether to stop: + # just after the specified recovery target (on) + # just before the recovery target (off) + # (change requires restart) +#recovery_target_timeline = 'latest' # 'current', 'latest', or timeline ID + # (change requires restart) +#recovery_target_action = 'pause' # 'pause', 'promote', 'shutdown' + # (change requires restart) + + +#------------------------------------------------------------------------------ +# REPLICATION +#------------------------------------------------------------------------------ + +# - Sending Servers - + +# Set these on the master and on any standby that will send replication data. + +#max_wal_senders = 10 # max number of walsender processes + # (change requires restart) +#wal_keep_size = 0 # in megabytes; 0 disables +#max_slot_wal_keep_size = -1 # in megabytes; -1 disables +#wal_sender_timeout = 60s # in milliseconds; 0 disables + +#max_replication_slots = 10 # max number of replication slots + # (change requires restart) +#track_commit_timestamp = off # collect timestamp of transaction commit + # (change requires restart) + +# - Master Server - + +# These settings are ignored on a standby server. + +#synchronous_standby_names = '' # standby servers that provide sync rep + # method to choose sync standbys, number of sync standbys, + # and comma-separated list of application_name + # from standby(s); '*' = all +#vacuum_defer_cleanup_age = 0 # number of xacts by which cleanup is delayed + +# - Standby Servers - + +# These settings are ignored on a master server. + +#primary_conninfo = '' # connection string to sending server +#primary_slot_name = '' # replication slot on sending server +#promote_trigger_file = '' # file name whose presence ends recovery +#hot_standby = on # "off" disallows queries during recovery + # (change requires restart) +#max_standby_archive_delay = 30s # max delay before canceling queries + # when reading WAL from archive; + # -1 allows indefinite delay +#max_standby_streaming_delay = 30s # max delay before canceling queries + # when reading streaming WAL; + # -1 allows indefinite delay +#wal_receiver_create_temp_slot = off # create temp slot if primary_slot_name + # is not set +#wal_receiver_status_interval = 10s # send replies at least this often + # 0 disables +#hot_standby_feedback = off # send info from standby to prevent + # query conflicts +#wal_receiver_timeout = 60s # time that receiver waits for + # communication from master + # in milliseconds; 0 disables +#wal_retrieve_retry_interval = 5s # time to wait before retrying to + # retrieve WAL after a failed attempt +#recovery_min_apply_delay = 0 # minimum delay for applying changes during recovery + +# - Subscribers - + +# These settings are ignored on a publisher. + +#max_logical_replication_workers = 4 # taken from max_worker_processes + # (change requires restart) +#max_sync_workers_per_subscription = 2 # taken from max_logical_replication_workers + + +#------------------------------------------------------------------------------ +# QUERY TUNING +#------------------------------------------------------------------------------ + +# - Planner Method Configuration - + +#enable_bitmapscan = on +#enable_hashagg = on +#enable_hashjoin = on +#enable_indexscan = on +#enable_indexonlyscan = on +#enable_material = on +#enable_mergejoin = on +#enable_nestloop = on +#enable_parallel_append = on +#enable_seqscan = on +#enable_sort = on +#enable_incremental_sort = on +#enable_tidscan = on +#enable_partitionwise_join = off +#enable_partitionwise_aggregate = off +#enable_parallel_hash = on +#enable_partition_pruning = on + +# - Planner Cost Constants - + +#seq_page_cost = 1.0 # measured on an arbitrary scale +#random_page_cost = 4.0 # same scale as above +#cpu_tuple_cost = 0.01 # same scale as above +#cpu_index_tuple_cost = 0.005 # same scale as above +#cpu_operator_cost = 0.0025 # same scale as above +#parallel_tuple_cost = 0.1 # same scale as above +#parallel_setup_cost = 1000.0 # same scale as above + +#jit_above_cost = 100000 # perform JIT compilation if available + # and query more expensive than this; + # -1 disables +#jit_inline_above_cost = 500000 # inline small functions if query is + # more expensive than this; -1 disables +#jit_optimize_above_cost = 500000 # use expensive JIT optimizations if + # query is more expensive than this; + # -1 disables + +#min_parallel_table_scan_size = 8MB +#min_parallel_index_scan_size = 512kB +#effective_cache_size = 4GB + +# - Genetic Query Optimizer - + +#geqo = on +#geqo_threshold = 12 +#geqo_effort = 5 # range 1-10 +#geqo_pool_size = 0 # selects default based on effort +#geqo_generations = 0 # selects default based on effort +#geqo_selection_bias = 2.0 # range 1.5-2.0 +#geqo_seed = 0.0 # range 0.0-1.0 + +# - Other Planner Options - + +#default_statistics_target = 100 # range 1-10000 +#constraint_exclusion = partition # on, off, or partition +#cursor_tuple_fraction = 0.1 # range 0.0-1.0 +#from_collapse_limit = 8 +#join_collapse_limit = 8 # 1 disables collapsing of explicit + # JOIN clauses +#force_parallel_mode = off +#jit = on # allow JIT compilation +#plan_cache_mode = auto # auto, force_generic_plan or + # force_custom_plan + + +#------------------------------------------------------------------------------ +# REPORTING AND LOGGING +#------------------------------------------------------------------------------ + +# - Where to Log - + +log_destination = 'stderr' # Valid values are combinations of + # stderr, csvlog, syslog, and eventlog, + # depending on platform. csvlog + # requires logging_collector to be on. + +# This is used when logging to stderr: +logging_collector = on # Enable capturing of stderr and csvlog + # into log files. Required to be on for + # csvlogs. + # (change requires restart) + +# These are only used if logging_collector is on: +log_directory = 'log' # directory where log files are written, + # can be absolute or relative to PGDATA +log_filename = 'postgresql-%a.log' # log file name pattern, + # can include strftime() escapes +#log_file_mode = 0600 # creation mode for log files, + # begin with 0 to use octal notation +log_truncate_on_rotation = on # If on, an existing log file with the + # same name as the new log file will be + # truncated rather than appended to. + # But such truncation only occurs on + # time-driven rotation, not on restarts + # or size-driven rotation. Default is + # off, meaning append to existing files + # in all cases. +log_rotation_age = 1d # Automatic rotation of logfiles will + # happen after that time. 0 disables. +log_rotation_size = 0 # Automatic rotation of logfiles will + # happen after that much log output. + # 0 disables. + +# These are relevant when logging to syslog: +#syslog_facility = 'LOCAL0' +#syslog_ident = 'postgres' +#syslog_sequence_numbers = on +#syslog_split_messages = on + +# This is only relevant when logging to eventlog (win32): +# (change requires restart) +#event_source = 'PostgreSQL' + +# - When to Log - + +#log_min_messages = warning # values in order of decreasing detail: + # debug5 + # debug4 + # debug3 + # debug2 + # debug1 + # info + # notice + # warning + # error + # log + # fatal + # panic + +#log_min_error_statement = error # values in order of decreasing detail: + # debug5 + # debug4 + # debug3 + # debug2 + # debug1 + # info + # notice + # warning + # error + # log + # fatal + # panic (effectively off) + +#log_min_duration_statement = -1 # -1 is disabled, 0 logs all statements + # and their durations, > 0 logs only + # statements running at least this number + # of milliseconds + +#log_min_duration_sample = -1 # -1 is disabled, 0 logs a sample of statements + # and their durations, > 0 logs only a sample of + # statements running at least this number + # of milliseconds; + # sample fraction is determined by log_statement_sample_rate + +#log_statement_sample_rate = 1.0 # fraction of logged statements exceeding + # log_min_duration_sample to be logged; + # 1.0 logs all such statements, 0.0 never logs + + +#log_transaction_sample_rate = 0.0 # fraction of transactions whose statements + # are logged regardless of their duration; 1.0 logs all + # statements from all transactions, 0.0 never logs + +# - What to Log - + +#debug_print_parse = off +#debug_print_rewritten = off +#debug_print_plan = off +#debug_pretty_print = on +#log_checkpoints = off +#log_connections = off +#log_disconnections = off +#log_duration = off +#log_error_verbosity = default # terse, default, or verbose messages +#log_hostname = off +log_line_prefix = '%m [%p] ' # special values: + # %a = application name + # %u = user name + # %d = database name + # %r = remote host and port + # %h = remote host + # %b = backend type + # %p = process ID + # %t = timestamp without milliseconds + # %m = timestamp with milliseconds + # %n = timestamp with milliseconds (as a Unix epoch) + # %i = command tag + # %e = SQL state + # %c = session ID + # %l = session line number + # %s = session start timestamp + # %v = virtual transaction ID + # %x = transaction ID (0 if none) + # %q = stop here in non-session + # processes + # %% = '%' + # e.g. '<%u%%%d> ' +#log_lock_waits = off # log lock waits >= deadlock_timeout +#log_parameter_max_length = -1 # when logging statements, limit logged + # bind-parameter values to N bytes; + # -1 means print in full, 0 disables +#log_parameter_max_length_on_error = 0 # when logging an error, limit logged + # bind-parameter values to N bytes; + # -1 means print in full, 0 disables +#log_statement = 'none' # none, ddl, mod, all +#log_replication_commands = off +#log_temp_files = -1 # log temporary files equal or larger + # than the specified size in kilobytes; + # -1 disables, 0 logs all temp files +log_timezone = 'UTC' + +#------------------------------------------------------------------------------ +# PROCESS TITLE +#------------------------------------------------------------------------------ + +#cluster_name = '' # added to process titles if nonempty + # (change requires restart) +#update_process_title = on + + +#------------------------------------------------------------------------------ +# STATISTICS +#------------------------------------------------------------------------------ + +# - Query and Index Statistics Collector - + +#track_activities = on +#track_counts = on +#track_io_timing = off +#track_functions = none # none, pl, all +#track_activity_query_size = 1024 # (change requires restart) +#stats_temp_directory = 'pg_stat_tmp' + + +# - Monitoring - + +#log_parser_stats = off +#log_planner_stats = off +#log_executor_stats = off +#log_statement_stats = off + + +#------------------------------------------------------------------------------ +# AUTOVACUUM +#------------------------------------------------------------------------------ + +#autovacuum = on # Enable autovacuum subprocess? 'on' + # requires track_counts to also be on. +#log_autovacuum_min_duration = -1 # -1 disables, 0 logs all actions and + # their durations, > 0 logs only + # actions running at least this number + # of milliseconds. +#autovacuum_max_workers = 3 # max number of autovacuum subprocesses + # (change requires restart) +#autovacuum_naptime = 1min # time between autovacuum runs +#autovacuum_vacuum_threshold = 50 # min number of row updates before + # vacuum +#autovacuum_vacuum_insert_threshold = 1000 # min number of row inserts + # before vacuum; -1 disables insert + # vacuums +#autovacuum_analyze_threshold = 50 # min number of row updates before + # analyze +#autovacuum_vacuum_scale_factor = 0.2 # fraction of table size before vacuum +#autovacuum_vacuum_insert_scale_factor = 0.2 # fraction of inserts over table + # size before insert vacuum +#autovacuum_analyze_scale_factor = 0.1 # fraction of table size before analyze +#autovacuum_freeze_max_age = 200000000 # maximum XID age before forced vacuum + # (change requires restart) +#autovacuum_multixact_freeze_max_age = 400000000 # maximum multixact age + # before forced vacuum + # (change requires restart) +#autovacuum_vacuum_cost_delay = 2ms # default vacuum cost delay for + # autovacuum, in milliseconds; + # -1 means use vacuum_cost_delay +#autovacuum_vacuum_cost_limit = -1 # default vacuum cost limit for + # autovacuum, -1 means use + # vacuum_cost_limit + + +#------------------------------------------------------------------------------ +# CLIENT CONNECTION DEFAULTS +#------------------------------------------------------------------------------ + +# - Statement Behavior - + +#client_min_messages = notice # values in order of decreasing detail: + # debug5 + # debug4 + # debug3 + # debug2 + # debug1 + # log + # notice + # warning + # error +#search_path = '"$user", public' # schema names +#row_security = on +#default_tablespace = '' # a tablespace name, '' uses the default +#temp_tablespaces = '' # a list of tablespace names, '' uses + # only default tablespace +#default_table_access_method = 'heap' +#check_function_bodies = on +#default_transaction_isolation = 'read committed' +#default_transaction_read_only = off +#default_transaction_deferrable = off +#session_replication_role = 'origin' +#statement_timeout = 0 # in milliseconds, 0 is disabled +#lock_timeout = 0 # in milliseconds, 0 is disabled +#idle_in_transaction_session_timeout = 0 # in milliseconds, 0 is disabled +#vacuum_freeze_min_age = 50000000 +#vacuum_freeze_table_age = 150000000 +#vacuum_multixact_freeze_min_age = 5000000 +#vacuum_multixact_freeze_table_age = 150000000 +#vacuum_cleanup_index_scale_factor = 0.1 # fraction of total number of tuples + # before index cleanup, 0 always performs + # index cleanup +#bytea_output = 'hex' # hex, escape +#xmlbinary = 'base64' +#xmloption = 'content' +#gin_fuzzy_search_limit = 0 +#gin_pending_list_limit = 4MB + +# - Locale and Formatting - + +datestyle = 'iso, mdy' +#intervalstyle = 'postgres' +timezone = 'UTC' +#timezone_abbreviations = 'Default' # Select the set of available time zone + # abbreviations. Currently, there are + # Default + # Australia (historical usage) + # India + # You can create your own file in + # share/timezonesets/. +#extra_float_digits = 1 # min -15, max 3; any value >0 actually + # selects precise output mode +#client_encoding = sql_ascii # actually, defaults to database + # encoding + +# These settings are initialized by initdb, but they can be changed. +lc_messages = 'en_US.UTF-8' # locale for system error message + # strings +lc_monetary = 'en_US.UTF-8' # locale for monetary formatting +lc_numeric = 'en_US.UTF-8' # locale for number formatting +lc_time = 'en_US.UTF-8' # locale for time formatting + +# default configuration for text search +default_text_search_config = 'pg_catalog.english' + +# - Shared Library Preloading - + +#shared_preload_libraries = '' # (change requires restart) +#local_preload_libraries = '' +#session_preload_libraries = '' +#jit_provider = 'llvmjit' # JIT library to use + +# - Other Defaults - + +#dynamic_library_path = '$libdir' + + +#------------------------------------------------------------------------------ +# LOCK MANAGEMENT +#------------------------------------------------------------------------------ + +#deadlock_timeout = 1s +#max_locks_per_transaction = 64 # min 10 + # (change requires restart) +#max_pred_locks_per_transaction = 64 # min 10 + # (change requires restart) +#max_pred_locks_per_relation = -2 # negative values mean + # (max_pred_locks_per_transaction + # / -max_pred_locks_per_relation) - 1 +#max_pred_locks_per_page = 2 # min 0 + + +#------------------------------------------------------------------------------ +# VERSION AND PLATFORM COMPATIBILITY +#------------------------------------------------------------------------------ + +# - Previous PostgreSQL Versions - + +#array_nulls = on +#backslash_quote = safe_encoding # on, off, or safe_encoding +#escape_string_warning = on +#lo_compat_privileges = off +#operator_precedence_warning = off +#quote_all_identifiers = off +#standard_conforming_strings = on +#synchronize_seqscans = on + +# - Other Platforms and Clients - + +#transform_null_equals = off + + +#------------------------------------------------------------------------------ +# ERROR HANDLING +#------------------------------------------------------------------------------ + +#exit_on_error = off # terminate session on any error? +#restart_after_crash = on # reinitialize after backend crash? +#data_sync_retry = off # retry or panic on failure to fsync + # data? + # (change requires restart) + + +#------------------------------------------------------------------------------ +# CONFIG FILE INCLUDES +#------------------------------------------------------------------------------ + +# These options allow settings to be loaded from files other than the +# default postgresql.conf. Note that these are directives, not variable +# assignments, so they can usefully be given more than once. + +#include_dir = '...' # include files ending in '.conf' from + # a directory, e.g., 'conf.d' +#include_if_exists = '...' # include file only if it exists +#include = '...' # include file +include = 'postgresql-epiphany.conf' # Epiphany managed configuration that overrides settings above + + +#------------------------------------------------------------------------------ +# CUSTOMIZED OPTIONS +#------------------------------------------------------------------------------ + +# Add settings for extensions here diff --git a/core/src/epicli/data/common/ansible/playbooks/roles/preflight/tasks/apply.yml b/core/src/epicli/data/common/ansible/playbooks/roles/preflight/tasks/apply.yml index 6998636c09..c4f5d811fe 100644 --- a/core/src/epicli/data/common/ansible/playbooks/roles/preflight/tasks/apply.yml +++ b/core/src/epicli/data/common/ansible/playbooks/roles/preflight/tasks/apply.yml @@ -9,7 +9,9 @@ - name: Check if enabled applications are supported for the architecture assert: that: _unsupported_enabled_apps | length == 0 - fail_msg: "Following application(s) are not supported for {{ _k8s_arch }} and cannot be installed: {{ _unsupported_enabled_apps | map(attribute='name') | join(', ') }}" + fail_msg: >- + Following application(s) are not supported for {{ _k8s_arch }} and cannot be installed: + {{ _unsupported_enabled_apps | map(attribute='name') | list | join(', ') }} success_msg: "All enabled applications are supported for {{ _k8s_arch }}" quiet: true vars: @@ -30,7 +32,7 @@ - groups.kubernetes_master | length > 0 - "'applications' in roles_with_generated_vars" # there is a case with disabled applications by custom feature mapping -- name: Check if PostgreSQL extentions and architecture are compatible +- name: PostgreSQL checks block: - name: Include postgresql vars from postgresql role include_vars: @@ -41,8 +43,8 @@ assert: that: _unsupported_enabled_extensions | length == 0 fail_msg: >- - {{ unsupported_postgres_extensions[_pg_arch] | join(', ') }} extensions are not supported for {{ _pg_arch }} - and cannot be installed + {{ _unsupported_enabled_extensions | map(attribute='name') | list | join(', ') }} extensions are not supported + for {{ _pg_arch }} and cannot be installed success_msg: "All enabled PostgreSQL extensions are supported for current architecture" vars: _pg_arch: >- @@ -61,6 +63,13 @@ {{ (_defined | selectattr('config.enabled') | list) + _undefined }} _unsupported_enabled_extensions: >- {{ _enabled_extensions | selectattr('name', 'in', unsupported_postgres_extensions[_pg_arch]) | list }} + + - name: Check the number of PostgreSQL hosts for replication + when: postgresql.specification.extensions.replication.enabled | default(false) + assert: + that: groups.postgresql | length == 2 + fail_msg: The supported number of PostgreSQL hosts with enabled replication is 2 # TODO: issue 2346 + success_msg: The number of PostgreSQL hosts is correct run_once: true delegate_to: localhost when: diff --git a/core/src/epicli/data/common/ansible/playbooks/roles/repository/files/download-requirements/centos-7/add-repositories.multiarch.sh b/core/src/epicli/data/common/ansible/playbooks/roles/repository/files/download-requirements/centos-7/add-repositories.multiarch.sh index b28df2df1b..7c1f323719 100644 --- a/core/src/epicli/data/common/ansible/playbooks/roles/repository/files/download-requirements/centos-7/add-repositories.multiarch.sh +++ b/core/src/epicli/data/common/ansible/playbooks/roles/repository/files/download-requirements/centos-7/add-repositories.multiarch.sh @@ -82,9 +82,9 @@ EOF ) POSTGRESQL_REPO_CONF=$(cat <<'EOF' -[pgdg10] -name=PostgreSQL 10 for RHEL/CentOS $releasever - $basearch -baseurl=https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-$releasever-$basearch +[pgdg13] +name=PostgreSQL 13 for RHEL/CentOS $releasever - $basearch +baseurl=https://download.postgresql.org/pub/repos/yum/13/redhat/rhel-$releasever-$basearch enabled=1 gpgcheck=1 gpgkey=https://download.postgresql.org/pub/repos/yum/RPM-GPG-KEY-PGDG @@ -117,5 +117,5 @@ add_repo_as_file 'elasticsearch-curator-5' "$ELASTICSEARCH_CURATOR_REPO_CONF" add_repo_as_file 'grafana' "$GRAFANA_REPO_CONF" add_repo_as_file 'kubernetes' "$KUBERNETES_REPO_CONF" add_repo_as_file 'opendistroforelasticsearch' "$OPENDISTRO_REPO_CONF" -add_repo_as_file 'postgresql-10' "$POSTGRESQL_REPO_CONF" +add_repo_as_file 'postgresql-13' "$POSTGRESQL_REPO_CONF" add_repo_as_file 'rabbitmq' "$RABBITMQ_SERVER_REPO_CONF" diff --git a/core/src/epicli/data/common/ansible/playbooks/roles/repository/files/download-requirements/centos-7/add-repositories.x86_64.sh b/core/src/epicli/data/common/ansible/playbooks/roles/repository/files/download-requirements/centos-7/add-repositories.x86_64.sh index 9350c4b119..20bed5ddf5 100644 --- a/core/src/epicli/data/common/ansible/playbooks/roles/repository/files/download-requirements/centos-7/add-repositories.x86_64.sh +++ b/core/src/epicli/data/common/ansible/playbooks/roles/repository/files/download-requirements/centos-7/add-repositories.x86_64.sh @@ -1,4 +1,7 @@ #!/usr/bin/env bash -eu add_repo_from_script 'https://dl.2ndquadrant.com/default/release/get/10/rpm' # for repmgr +add_repo_from_script 'https://dl.2ndquadrant.com/default/release/get/13/rpm' + disable_repo '2ndquadrant-dl-default-release-pg10-debug' # script adds 2 repositories, only 1 is required +disable_repo '2ndquadrant-dl-default-release-pg13-debug' diff --git a/core/src/epicli/data/common/ansible/playbooks/roles/repository/files/download-requirements/centos-7/requirements.aarch64.txt b/core/src/epicli/data/common/ansible/playbooks/roles/repository/files/download-requirements/centos-7/requirements.aarch64.txt index a882956a60..a34b58d0d9 100644 --- a/core/src/epicli/data/common/ansible/playbooks/roles/repository/files/download-requirements/centos-7/requirements.aarch64.txt +++ b/core/src/epicli/data/common/ansible/playbooks/roles/repository/files/download-requirements/centos-7/requirements.aarch64.txt @@ -78,7 +78,7 @@ perl-libs # for vim perl-Pod-Perldoc # for vim perl-Pod-Simple # for vim perl-Pod-Usage # for vim -pgaudit12_10 +pgaudit15_13 policycoreutils-python # for container-selinux pyldb # for cifs-utils python-cffi # for python2-cryptography @@ -96,7 +96,7 @@ quota # for nfs-utils rabbitmq-server-3.8.9 #rh-haproxy18 #rh-haproxy18-haproxy-syspaths -postgresql10-server +postgresql13-server samba-client samba-client-libs # for samba-client samba-common diff --git a/core/src/epicli/data/common/ansible/playbooks/roles/repository/files/download-requirements/centos-7/requirements.x86_64.txt b/core/src/epicli/data/common/ansible/playbooks/roles/repository/files/download-requirements/centos-7/requirements.x86_64.txt index b28dc94547..3b00e328ee 100644 --- a/core/src/epicli/data/common/ansible/playbooks/roles/repository/files/download-requirements/centos-7/requirements.x86_64.txt +++ b/core/src/epicli/data/common/ansible/playbooks/roles/repository/files/download-requirements/centos-7/requirements.x86_64.txt @@ -23,7 +23,7 @@ https://github.com/google/go-containerregistry/releases/download/v0.4.1/go-conta [packages] audit # for docker-ce bash-completion -c-ares # for pgbouncer +#c-ares # for pgbouncer ca-certificates cifs-utils conntrack-tools # for kubelet @@ -78,8 +78,10 @@ perl-libs # for vim perl-Pod-Perldoc # for vim perl-Pod-Simple # for vim perl-Pod-Usage # for vim -pgaudit12_10 -pgbouncer-1.10.* +pgaudit15_13 +# should be uncommented in the task #2076 +# absent in configured repository, but latest version requires python3 binary +#pgbouncer-1.10.* policycoreutils-python # for container-selinux pyldb # for cifs-utils python-cffi # for python2-cryptography @@ -97,8 +99,9 @@ quota # for nfs-utils rabbitmq-server-3.8.9 rh-haproxy18 rh-haproxy18-haproxy-syspaths -postgresql10-server +postgresql13-server repmgr10-5.2.1 +repmgr13-5.2.1 samba-client samba-client-libs # for samba-client samba-common @@ -187,8 +190,8 @@ hashicorp/vault-k8s:0.10.0 vault:1.7.0 # applications epiphanyplatform/ignite:2.9.1 -bitnami/pgpool:4.1.1-debian-10-r29 -brainsam/pgbouncer:1.12 +bitnami/pgpool:4.2.2 +bitnami/pgbouncer:1.15.0 # istio istio/pilot:1.8.1 istio/proxyv2:1.8.1 diff --git a/core/src/epicli/data/common/ansible/playbooks/roles/repository/files/download-requirements/redhat-7/add-repositories.multiarch.sh b/core/src/epicli/data/common/ansible/playbooks/roles/repository/files/download-requirements/redhat-7/add-repositories.multiarch.sh index b28df2df1b..7c1f323719 100644 --- a/core/src/epicli/data/common/ansible/playbooks/roles/repository/files/download-requirements/redhat-7/add-repositories.multiarch.sh +++ b/core/src/epicli/data/common/ansible/playbooks/roles/repository/files/download-requirements/redhat-7/add-repositories.multiarch.sh @@ -82,9 +82,9 @@ EOF ) POSTGRESQL_REPO_CONF=$(cat <<'EOF' -[pgdg10] -name=PostgreSQL 10 for RHEL/CentOS $releasever - $basearch -baseurl=https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-$releasever-$basearch +[pgdg13] +name=PostgreSQL 13 for RHEL/CentOS $releasever - $basearch +baseurl=https://download.postgresql.org/pub/repos/yum/13/redhat/rhel-$releasever-$basearch enabled=1 gpgcheck=1 gpgkey=https://download.postgresql.org/pub/repos/yum/RPM-GPG-KEY-PGDG @@ -117,5 +117,5 @@ add_repo_as_file 'elasticsearch-curator-5' "$ELASTICSEARCH_CURATOR_REPO_CONF" add_repo_as_file 'grafana' "$GRAFANA_REPO_CONF" add_repo_as_file 'kubernetes' "$KUBERNETES_REPO_CONF" add_repo_as_file 'opendistroforelasticsearch' "$OPENDISTRO_REPO_CONF" -add_repo_as_file 'postgresql-10' "$POSTGRESQL_REPO_CONF" +add_repo_as_file 'postgresql-13' "$POSTGRESQL_REPO_CONF" add_repo_as_file 'rabbitmq' "$RABBITMQ_SERVER_REPO_CONF" diff --git a/core/src/epicli/data/common/ansible/playbooks/roles/repository/files/download-requirements/redhat-7/add-repositories.x86_64.sh b/core/src/epicli/data/common/ansible/playbooks/roles/repository/files/download-requirements/redhat-7/add-repositories.x86_64.sh index 9350c4b119..20bed5ddf5 100644 --- a/core/src/epicli/data/common/ansible/playbooks/roles/repository/files/download-requirements/redhat-7/add-repositories.x86_64.sh +++ b/core/src/epicli/data/common/ansible/playbooks/roles/repository/files/download-requirements/redhat-7/add-repositories.x86_64.sh @@ -1,4 +1,7 @@ #!/usr/bin/env bash -eu add_repo_from_script 'https://dl.2ndquadrant.com/default/release/get/10/rpm' # for repmgr +add_repo_from_script 'https://dl.2ndquadrant.com/default/release/get/13/rpm' + disable_repo '2ndquadrant-dl-default-release-pg10-debug' # script adds 2 repositories, only 1 is required +disable_repo '2ndquadrant-dl-default-release-pg13-debug' diff --git a/core/src/epicli/data/common/ansible/playbooks/roles/repository/files/download-requirements/redhat-7/requirements.x86_64.txt b/core/src/epicli/data/common/ansible/playbooks/roles/repository/files/download-requirements/redhat-7/requirements.x86_64.txt index 69b922d905..5bb3204b17 100644 --- a/core/src/epicli/data/common/ansible/playbooks/roles/repository/files/download-requirements/redhat-7/requirements.x86_64.txt +++ b/core/src/epicli/data/common/ansible/playbooks/roles/repository/files/download-requirements/redhat-7/requirements.x86_64.txt @@ -21,7 +21,7 @@ https://github.com/google/go-containerregistry/releases/download/v0.4.1/go-conta [packages] audit # for docker-ce bash-completion -c-ares # for pgbouncer +#c-ares # for pgbouncer ca-certificates cifs-utils conntrack-tools # for kubelet @@ -76,8 +76,10 @@ perl-libs # for vim perl-Pod-Perldoc # for vim perl-Pod-Simple # for vim perl-Pod-Usage # for vim -pgaudit12_10 -pgbouncer-1.10.* +pgaudit15_13 +# should be uncommented in the task #2076 +# absent in configured repository, but latest version requires python3 binary +#pgbouncer-1.10.* policycoreutils-python # for container-selinux pyldb # for cifs-utils python-cffi # for python2-cryptography @@ -93,8 +95,9 @@ quota # for nfs-utils rabbitmq-server-3.8.9 rh-haproxy18 rh-haproxy18-haproxy-syspaths -postgresql10-server +postgresql13-server repmgr10-5.2.1 +repmgr13-5.2.1 samba-client samba-client-libs # for samba-client samba-common @@ -183,8 +186,8 @@ hashicorp/vault-k8s:0.10.0 vault:1.7.0 # applications epiphanyplatform/ignite:2.9.1 -bitnami/pgpool:4.1.1-debian-10-r29 -brainsam/pgbouncer:1.12 +bitnami/pgpool:4.2.2 +bitnami/pgbouncer:1.15.0 # istio istio/pilot:1.8.1 istio/proxyv2:1.8.1 diff --git a/core/src/epicli/data/common/ansible/playbooks/roles/repository/files/download-requirements/ubuntu-18.04/add-repositories.sh b/core/src/epicli/data/common/ansible/playbooks/roles/repository/files/download-requirements/ubuntu-18.04/add-repositories.sh index df644e3e21..f282dca0cb 100644 --- a/core/src/epicli/data/common/ansible/playbooks/roles/repository/files/download-requirements/ubuntu-18.04/add-repositories.sh +++ b/core/src/epicli/data/common/ansible/playbooks/roles/repository/files/download-requirements/ubuntu-18.04/add-repositories.sh @@ -24,6 +24,9 @@ echo "deb https://artifacts.elastic.co/packages/oss-7.x/apt stable main" | tee / wget -qO - https://d3g5vo6xdbdb9a.cloudfront.net/GPG-KEY-opendistroforelasticsearch | apt-key add - echo "deb https://d3g5vo6xdbdb9a.cloudfront.net/apt stable main" | tee -a /etc/apt/sources.list.d/opendistroforelasticsearch.list +wget -qO - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add - +echo "deb http://apt.postgresql.org/pub/repos/apt bionic-pgdg main" | tee /etc/apt/sources.list.d/pgdg.list + wget -qO - https://dl.2ndquadrant.com/gpg-key.asc | apt-key add - echo "deb https://dl.2ndquadrant.com/default/release/apt bionic-2ndquadrant main" | tee -a /etc/apt/sources.list.d/2ndquadrant-dl-default-release.list diff --git a/core/src/epicli/data/common/ansible/playbooks/roles/repository/files/download-requirements/ubuntu-18.04/requirements.x86_64.txt b/core/src/epicli/data/common/ansible/playbooks/roles/repository/files/download-requirements/ubuntu-18.04/requirements.x86_64.txt index ed215d042f..b42a522b01 100644 --- a/core/src/epicli/data/common/ansible/playbooks/roles/repository/files/download-requirements/ubuntu-18.04/requirements.x86_64.txt +++ b/core/src/epicli/data/common/ansible/playbooks/roles/repository/files/download-requirements/ubuntu-18.04/requirements.x86_64.txt @@ -64,7 +64,7 @@ opendistro-sql 1.13.0 opendistroforelasticsearch-kibana 1.13.1 openjdk-8-jre-headless openssl -postgresql-10 +postgresql-13 python-pip python-psycopg2 python-selinux @@ -141,10 +141,13 @@ samba-libs libsmbclient # for postgres -pgbouncer 1.10.* -postgresql-10-pgaudit +pgbouncer 1.15.* +pgdg-keyring +postgresql-13-pgaudit postgresql-10-repmgr 5.2.1 -postgresql-client-10 +postgresql-13-repmgr 5.2.1 +postgresql-client-13 +postgresql-client-common postgresql-common repmgr-common 5.2.1 @@ -241,8 +244,8 @@ hashicorp/vault-k8s:0.10.0 vault:1.7.0 # applications epiphanyplatform/ignite:2.9.1 -bitnami/pgpool:4.1.1-debian-10-r29 -brainsam/pgbouncer:1.12 +bitnami/pgpool:4.2.2 +bitnami/pgbouncer:1.15.0 # istio istio/pilot:1.8.1 istio/proxyv2:1.8.1 diff --git a/core/src/epicli/data/common/defaults/configuration/applications.yml b/core/src/epicli/data/common/defaults/configuration/applications.yml index 6c33ffce66..2cb6f322b8 100644 --- a/core/src/epicli/data/common/defaults/configuration/applications.yml +++ b/core/src/epicli/data/common/defaults/configuration/applications.yml @@ -20,7 +20,7 @@ specification: - ignite-kubernetes # required to work on K8s - ignite-rest-http -# Abstract these configs to seperate default files and add +# Abstract these configs to separate default files and add # the ability to add custom application roles. ## --- rabbitmq --- @@ -78,7 +78,7 @@ specification: - name: pgpool # this service requires PostgreSQL to be installed in cluster enabled: false image: - path: bitnami/pgpool:4.1.1-debian-10-r29 + path: bitnami/pgpool:4.2.2 debug: false # ref: https://github.com/bitnami/minideb-extras/#turn-on-bash-debugging use_local_image_registry: true namespace: postgres-pool @@ -141,9 +141,8 @@ specification: - name: pgbouncer enabled: false - #https://github.com/brainsam/pgbouncer/tree/release/1.12 - image_path: brainsam/pgbouncer:1.12 - init_image_path: bitnami/pgpool:4.1.1-debian-10-r29 #TODO: make reference to pgpool section + image_path: bitnami/pgbouncer:1.15.0 + init_image_path: bitnami/pgpool:4.2.2 #TODO: make reference to pgpool section use_local_image_registry: true namespace: postgres-pool service: @@ -181,5 +180,5 @@ specification: - istio-system istio: istio-system # namespace where istio control plane will be deployed istio_spec: - profile: default # Check all possibilites https://istio.io/latest/docs/setup/additional-setup/config-profiles/ + profile: default # Check all possibilities https://istio.io/latest/docs/setup/additional-setup/config-profiles/ name: istiocontrolplane diff --git a/core/src/epicli/data/common/defaults/configuration/image-registry.yml b/core/src/epicli/data/common/defaults/configuration/image-registry.yml index b6b7ff3f3f..b9a26d1369 100644 --- a/core/src/epicli/data/common/defaults/configuration/image-registry.yml +++ b/core/src/epicli/data/common/defaults/configuration/image-registry.yml @@ -30,10 +30,10 @@ specification: - name: "istio/operator:1.8.1" file_name: operator-1.8.1.tar # postgres - - name: bitnami/pgpool:4.1.1-debian-10-r29 - file_name: pgpool-4.1.1-debian-10-r29.tar - - name: "brainsam/pgbouncer:1.12" - file_name: pgbouncer-1.12.tar + - name: bitnami/pgpool:4.2.2 + file_name: pgpool-4.2.2.tar + - name: bitnami/pgbouncer:1.15.0 + file_name: pgbouncer-1.15.0.tar current: - name: "haproxy:2.2.2-alpine" file_name: haproxy-2.2.2-alpine.tar diff --git a/core/src/epicli/data/common/defaults/configuration/postgresql.yml b/core/src/epicli/data/common/defaults/configuration/postgresql.yml index 2e9a781a43..f4fe3ee4b6 100644 --- a/core/src/epicli/data/common/defaults/configuration/postgresql.yml +++ b/core/src/epicli/data/common/defaults/configuration/postgresql.yml @@ -40,13 +40,16 @@ specification: - name: wal_level value: replica when: replication + # Changes to archive_mode require a full PostgreSQL server restart, + # while archive_command changes can be applied via a normal configuration reload. + # See https://repmgr.org/docs/repmgr.html#CONFIGURATION-POSTGRESQL - name: Archiving parameters: - name: archive_mode value: 'on' when: replication - name: archive_command - value: "'test ! -f /dbbackup/{{ inventory_hostname }}/backup/%f && gzip -c < %p > /dbbackup/{{ inventory_hostname }}/backup/%f'" + value: "'/bin/true'" when: replication - name: REPLICATION subgroups: @@ -56,9 +59,9 @@ specification: value: 10 comment: maximum number of simultaneously running WAL sender processes when: replication - - name: wal_keep_segments - value: 34 - comment: number of WAL files held for standby servers + - name: wal_keep_size + value: 500 + comment: the size of WAL files held for standby servers (MB) when: replication - name: Standby Servers # ignored on master server parameters: @@ -76,8 +79,8 @@ specification: log_disconnections: 'off' log_statement: 'none' log_line_prefix: "'%m [%p] %q%u@%d,host=%h '" - ## pgaudit specific, see https://github.com/pgaudit/pgaudit/blob/REL_10_STABLE/README.md#settings - pgaudit.log: "'write, function, role, ddl' # 'misc_set' is not supported for PG 10" + # pgaudit specific, see https://github.com/pgaudit/pgaudit/tree/REL_13_STABLE#settings + pgaudit.log: "'write, function, role, ddl, misc_set'" pgaudit.log_catalog: 'off # to reduce overhead of logging' # default is 'on' # the following first 2 parameters are set to values that make it easier to access audit log per table # change their values to the opposite if you need to reduce overhead of logging diff --git a/core/src/epicli/data/common/tests/spec/postgresql/postgresql_spec.rb b/core/src/epicli/data/common/tests/spec/postgresql/postgresql_spec.rb index edd5fd2833..6563bff09b 100644 --- a/core/src/epicli/data/common/tests/spec/postgresql/postgresql_spec.rb +++ b/core/src/epicli/data/common/tests/spec/postgresql/postgresql_spec.rb @@ -111,7 +111,7 @@ def queryForDropping describe 'Check PostgreSQL service status' do if os[:family] == 'redhat' - describe command("systemctl status postgresql-10 > /dev/null") do + describe command("systemctl status postgresql-13 > /dev/null") do its(:exit_status) { should eq 0 } end elsif os[:family] == 'ubuntu' @@ -123,7 +123,7 @@ def queryForDropping describe 'Check if PostgreSQL service is running' do if os[:family] == 'redhat' - describe service('postgresql-10') do + describe service('postgresql-13') do it { should be_enabled } it { should be_running } end @@ -138,7 +138,7 @@ def queryForDropping if replicated describe 'Check if repmgr service is running' do if os[:family] == 'redhat' - describe service('repmgr10') do + describe service('repmgr13') do it { should be_enabled } it { should be_running } end @@ -154,21 +154,21 @@ def queryForDropping if os[:family] == 'redhat' describe 'Check PostgreSQL directories and config files' do let(:disable_sudo) { false } - describe file('/var/lib/pgsql/10/data') do + describe file('/var/lib/pgsql/13/data') do it { should exist } it { should be_a_directory } end - describe file("/var/lib/pgsql/10/data/pg_hba.conf") do + describe file("/var/lib/pgsql/13/data/pg_hba.conf") do it { should exist } it { should be_a_file } it { should be_readable } end - describe file("/var/lib/pgsql/10/data/postgresql.conf") do + describe file("/var/lib/pgsql/13/data/postgresql.conf") do it { should exist } it { should be_a_file } it { should be_readable } end - describe file("/var/lib/pgsql/10/data/postgresql-epiphany.conf") do + describe file("/var/lib/pgsql/13/data/postgresql-epiphany.conf") do it { should exist } it { should be_a_file } it { should be_readable } @@ -177,21 +177,21 @@ def queryForDropping elsif os[:family] == 'ubuntu' describe 'Check PostgreSQL directories and config files' do let(:disable_sudo) { false } - describe file('/etc/postgresql/10/main') do + describe file('/etc/postgresql/13/main') do it { should exist } it { should be_a_directory } end - describe file("/etc/postgresql/10/main/pg_hba.conf") do + describe file("/etc/postgresql/13/main/pg_hba.conf") do it { should exist } it { should be_a_file } it { should be_readable } end - describe file("/etc/postgresql/10/main/postgresql.conf") do + describe file("/etc/postgresql/13/main/postgresql.conf") do it { should exist } it { should be_a_file } it { should be_readable } end - describe file("/etc/postgresql/10/main/postgresql-epiphany.conf") do + describe file("/etc/postgresql/13/main/postgresql-epiphany.conf") do it { should exist } it { should be_a_file } it { should be_readable } @@ -254,12 +254,12 @@ def queryForDropping describe 'Check hot_standby setting in postgresql-epiphany.conf file' do let(:disable_sudo) { false } if os[:family] == 'redhat' - describe command("grep -Eio '^hot_standby\s*=[^#]*' /var/lib/pgsql/10/data/postgresql-epiphany.conf") do + describe command("grep -Eio '^hot_standby\s*=[^#]*' /var/lib/pgsql/13/data/postgresql-epiphany.conf") do its(:exit_status) { should eq 0 } its(:stdout) { should match /^hot_standby\s*=\s*#{pg_config_file_booleans[:true]}/i } end elsif os[:family] == 'ubuntu' - describe command("grep -Eio '^hot_standby\s*=[^#]*' /etc/postgresql/10/main/postgresql-epiphany.conf") do + describe command("grep -Eio '^hot_standby\s*=[^#]*' /etc/postgresql/13/main/postgresql-epiphany.conf") do its(:exit_status) { should eq 0 } its(:stdout) { should match /^hot_standby\s*=\s*#{pg_config_file_booleans[:true]}/i } end @@ -270,15 +270,15 @@ def queryForDropping if os[:family] == 'redhat' describe 'Check PostgreSQL config files for master node' do let(:disable_sudo) { false } - describe command("cat /var/lib/pgsql/10/data/postgresql-epiphany.conf | grep wal_level") do + describe command("cat /var/lib/pgsql/13/data/postgresql-epiphany.conf | grep wal_level") do its(:stdout) { should match /^wal_level = replica/ } its(:exit_status) { should eq 0 } end - describe command("cat /var/lib/pgsql/10/data/postgresql-epiphany.conf | grep max_wal_senders") do + describe command("cat /var/lib/pgsql13/data/postgresql-epiphany.conf | grep max_wal_senders") do its(:stdout) { should match /^max_wal_senders = #{max_wal_senders}/ } its(:exit_status) { should eq 0 } end - describe command("cat /var/lib/pgsql/10/data/postgresql-epiphany.conf | grep wal_keep_segments") do + describe command("cat /var/lib/pgsql/13/data/postgresql-epiphany.conf | grep wal_keep_segments") do its(:stdout) { should match /^wal_keep_segments = #{wal_keep_segments}/ } its(:exit_status) { should eq 0 } end @@ -287,7 +287,7 @@ def queryForDropping its(:stdout) { should match /Replication/ } its(:exit_status) { should eq 0 } end - describe command("cat /var/lib/pgsql/10/data/pg_hba.conf | grep replication | grep md5") do + describe command("cat /var/lib/pgsql/13/data/pg_hba.conf | grep replication | grep md5") do its(:stdout) { should match /#{replication_user}/ } its(:stdout) { should match /replication/ } its(:exit_status) { should eq 0 } @@ -296,15 +296,15 @@ def queryForDropping elsif os[:family] == 'ubuntu' describe 'Check PostgreSQL config files for master node' do let(:disable_sudo) { false } - describe command("cat /etc/postgresql/10/main/postgresql-epiphany.conf | grep wal_level") do + describe command("cat /etc/postgresql/13/main/postgresql-epiphany.conf | grep wal_level") do its(:stdout) { should match /^wal_level = replica/ } its(:exit_status) { should eq 0 } end - describe command("cat /etc/postgresql/10/main/postgresql-epiphany.conf | grep max_wal_senders") do + describe command("cat /etc/postgresql/13/main/postgresql-epiphany.conf | grep max_wal_senders") do its(:stdout) { should match /^max_wal_senders = #{max_wal_senders}/ } its(:exit_status) { should eq 0 } end - describe command("cat /etc/postgresql/10/main/postgresql-epiphany.conf | grep wal_keep_segments") do + describe command("cat /etc/postgresql/13/main/postgresql-epiphany.conf | grep wal_keep_segments") do its(:stdout) { should match /^wal_keep_segments = #{wal_keep_segments}/ } its(:exit_status) { should eq 0 } end @@ -313,7 +313,7 @@ def queryForDropping its(:stdout) { should match /Replication/ } its(:exit_status) { should eq 0 } end - describe command("cat /etc/postgresql/10/main/pg_hba.conf | grep replication | grep md5") do + describe command("cat /etc/postgresql/13/main/pg_hba.conf | grep replication | grep md5") do its(:stdout) { should match /#{replication_user}/ } its(:stdout) { should match /replication/ } its(:exit_status) { should eq 0 } @@ -532,7 +532,7 @@ def get_elasticsearch_query(message_pattern:, size: 20, with_sort: true) _source: [ 'message', '@timestamp' ], query: { query_string: { - query: "log.file.path:(\\/var\\/log\\/postgresql\\/postgresql\\-10\\-main.log OR \\/var\\/log\\/postgresql\\/postgresql.log) AND message:#{message_pattern} AND @timestamp:[now-30m TO now]" + query: "log.file.path:(\\/var\\/log\\/postgresql\\/postgresql\\-13\\-main.log OR \\/var\\/log\\/postgresql\\/postgresql.log) AND message:#{message_pattern} AND @timestamp:[now-30m TO now]" } }, size: size diff --git a/docs/home/COMPONENTS.md b/docs/home/COMPONENTS.md index 68a5128bc3..6c87c23dcd 100644 --- a/docs/home/COMPONENTS.md +++ b/docs/home/COMPONENTS.md @@ -31,12 +31,12 @@ Note that versions are default versions and can be changed in certain cases thro | HAProxy Exporter | 0.10.0 | https://github.com/prometheus/haproxy_exporter | [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0) | | JMX Exporter | 0.12.0 | https://github.com/prometheus/jmx_exporter | [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0) | | Postgres Exporter | 0.9.0 | https://github.com/prometheus-community/postgres_exporter | [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0) | -| PostgreSQL | 10 | https://www.postgresql.org/ | https://opensource.org/licenses/postgresql | +| PostgreSQL | 13 | https://www.postgresql.org/ | [PostgreSQL license](http://www.postgresql.org/about/licence/) | | HAProxy | 2.2.2 | https://www.haproxy.org/ | [GNU General Public License 2.0](https://www.gnu.org/licenses/old-licenses/gpl-2.0.html) | -| PGAudit | 1.2.2 | https://github.com/pgaudit/pgaudit | [PostgreSQL license](http://www.postgresql.org/about/licence/) | +| PgAudit | 1.5.0 | https://github.com/pgaudit/pgaudit | [PostgreSQL license](http://www.postgresql.org/about/licence/) | | PgBouncer | 1.10.0 | https://github.com/pgbouncer/pgbouncer | [ISC License](https://opensource.org/licenses/isc) | | repmgr | 5.2.1 | https://github.com/EnterpriseDB/repmgr | [GNU General Public License 3.0](https://github.com/EnterpriseDB/repmgr/blob/master/LICENSE) | -| PGPool | 4.1.1 | https://www.pgpool.net/ | [License](https://www.pgpool.net/mediawiki/index.php/pgpool-II_License) | +| PgPool | 4.2.2 | https://www.pgpool.net/ | [License](https://www.pgpool.net/mediawiki/index.php/pgpool-II_License) | | Alertmanager | 0.17.0 | https://github.com/prometheus/alertmanager | [Apache License 2.0](https://github.com/prometheus/alertmanager/blob/master/LICENSE) | | Apache Ignite | 2.9.1 | https://github.com/apache/ignite | [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0) | | Apache2 | 2.4.29 | https://httpd.apache.org/ | [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0) |