Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get DB owner's name in PostgreSql

Tags:

postgresql

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

like image 404
mindia Avatar asked Jun 18 '13 09:06

mindia


People also ask

How do I find the owner of a Postgres database?

You can use current_database() if you need to dynamically find out which database you are connected to and which owner you are interested in. You can remove the where clause to get owners of all databases in the current cluster.

What is table owner in PostgreSQL?

The owner is (if nothing else happened) the user (role) that created the table. So if user arthur runs create table foo (id integer) , arthur owns the table. The owner of a table has all privileges on it - including the privilege to drop it. Or the privilege to grant other users (roles) access to the table.

How do I list users in PostgreSQL?

Use \du or \du+ psql command to list all users in the current database server. Use the SELECT statement to query the user information from the pg_catalog. pg_user catalog.


2 Answers

You can find such things in the system catalog

SELECT d.datname as "Name", pg_catalog.pg_get_userbyid(d.datdba) as "Owner" FROM pg_catalog.pg_database d WHERE d.datname = 'database_name' ORDER BY 1; 
like image 58
DrColossos Avatar answered Nov 20 '22 20:11

DrColossos


If you use the psql command-line tool, you can simply use \l

like image 24
gilad905 Avatar answered Nov 20 '22 20:11

gilad905