The Postgres Operator from Crunchy Data
For more information, see CrunchyData/postgres-operator: Production PostgreSQL for Kubernetes, from high availability Postgres clusters to full-scale database-as-a-service.
Move database from a cluster to another
Section titled “Move database from a cluster to another”pg_dump --dbname=postgresql://postgres:PASSWORD@10.42.5.56:5432/DATABASE | psql "host=localhost port=5432 dbname=DATABASE user=postgres password=PASSWORD"Restore
Section titled “Restore”kubectl -n inma-postgresql exec -i postgresql-postgresql-ha-postgresql-0 -- env PGPASSWORD=XXXXX pg_restore -U postgres -d database-name < database-file.dumpRestart cluster
Section titled “Restart cluster”kubectl patch postgrescluster/inmadbs -n inma-postgresql --type merge --patch '{"spec":{"metadata":{"annotations":{"restarted":"'"$(date)"'"}}}}'- Set Retain policy to Retained
Storage Resize
Section titled “Storage Resize”- Make sure there is double free space in the storage
- Add new instance (with desired size)
- Check if replicas are done via select * from pg_stat_replication;
- Remove old instance
Client Connections
Section titled “Client Connections”- Use connection pool (pgBouncer)
- Create a manager user with idle_session_timeout set to 5m using command
set idle_session_timeout to 300000;ALTER ROLE manager SET idle_session_timeout = 300000; (to specific role)- Monitor connections using
SELECT sum(numbackends) FROM pg_stat_database;SELECT * FROM pg_stat_activity order by state_change;show max_connections;SELECT count(*), state FROM pg_stat_activity GROUP BY 2;SHOW idle_session_timeout;