Skip to content

Use cases

Oleg Gurov edited this page Oct 30, 2020 · 50 revisions

Various tasks can be solved using the db_converter. This page covers the most simple and useful examples. More examples see in packets directory.

Alerts

Hooks can be used to deliver alerts.

How to determine the low number of possible new connections

Configure packet:

cd db_converter/packets
mkdir alert_max_connections
cat > alert_max_connections/01_step.sql << EOL
SELECT format('Low number of free connections: %s (%s) [max_connections = %s]', T.c, T.v || '%', T.s)
FROM (
	SELECT
		round(((select count(1) from pg_stat_activity) * 100)::numeric / setting::integer, 2) as v,
		setting::integer - (select count(1) from pg_stat_activity) as c,
		setting as s
	FROM pg_settings
	WHERE name = 'max_connections'
) T WHERE T.v > 70
EOL


cat > alert_max_connections/meta_data.json << EOL
{
	"description": "Check available connections",
	"type": "read_only",
	"client_min_messages": "INFO",
	"hook": {
		"type": "matterhook",
		"username": "db_converter",
		"verbosity": ["resultset"],
		"channel": "dbc-alert",
		"message": ":warning: @here Found problem with max_connections:"
	}
}

Run packet:

DBA tasks

Dev tasks

Clone this wiki locally