Skip to content

Commit a526879

Browse files
committed
[+] improve development experience with docker compose
- add "demo_pgbouncer" and "demo_pgpool" test monitored sources - add "debug" preset with all built-in - fix "pgpool" and "pgbouncer" compose service - fix "postgres-standby" service init
1 parent b38f62d commit a526879

File tree

6 files changed

+136
-34
lines changed

6 files changed

+136
-34
lines changed

README.md

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ For the fastest development and deployment experience the Docker compose files a
5050
docker compose -f ./docker/docker-compose.yml build
5151
5252
docker compose -f ./docker/docker-compose.yml up --detach
53+
54+
docker/compose.add-test-db.sh
5355
```
5456

5557
These commands will build and start services listed in the compose file:
@@ -70,22 +72,7 @@ These commands will build and start services listed in the compose file:
7072
After start, you could open the [monitoring dashboard](http://localhost:3000/) and start
7173
looking at metrics.
7274

73-
To add a test database under monitoring, you can use [built-in WebUI](http://localhost:8080/). Or simply
74-
execute from command line:
75-
76-
```shell
77-
docker/compose.add-test-db.sh
78-
```
79-
80-
```console
81-
CREATE EXTENSION
82-
CREATE EXTENSION
83-
CREATE FUNCTION
84-
GRANT
85-
GRANT
86-
GRANT
87-
INSERT 0 1
88-
```
75+
To add a test database under monitoring, you can use [built-in WebUI](http://localhost:8080/).
8976

9077
## Produce Workload
9178

docker/compose.add-test-db.sh

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,19 @@ cd "$(dirname "${BASH_SOURCE[0]}")"
55
export MSYS_NO_PATHCONV=1
66

77
# We want to pipe the output of the `pgwatch metric print-init` command to the `psql` command
8-
docker compose exec -T pgwatch /pgwatch/pgwatch metric print-init full | \
8+
docker compose exec -T pgwatch /pgwatch/pgwatch metric print-init debug | \
99
docker compose exec -T -i postgres psql -d pgwatch -v ON_ERROR_STOP=1
1010

11-
docker compose exec -T postgres psql -d pgwatch -v ON_ERROR_STOP=1 -c \
12-
"INSERT INTO pgwatch.source (name, preset_config, connstr) VALUES
13-
('demo', 'full', 'postgresql://pgwatch:pgwatchadmin@postgres/pgwatch'),
14-
('demo_standby', 'full', 'postgresql://pgwatch:pgwatchadmin@postgres-standby/pgwatch')"
15-
16-
11+
docker compose exec -T pgwatch /pgwatch/pgwatch metric print-init full | \
12+
docker compose exec -T -i postgres psql -d pgwatch_metrics -v ON_ERROR_STOP=1
1713

14+
docker compose exec -T postgres psql -d pgwatch -v ON_ERROR_STOP=1 -c \
15+
"TRUNCATE pgwatch.source CASCADE;
16+
INSERT INTO pgwatch.source
17+
(name, dbtype, preset_config, connstr)
18+
VALUES
19+
('demo', 'postgres', 'debug', 'postgresql://pgwatch:pgwatchadmin@postgres/pgwatch'),
20+
('demo_metrics', 'postgres', 'full', 'postgresql://pgwatch:pgwatchadmin@postgres/pgwatch_metrics'),
21+
('demo_standby', 'postgres', 'full', 'postgresql://pgwatch:pgwatchadmin@postgres-standby/pgwatch'),
22+
('demo_pgbouncer', 'pgbouncer', 'pgbouncer', 'postgresql://pgwatch:pgwatchadmin@pgbouncer/pgbouncer'),
23+
('demo_pgpool', 'pgpool', 'pgpool', 'postgresql://pgwatch:pgwatchadmin@pgpool/pgwatch');"

docker/compose.pgbouncer.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,16 @@ services:
33
image: bitnami/pgbouncer:latest
44
container_name: pgbouncer
55
ports:
6-
- "6432:6432"
6+
- "6432:5432"
77
environment:
88
POSTGRESQL_HOST: postgres
9+
POSTGRESQL_PORT: 5432
10+
POSTGRESQL_USERNAME: pgwatch
11+
POSTGRESQL_PASSWORD: pgwatchadmin
12+
POSTGRESQL_DATABASE: pgwatch
913
PGBOUNCER_AUTH_TYPE: trust
14+
PGBOUNCER_POOL_MODE: session
15+
PGBOUNCER_PORT: 5432
1016
depends_on:
1117
postgres:
1218
condition: service_healthy

docker/compose.pgpool.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ services:
99
PGPOOL_SR_CHECK_USER: postgres
1010
PGPOOL_SR_CHECK_PASSWORD: standbypass
1111
PGPOOL_ENABLE_LDAP: no
12-
PGPOOL_POSTGRES_USERNAME: postgres
13-
PGPOOL_POSTGRES_PASSWORD: adminpassword
14-
PGPOOL_ADMIN_USERNAME: admin
15-
PGPOOL_ADMIN_PASSWORD: adminpassword
12+
PGPOOL_POSTGRES_USERNAME: pgwatch
13+
PGPOOL_POSTGRES_PASSWORD: pgwatchadmin
14+
PGPOOL_ADMIN_USERNAME: pgwatch
15+
PGPOOL_ADMIN_PASSWORD: pgwatchadmin
1616
depends_on:
1717
postgres:
1818
condition: service_healthy

docker/compose.postgres.yml

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,36 @@ services:
4141
depends_on:
4242
postgres:
4343
condition: service_healthy
44-
command: >
45-
bash -c "psql -h postgres -c \"SELECT * FROM pg_create_physical_replication_slot('standby_slot')\" ||
46-
rm -rf /var/lib/postgresql/data/* &&
47-
pg_basebackup -h postgres --pgdata=/var/lib/postgresql/data --wal-method=stream --progress --write-recovery-conf --slot=standby_slot &&
48-
chmod 0700 /var/lib/postgresql/data &&
49-
postgres -cshared_preload_libraries=pg_stat_statements -cpg_stat_statements.track=all -ctrack_io_timing=on -ctrack_functions=pl"
44+
command: |
45+
bash -c "
46+
echo 'Setting up standby server...'
47+
export PGDATA=/var/lib/postgresql/standby
48+
49+
# Check if data directory already exists and is initialized
50+
if [ -f /var/lib/postgresql/standby/PG_VERSION ]; then
51+
echo 'Data directory already exists and is initialized, starting PostgreSQL...'
52+
else
53+
echo 'Initializing new standby server...'
54+
55+
# Create replication slot if it doesn't exist
56+
psql -h postgres -U postgres -c \"SELECT * FROM pg_create_physical_replication_slot('standby_slot');\" 2>/dev/null || true
57+
58+
# Create custom data directory with correct permissions
59+
mkdir -p /var/lib/postgresql/standby
60+
chmod 0700 /var/lib/postgresql/standby
61+
62+
# Remove any existing files to ensure clean backup
63+
rm -rf /var/lib/postgresql/standby/* || true
64+
65+
# Create base backup directly to our custom directory
66+
pg_basebackup -h postgres -U postgres -D /var/lib/postgresql/standby -Xs -P -R -S standby_slot
67+
68+
# Ensure correct permissions after backup
69+
chmod 0700 /var/lib/postgresql/standby
70+
fi
71+
72+
# Start PostgreSQL with custom data directory
73+
exec postgres -D /var/lib/postgresql/standby -c shared_preload_libraries=pg_stat_statements -c pg_stat_statements.track=all -c track_io_timing=on -c track_functions=pl
74+
"
5075
links:
5176
- postgres

internal/metrics/metrics.yaml

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4912,3 +4912,81 @@ presets:
49124912
table_io_stats: 600
49134913
table_stats: 300
49144914
wal: 60
4915+
debug:
4916+
description: all available metrics with 30 second intervals for debugging and development
4917+
metrics:
4918+
archiver: 30
4919+
archiver_pending_count: 30
4920+
backends: 30
4921+
backup_age_pgbackrest: 30
4922+
backup_age_walg: 30
4923+
bgwriter: 30
4924+
blocking_locks: 30
4925+
buffercache_by_db: 30
4926+
buffercache_by_type: 30
4927+
change_events: 30
4928+
checkpointer: 30
4929+
configuration_hashes: 30
4930+
cpu_load: 30
4931+
database_conflicts: 30
4932+
datfrozenxid: 30
4933+
db_size: 30
4934+
db_size_approx: 30
4935+
db_stats: 30
4936+
db_stats_aurora: 30
4937+
index_hashes: 30
4938+
index_stats: 30
4939+
instance_up: 30
4940+
invalid_indexes: 30
4941+
kpi: 30
4942+
locks: 30
4943+
locks_mode: 30
4944+
logical_subscriptions: 30
4945+
pgbouncer_clients: 30
4946+
pgbouncer_stats: 30
4947+
pgpool_processes: 30
4948+
pgpool_stats: 30
4949+
postgres_role: 30
4950+
privilege_changes: 30
4951+
psutil_cpu: 30
4952+
psutil_disk: 30
4953+
psutil_disk_io_total: 30
4954+
psutil_mem: 30
4955+
reco_add_index: 30
4956+
reco_default_public_schema: 30
4957+
reco_disabled_triggers: 30
4958+
reco_drop_index: 30
4959+
reco_nested_views: 30
4960+
reco_partial_index_candidates: 30
4961+
reco_sprocs_wo_search_path: 30
4962+
reco_superusers: 30
4963+
replication: 30
4964+
replication_slot_stats: 30
4965+
replication_slots: 30
4966+
sequence_health: 30
4967+
server_log_event_counts: 30
4968+
settings: 30
4969+
smart_health_per_disk: 30
4970+
sproc_hashes: 30
4971+
sproc_stats: 30
4972+
stat_activity: 30
4973+
stat_io: 30
4974+
stat_ssl: 30
4975+
stat_statements: 30
4976+
stat_statements_calls: 30
4977+
stat_statements_no_query_text: 30
4978+
subscription_stats: 30
4979+
table_bloat_approx_stattuple: 30
4980+
table_bloat_approx_summary: 30
4981+
table_bloat_approx_summary_sql: 30
4982+
table_hashes: 30
4983+
table_io_stats: 30
4984+
table_stats: 30
4985+
table_stats_approx: 30
4986+
unused_indexes: 30
4987+
vmstat: 30
4988+
wait_events: 30
4989+
wal: 30
4990+
wal_receiver: 30
4991+
wal_size: 30
4992+
wal_stats: 30

0 commit comments

Comments
 (0)