I tried to create a system which changes the number of replicas in Postgres based on system metrics - latency, I/O operations, read/write frequency and CPU usage. I know that those metrics are available in pg_stat_* tables (for example pg_stat_statement or pg_stat_replication).
At the beginning I had a plan to periodically check those metrics (by querying them) and then based on same thresholds make a decision to add/remove a replica (or even replicas). But then I found out that I can use triggers for the purpose and do it "asynchronously" (instead of polling).
But as far as I see those "metrics" tables in Postgres (and probably in other databases too) are views and because of that I cannot create a trigger on them. Am I right? And if so - what do you recommend to solve this issue? Go back to my solution with polling data from pg_stat?