From 89a8745430c7f2796c8fad2304e23b6c843714ab Mon Sep 17 00:00:00 2001 From: kirby Date: Wed, 21 May 2025 09:12:31 +0200 Subject: [PATCH] adding postgresql --- postgresql/cli.md | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 postgresql/cli.md diff --git a/postgresql/cli.md b/postgresql/cli.md new file mode 100644 index 0000000..beaa777 --- /dev/null +++ b/postgresql/cli.md @@ -0,0 +1,28 @@ +### Get list of users and numbers of active connections + +```sql +SELECT + datname AS database_name, + usename AS user_name, + count(*) AS active_connections +FROM pg_stat_activity +GROUP BY datname, usename order by active_connections DESC; +``` + +### Limit number of connections for user + +```sql +alter user keycloak connection limit 80;ALTER ROLE +``` + +### Remove limit number of connections for user + +```sql +alter user keycloak connection limit -1;ALTER ROLE +``` + +### Get replication status + +```sql +select * from pg_stat_replication; +```