Get DB owner's name in PostgreSql

后端 未结 7 2165
忘了有多久
忘了有多久 2020-12-15 02:07

I have DB \"test\" in PostgreSql. I want to write sql to get owner my database.

7条回答
  •  盖世英雄少女心
    2020-12-15 02:51

    This work with database owned by group role:

    SELECT
        U.rolname
       ,D.datname
    FROM
        pg_roles AS U JOIN pg_database AS D ON (D.datdba = U.oid)
    WHERE
        D.datname = current_database();
    

    Using pg_authid (as I did in my previous version) instead of pg_roles is limited to SuperUser because it holds password (see documentation):

    Since this catalog contains passwords, it must not be publicly readable. pg_roles is a publicly readable view on pg_authid that blanks out the password field.

提交回复
热议问题