Skip to content

Use cases

Oleg Gurov edited this page Oct 31, 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

Prepare the packet directory:

cd db_converter/packets
mkdir alert_max_connections

Make the packet and alert configuration:

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) as alert
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 and check output:

python3 db_converter.py --packet-name=alert_max_connections --db=name=some_db

>>
	----------------------------------------------------------------------
	| alert                                                              |
	----------------------------------------------------------------------
	| Low number of free connections: 98 (6.67%) [max_connections = 105] |

DBA tasks

Dev tasks

Clone this wiki locally