Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added pmm_qa/__init__.py
Empty file.
12 changes: 12 additions & 0 deletions pmm_qa/percona-distribution-postgresql/data/etcd.conf.yaml.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: 'node{{item}}'
data-dir: /var/lib/etcd
initial-cluster-token: PostgreSQL_HA_Cluster_1
initial-cluster-state: new

listen-peer-urls: http://0.0.0.0:2380
initial-advertise-peer-urls: http://pdpgsql_pmm_patroni_{{ pg_version }}_{{ item }}:2380

listen-client-urls: http://0.0.0.0:2379
advertise-client-urls: http://pdpgsql_pmm_patroni_{{ pg_version }}_{{ item }}:2379

initial-cluster: node1=http://pdpgsql_pmm_patroni_{{ pg_version }}_1:2380,node2=http://pdpgsql_pmm_patroni_{{ pg_version }}_2:2380,node3=http://pdpgsql_pmm_patroni_{{ pg_version }}_3:2380
83 changes: 83 additions & 0 deletions pmm_qa/percona-distribution-postgresql/data/patroni.yml.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
scope: patroni_cls
namespace: /var/lib/pgsql/config/
name: pg_node_{{ item }}

restapi:
listen: 0.0.0.0:8008
connect_address: "pdpgsql_pmm_patroni_{{ pg_version }}_{{ item }}:8008"

etcd3:
host: "pdpgsql_pmm_patroni_{{ pg_version }}_1:2379"

bootstrap:
dcs:
ttl: 30
loop_wait: 10
retry_timeout: 10
maximum_lag_on_failover: 1048576

postgresql:
use_pg_rewind: true
use_slots: true
parameters:
shared_preload_libraries: 'pg_stat_monitor'
wal_level: replica
hot_standby: "on"
wal_keep_size: 128MB
max_wal_senders: 10
max_replication_slots: 10
wal_log_hints: "on"
archive_mode: "on"
archive_timeout: 600s
archive_command: "cp -f %p /home/postgres/archived/%f"
pg_hba:
- host replication replicator 127.0.0.1/32 md5
- host replication replicator 172.18.0.0/16 md5
- host all all 0.0.0.0/0 md5
- local all postgres trust

initdb:
- encoding: UTF8
- data-checksums
- waldir: /pg_wal
- wal-segsize=512

users:
admin:
password: admin
options:
- createrole
- createdb

postgresql:
listen: 0.0.0.0:5432
connect_address: "pdpgsql_pmm_patroni_{{ pg_version }}_{{ item }}:5432"
data_dir: /var/lib/pgsql/{{ pg_version}}/data
bin_dir: /usr/pgsql-{{ pg_version }}/bin
pgpass: /tmp/pgpass

authentication:
replication:
username: replicator
password: replPasswd
superuser:
username: postgres
password: postgres

create_replica_methods:
- pgbackrest
- basebackup

pgbackrest:
command: pgbackrest --stanza=patroni_backup restore --type=none
keep_data: true
no_params: true

basebackup:
checkpoint: fast

tags:
nofailover: false
noloadbalance: false
clonefrom: false
nosync: false
3 changes: 3 additions & 0 deletions pmm_qa/percona-distribution-postgresql/data/pg_hba.conf.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
host replication {{ replication_user }} 0.0.0.0/0 md5
host all all 0.0.0.0/0 md5
local all postgres trust
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
host replication {{ replication_user }} 0.0.0.0/0 md5
host all all 0.0.0.0/0 md5
local all postgres trust
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
hba_file = '/etc/postgresql/pg_hba.conf'
shared_preload_libraries = 'pg_stat_monitor'
track_activity_query_size=2048
track_io_timing=ON
max_connections=1000
listen_addresses = '*'
pg_stat_monitor.pgsm_enable_query_plan = 'yes'
pg_stat_monitor.pgsm_query_max_len = 2048
pg_stat_monitor.pgsm_normalized_query=1
pg_stat_monitor.pgsm_enable_query_plan=1
log_connections = on
log_disconnections = on
log_replication_commands = on
log_statement = 'all'
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
wal_level = replica
max_wal_senders = 10
wal_keep_size = 64MB
hot_standby = on
listen_addresses = '*'
hba_file = '/etc/postgresql/pg_hba.conf'
shared_preload_libraries = 'pg_stat_monitor'
track_activity_query_size=2048
track_io_timing=ON
max_connections=1000
listen_addresses = '*'
pg_stat_monitor.pgsm_enable_query_plan = 'yes'
log_connections = on
log_disconnections = on
log_replication_commands = on
log_statement = 'all'
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
# Percona Distribution Postgresql Replication
- name: Setup Postgresql replication
hosts: localhost
connection: local
gather_facts: yes
vars:
pg_version: "{{ lookup('env', 'PGSQL_VERSION') | default('17', true) }}"
replication_user: "repl_user"
replication_password: "GRgrO9301RuF"
root_password: "GRgrO9301RuF"
pdpgsql_port: 5432
nodes_count: "{{ (lookup('env', 'NODES_COUNT') | default('2', true)) | int }}"
network_name: "pmm-qa"
data_dir: "{{ lookup('env', 'HOME') }}/pgsql_cluster_data"
pmm_server_ip: "{{ lookup('vars', 'extra_pmm_server_ip', default=lookup('env','PMM_SERVER_IP') | default('127.0.0.1', true) ) }}"
client_version: "{{ lookup('vars', 'extra_client_version', default=lookup('env','CLIENT_VERSION') | default('3-dev-latest', true) ) }}"
admin_password: "{{ lookup('vars', 'extra_admin_password', default=lookup('env','ADMIN_PASSWORD') | default('admin', true) ) }}"
query_source: "{{ lookup('env', 'QUERY_SOURCE') | default('pgstatements', true) }}"
metrics_mode: "auto"
setup_type: "{{ lookup('env', 'SETUP_TYPE') }}"
random_service_name_value: ""
docker_repo: "percona/percona-distribution-postgresql"

tasks:
- name: Display binary log status for primary
debug:
msg: "{{ setup_type }}"

- name: Install Percona Distribution for Postgres with Replication
include_tasks: tasks/percona-distribution-postgres-replication-setup.yml
when: setup_type == "replication"

- name: Install Percona Distribution for Postgres with Patroni replication
include_tasks: tasks/percona-distribution-postgres-patroni-setup.yml
when: setup_type == "patroni"
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
- name: Detect OS inside the container
community.docker.docker_container_exec:
container: "{{ container_name }}_1"
command: cat /etc/os-release
register: container_os_info

- name: Set distro family (debian/rhel)
set_fact:
distro_family: >-
{{
(
'debian' if 'debian' in container_os_info.stdout | lower else
'rhel' if 'rhel' in container_os_info.stdout | lower or 'centos' in container_os_info.stdout | lower or 'fedora' in container_os_info.stdout | lower
else 'unknown'
) | trim
}}

- name: Install dependencies inside Debian-family container
community.docker.docker_container_exec:
container: "{{ container_name }}_{{ item }}"
command: >
sh -c '
apt-get update &&
apt-get install percona-pg-stat-monitor{{ pg_version }}
'
user: "root"
when: distro_family == "debian"
loop: "{{ range(1, nodes_count | int + 1) | list }}"

- name: Install dependencies inside RHEL-family container
community.docker.docker_container_exec:
container: "{{ container_name }}_{{ item }}"
command: >
sh -c '
microdnf install percona-pg-stat-monitor{{ pg_version }}
'
user: "root"
when: distro_family == "rhel"
loop: "{{ range(1, nodes_count | int + 1) | list }}"

- name: Create pg_stat_statements extension
community.docker.docker_container_exec:
container: "{{ container_name }}_1"
user: postgres
command: >
psql -U postgres -d 'postgres' -c "
CREATE EXTENSION IF NOT EXISTS pg_stat_monitor;
SELECT pg_stat_monitor_version();
"
Loading
Loading