Skip to content

Instantly share code, notes, and snippets.

View tristantreb's full-sized avatar

tristan tristantreb

View GitHub Profile
@tristantreb
tristantreb / conn_status.sql
Created June 27, 2023 13:58
PostgreSQL connection status (used, res_for_super, max_conn)
select * from
(select count(*) used from pg_stat_activity) q1,
(select setting::int res_for_super from pg_settings where name=$$superuser_reserved_connections$$) q2,
(select setting::int max_conn from pg_settings where name=$$max_connections$$) q3;
@tristantreb
tristantreb / read-access.sql
Created June 5, 2023 16:35 — forked from oinopion/read-access.sql
How to create read only user in PostgreSQL
-- Create a group
CREATE ROLE readaccess;
-- Grant access to existing schemas & tables, and to future tables (as of now you can't grant access to future schemas)
DO
$do$
DECLARE
sch text;
BEGIN
FOR sch IN