-- Muestra gratuita: resumen de conexiones. Solo lectura.
SELECT COALESCE(datname, '[sin base de datos]') AS database_name,
       COALESCE(state, '[sin estado]') AS connection_state,
       count(*) AS connections
FROM pg_stat_activity
GROUP BY datname, state
ORDER BY connections DESC;
