You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Grant Default PRIVILEGES to tables. (also auto apply for new tables.)
ALTER DEFAULT PRIVILEGES FOR ROLE postgres IN SCHEMA public \
GRANTSELECT,INSERT,REFERENCES,TRIGGER,UPDATEON TABLES TO users001;
Disable pager in shell
\pset pager 0
List all tables and sorted by Size.
SELECT
schema_name,
relname,
pg_size_pretty(table_size) AS size,
table_size
FROM (
SELECTpg_catalog.pg_namespace.nspname AS schema_name,
relname,
pg_relation_size(pg_catalog.pg_class.oid) AS table_size
FROMpg_catalog.pg_classJOINpg_catalog.pg_namespaceON relnamespace =pg_catalog.pg_namespace.oid
) t
WHERE schema_name NOT LIKE'pg_%'ORDER BY table_size DESC;
List all schema=public tables detail sizes ()
SELECT*, pg_size_pretty(total_bytes) AS total
, pg_size_pretty(index_bytes) AS INDEX
, pg_size_pretty(toast_bytes) AS toast
, pg_size_pretty(table_bytes) AS TABLE
FROM (
SELECT*, total_bytes-index_bytes-COALESCE(toast_bytes,0) AS table_bytes
FROM (
SELECTc.oid,nspname AS table_schema, relname AS TABLE_NAME
, c.reltuplesAS row_estimate
, pg_total_relation_size(c.oid) AS total_bytes
, pg_indexes_size(c.oid) AS index_bytes
, pg_total_relation_size(reltoastrelid) AS toast_bytes
FROM pg_class c
LEFT JOIN pg_namespace n ONn.oid=c.relnamespaceWHERE relkind ='r'
) a
) a where table_schema ='public'ORDER BY total_bytes DESC;
ALTER TABLE public.users ALTER COLUMN column1 set COMPRESSION lz4;
List running queries
SELECT datname, pid, state, query, age(clock_timestamp(), query_start) AS age
FROM pg_stat_activity
WHERE state <>'idle'AND query NOT LIKE'% FROM pg_stat_activity %'ORDER BY age;