Thread: hide databases/users from normal postgres user

hide databases/users from normal postgres user

From
"Mario Weilguni"
Date:
Is it possible to hide the list of databases. The query is
SELECT d.datname as "Name",
       u.usename as "Owner"
FROM pg_database d LEFT JOIN pg_user u ON d.datdba = u.usesysid
ORDER BY 1;

so I tried to play with rules like this one:
create rule hide_db as on select to pg_database
do instead
SELECT datname, datdba, encoding, datistemplate, datallowconn,
datlastsysoid, datvacuumxid, datfrozenxid, datpath, datconfig, datacl
FROM pg_catalog.pg_database d
where (
       exists (select 1 from pg_user where current_user = usename and
usesuper = true)
       or
       d.datname=current_user
      )
ORDER BY 1;

This would allow a user to see only "his" databases, but that seems to be
impossible to achieve with a rule. Same rules would be for pg_user. A
"revoke select on pg_database" seems to work too, but imo this is not the
best approach. And I'm not sure if a "revoke select on pg_user" will break
the database system.

Regards,
    Mario Weilguni