Skip to content

Commit c2dde01

Browse files
PMM-14517: Percona Distribution for Postgresql 18 and support for cgroups (#180)
* Pmm 14517 (#179) * PMM-14517: Skeleton PG Setup * PMM14517: Fix pdpgsql 18 systemd (#182) * PMM-14517: Fix setup for pmm client
1 parent bfe1971 commit c2dde01

19 files changed

+589
-401
lines changed

pmm_qa/percona-distribution-postgresql/data/etcd.conf.yaml.j2

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ initial-cluster-token: PostgreSQL_HA_Cluster_1
44
initial-cluster-state: new
55

66
listen-peer-urls: http://0.0.0.0:2380
7-
initial-advertise-peer-urls: http://pdpgsql_pmm_patroni_{{ pg_version }}_{{ item }}:2380
7+
initial-advertise-peer-urls: http://pdpgsql_pmm_patroni_{{ pdpgsql_version }}_{{ item }}:2380
88

99
listen-client-urls: http://0.0.0.0:2379
10-
advertise-client-urls: http://pdpgsql_pmm_patroni_{{ pg_version }}_{{ item }}:2379
10+
advertise-client-urls: http://pdpgsql_pmm_patroni_{{ pdpgsql_version }}_{{ item }}:2379
1111

12-
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
12+
initial-cluster: node1=http://pdpgsql_pmm_patroni_{{ pdpgsql_version }}_1:2380,node2=http://pdpgsql_pmm_patroni_{{ pdpgsql_version }}_2:2380,node3=http://pdpgsql_pmm_patroni_{{ pdpgsql_version }}_3:2380

pmm_qa/percona-distribution-postgresql/data/patroni.yml.j2

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
scope: patroni_cls
22
namespace: /var/lib/pgsql/config/
3-
name: pg_node_{{ item }}
3+
name: {{ container_prefix }}{{ item }}
44

55
restapi:
66
listen: 0.0.0.0:8008
7-
connect_address: "pdpgsql_pmm_patroni_{{ pg_version }}_{{ item }}:8008"
7+
connect_address: "{{ container_prefix }}{{ item }}:8008"
88

99
etcd3:
10-
host: "pdpgsql_pmm_patroni_{{ pg_version }}_1:2379"
10+
host: "{{ container_prefix }}1:2379"
1111

1212
bootstrap:
1313
dcs:
@@ -29,7 +29,7 @@ bootstrap:
2929
wal_log_hints: "on"
3030
archive_mode: "on"
3131
archive_timeout: 600s
32-
archive_command: "cp -f %p /home/postgres/archived/%f"
32+
archive_command: pgbackrest --stanza=patroni_backup --log-level-console=info archive-push /var/lib/postgresql/{{ pdpgsql_version }}/main/pg_wal/%f
3333
pg_hba:
3434
- host replication replicator 127.0.0.1/32 md5
3535
- host replication replicator 172.18.0.0/16 md5
@@ -51,9 +51,9 @@ bootstrap:
5151

5252
postgresql:
5353
listen: 0.0.0.0:5432
54-
connect_address: "pdpgsql_pmm_patroni_{{ pg_version }}_{{ item }}:5432"
55-
data_dir: /var/lib/pgsql/{{ pg_version}}/data
56-
bin_dir: /usr/pgsql-{{ pg_version }}/bin
54+
connect_address: "{{ container_prefix }}{{ item }}:5432"
55+
data_dir: /var/lib/postgresql/{{ pdpgsql_version }}/main
56+
bin_dir: /usr/lib/postgresql/{{ pdpgsql_version }}/bin
5757
pgpass: /tmp/pgpass
5858

5959
authentication:
@@ -62,14 +62,14 @@ postgresql:
6262
password: replPasswd
6363
superuser:
6464
username: postgres
65-
password: postgres
65+
password: pass+this
6666

6767
create_replica_methods:
6868
- pgbackrest
6969
- basebackup
7070

7171
pgbackrest:
72-
command: pgbackrest --stanza=patroni_backup restore --type=none
72+
command: pgbackrest --stanza=patroni_backup restore --pg1-path=/var/lib/postgresql/{{ pdpgsql_version }}/main --type=none
7373
keep_data: true
7474
no_params: true
7575

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
host replication {{ replication_user }} 0.0.0.0/0 md5
22
host all all 0.0.0.0/0 md5
33
local all postgres trust
4+
local all all md5
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
host replication {{ replication_user }} 0.0.0.0/0 md5
22
host all all 0.0.0.0/0 md5
33
local all postgres trust
4+
local all all md5
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/sh
2+
3+
## Running Queries
4+
wget https://raw.githubusercontent.com/percona/pmm-agent/main/testqueries/postgres/pg_stat_monitor_load.sql
5+
while true
6+
do
7+
su postgres bash -c 'psql -d contrib_regression -f pg_stat_monitor_load.sql'
8+
su postgres bash -c 'psql -d sbtest1 -f pg_stat_monitor_load.sql'
9+
sleep 30
10+
done
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
-- ========================================
2+
-- CREATE TABLES
3+
-- ========================================
4+
5+
CREATE TABLE students (
6+
student_id SERIAL PRIMARY KEY,
7+
first_name VARCHAR(50),
8+
last_name VARCHAR(50),
9+
birth_date DATE
10+
);
11+
12+
CREATE TABLE classes (
13+
class_id SERIAL PRIMARY KEY,
14+
name VARCHAR(100),
15+
teacher VARCHAR(100)
16+
);
17+
18+
CREATE TABLE enrollments (
19+
enrollment_id SERIAL PRIMARY KEY,
20+
student_id INTEGER REFERENCES students(student_id),
21+
class_id INTEGER REFERENCES classes(class_id),
22+
enrollment_date DATE DEFAULT CURRENT_DATE
23+
);
24+
25+
-- ========================================
26+
-- INSERT MOCK DATA
27+
-- ========================================
28+
29+
INSERT INTO students (first_name, last_name, birth_date) VALUES
30+
('Alice', 'Smith', '2005-04-10'),
31+
('Bob', 'Johnson', '2006-08-15'),
32+
('Charlie', 'Brown', '2004-12-01');
33+
34+
INSERT INTO classes (name, teacher) VALUES
35+
('Mathematics', 'Mrs. Taylor'),
36+
('History', 'Mr. Anderson'),
37+
('Science', 'Dr. Reynolds');
38+
39+
INSERT INTO enrollments (student_id, class_id) VALUES
40+
(1, 1),
41+
(1, 2),
42+
(2, 2),
43+
(3, 1),
44+
(3, 3);
45+
46+
-- ========================================
47+
-- SIMULATE DEAD TUPLES
48+
-- ========================================
49+
50+
51+
INSERT INTO students (first_name, last_name, birth_date)
52+
SELECT 'John', 'Doe', CURRENT_DATE - (random() * 5000)::int
53+
FROM generate_series(1, 100000);
54+
55+
-- These updates and deletes will create dead tuples
56+
57+
-- Update records (old versions become dead)
58+
UPDATE students
59+
SET last_name = last_name || '_updated'
60+
WHERE student_id IN (1, 2);
61+
62+
-- Delete records (deleted rows become dead)
63+
DELETE FROM enrollments
64+
WHERE enrollment_id IN (SELECT enrollment_id FROM enrollments LIMIT 2);
65+
66+
-- Disable autovacuum temporarily (for demo)
67+
ALTER TABLE students SET (autovacuum_enabled = false);
68+
ALTER TABLE enrollments SET (autovacuum_enabled = false);
69+
70+
-- ========================================
71+
-- SELECT QUERIES
72+
-- ========================================
73+
74+
-- Get all students
75+
SELECT * FROM students;
76+
77+
-- Get all students enrolled in Mathematics
78+
SELECT s.first_name, s.last_name
79+
FROM students s
80+
JOIN enrollments e ON s.student_id = e.student_id
81+
JOIN classes c ON e.class_id = c.class_id
82+
WHERE c.name = 'Mathematics';
83+
84+
-- Count students per class
85+
SELECT c.name, COUNT(e.student_id) AS student_count
86+
FROM classes c
87+
LEFT JOIN enrollments e ON c.class_id = e.class_id
88+
GROUP BY c.name;
89+
90+
-- ========================================
91+
-- UPDATE QUERIES
92+
-- ========================================
93+
94+
-- Change Bob's last name
95+
UPDATE students
96+
SET last_name = 'Williams'
97+
WHERE first_name = 'Bob' AND last_name = 'Johnson';
98+
99+
-- Update the teacher for the History class
100+
UPDATE classes
101+
SET teacher = 'Ms. Carter'
102+
WHERE name = 'History';
103+
104+
-- ========================================
105+
-- DELETE QUERIES
106+
-- ========================================
107+
108+
-- Remove Charlie from Science class
109+
DELETE FROM enrollments
110+
WHERE student_id = (SELECT student_id FROM students WHERE first_name = 'Charlie')
111+
AND class_id = (SELECT class_id FROM classes WHERE name = 'Science');
112+
113+
-- Delete a student completely
114+
DELETE FROM students
115+
WHERE first_name = 'Alice' AND last_name = 'Smith';

pmm_qa/percona-distribution-postgresql/data/postgresql-primary.conf renamed to pmm_qa/percona-distribution-postgresql/data/postgresql-primary.conf.j2

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ max_wal_senders = 10
33
wal_keep_size = 64MB
44
hot_standby = on
55
listen_addresses = '*'
6-
hba_file = '/etc/postgresql/pg_hba.conf'
6+
hba_file = '/etc/postgresql/{{ pdpgsql_version }}/main/pg_hba.conf'
7+
data_directory = '/var/lib/postgresql/{{ pdpgsql_version }}/main'
78
shared_preload_libraries = 'pg_stat_monitor'
89
track_activity_query_size=2048
910
track_io_timing=ON

pmm_qa/percona-distribution-postgresql/data/postgres-replica.conf renamed to pmm_qa/percona-distribution-postgresql/data/postgresql-replica.conf.j2

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
hba_file = '/etc/postgresql/pg_hba.conf'
1+
hba_file = '/etc/postgresql/{{ pdpgsql_version }}/main/pg_hba.conf'
2+
data_directory = '/var/lib/postgresql/{{ pdpgsql_version }}/main'
23
shared_preload_libraries = 'pg_stat_monitor'
34
track_activity_query_size=2048
45
track_io_timing=ON
@@ -11,4 +12,4 @@ pg_stat_monitor.pgsm_enable_query_plan=1
1112
log_connections = on
1213
log_disconnections = on
1314
log_replication_commands = on
14-
log_statement = 'all'
15+
log_statement = 'all'
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
listen_addresses = '*'
2+
hba_file = '/etc/postgresql/{{ pdpgsql_version }}/main/pg_hba.conf'
3+
data_directory = '/var/lib/postgresql/{{ pdpgsql_version }}/main'
4+
shared_preload_libraries = 'pg_stat_monitor'
5+
track_activity_query_size=2048
6+
track_io_timing=ON
7+
max_connections=1000
8+
pg_stat_monitor.pgsm_enable_query_plan = 'yes'
9+
log_connections = on
10+
log_disconnections = on
11+
log_replication_commands = on
12+
log_statement = 'all'

pmm_qa/percona-distribution-postgresql/percona-distribution-postgres-setup.yml

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
connection: local
66
gather_facts: yes
77
vars:
8-
pg_version: "{{ lookup('env', 'PGSQL_VERSION') | default('17', true) }}"
8+
pdpgsql_version: "{{ lookup('env', 'PDPGSQL_VERSION') | default('17', true) }}"
99
replication_user: "repl_user"
1010
replication_password: "GRgrO9301RuF"
1111
root_password: "GRgrO9301RuF"
1212
pdpgsql_port: 5432
13-
nodes_count: "{{ (lookup('env', 'NODES_COUNT') | default('2', true)) | int }}"
13+
nodes_count: "{{ (lookup('env', 'NODES_COUNT') | default('1', true)) | int }}"
1414
network_name: "pmm-qa"
1515
data_dir: "{{ lookup('env', 'HOME') }}/pgsql_cluster_data"
1616
pmm_server_ip: "{{ lookup('vars', 'extra_pmm_server_ip', default=lookup('env','PMM_SERVER_IP') | default('127.0.0.1', true) ) }}"
@@ -21,12 +21,22 @@
2121
setup_type: "{{ lookup('env', 'SETUP_TYPE') }}"
2222
random_service_name_value: ""
2323
docker_repo: "percona/percona-distribution-postgresql"
24+
container_prefix: "pdpgsql_pmm{{ (setup_type|default('')) and '_' ~ setup_type }}_{{ pdpgsql_version }}_"
2425

2526
tasks:
26-
- name: Display binary log status for primary
27+
- name: Display setup type selected
2728
debug:
2829
msg: "{{ setup_type }}"
2930

31+
- name: Create Docker network
32+
shell: docker network create {{ network_name }}
33+
ignore_errors: yes
34+
become: true
35+
36+
- name: Install Percona Distribution for Postgres
37+
include_tasks: tasks/install-percona-distribution-postgresql-single.yml
38+
when: setup_type != "replication" and setup_type != "patroni"
39+
3040
- name: Install Percona Distribution for Postgres with Replication
3141
include_tasks: tasks/percona-distribution-postgres-replication-setup.yml
3242
when: setup_type == "replication"

0 commit comments

Comments
 (0)