Allow postgres user to only list his own database

前端 未结 4 1619
温柔的废话
温柔的废话 2021-02-15 12:50

I\'m using a postgresql server and I want to forbid my users to see what other databases are on the same server.

Essentially a \\l should only list his own

4条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-15 13:36

    I would imagine this might have negative repercussions for the user, such as not being able to connect to the database since the system does not have access to the sytem tables, not sure though. But as far as figuring out what table to revoke - this a good general way to see what the psql meta commands are doing:

    To see what \l is doing you can also use the -E flag from the command line with psql.

    ~$ psql -E -c '\l'
    ********* QUERY **********
    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 "Collation",
           d.datctype as "Ctype",
           pg_catalog.array_to_string(d.datacl, E'\n') AS "Access privileges"
    FROM pg_catalog.pg_database d
    ORDER BY 1;
    **************************
    

    So if the user does not have access to pg_database they will not be able to use the \l command.

提交回复
热议问题