\l -- list all databases\c mydb -- switch to database\dt -- list all tables\dt schema.* -- list tables in specific schema\d tablename -- describe table (columns, types, constraints)\dn -- list schemas\du -- list users/roles\q -- quit
-- list all tables with row countSELECT relname, n_live_tupFROM pg_stat_user_tablesORDER BY n_live_tup DESC;-- show running queriesSELECT pid, query, state, now() - query_start AS durationFROM pg_stat_activityWHERE state != 'idle';-- kill a querySELECT pg_terminate_backend(pid);-- show table sizeSELECT pg_size_pretty(pg_total_relation_size('tablename'));-- show all indexes on a tableSELECT indexname, indexdef FROM pg_indexes WHERE tablename = 'tablename';