PostgreSQL
 sql >> Base de données >  >> RDS >> PostgreSQL

Comment lister toutes les bases de données et leurs schémas dans postgresql ?

La requête suivante fournira le même résultat que \l+ dans psql à partir de PostgreSQL 9.4.1 :

SELECT
  d.datname as "Name",
  pg_catalog.pg_get_userbyid(d.datdba) as "Owner",
  pg_catalog.pg_encoding_to_char(d.encoding) as "Encoding",
  d.datcollate as "Collate",
  d.datctype as "Ctype",
  pg_catalog.array_to_string(d.datacl, E'\n') as "Access privileges",
  CASE WHEN pg_catalog.has_database_privilege(d.datname, 'CONNECT')
    THEN pg_catalog.pg_size_pretty(pg_catalog.pg_database_size(d.datname))
    ELSE 'No Access'
  END as "Size",
  t.spcname as "Tablespace",
  pg_catalog.shobj_description(d.oid, 'pg_database') as "Description"
FROM
  pg_catalog.pg_database d
JOIN
  pg_catalog.pg_tablespace t on d.dattablespace = t.oid
ORDER BY 1;

Voici la source :src/ bin/psql/describe.c