RagePwn
RagePwn

Reputation: 421

How do I find what user owns a HIVE database?

I want to confirm which user is the owner of a database in HIVE. Where would I find this information?

Upvotes: 4

Views: 35658

Answers (3)

Indrajeet Gour
Indrajeet Gour

Reputation: 4500

Both will solve your problem:

hive> describe database extended db_name;

hive> describe schema extended db_name;

The output will have the owner user name.

Upvotes: 0

Ronak Patel
Ronak Patel

Reputation: 3849

DESCRIBE|DESC DATABASE shows the name of the database, its comment (if one has been set), and its root location on the filesystem. The uses of SCHEMA and DATABASE are interchangeable – they mean the same thing. DESCRIBE SCHEMA is added in Hive 0.15 (HIVE-8803).

EXTENDED also shows the database properties.

DESCRIBE DATABASE [EXTENDED] db_name;
DESCRIBE SCHEMA [EXTENDED] db_name;     -- (Note: Hive 0.15.0 and later)

These examples show that cards database was created by cloudera user:

hive> SET hive.cli.print.header=true;
hive> describe database cards;
OK
db_name comment location    owner_name  owner_type  parameters
cards       hdfs://quickstart.cloudera:8020/user/hive/warehouse/cards.db    cloudera    USER    
Time taken: 0.013 seconds, Fetched: 1 row(s)

hive> desc schema cards;
OK
db_name comment location    owner_name  owner_type  parameters
cards       hdfs://quickstart.cloudera:8020/user/hive/warehouse/cards.db    cloudera    USER    
Time taken: 0.022 seconds, Fetched: 1 row(s)

Alternatively,

Hive database is nothing but a hdfs directory in Hive warehouse dir location with .db extension. You can get user by simply from hadoop fs -ls command:

For a directory it returns list of its direct children as in Unix. A directory is listed as:

permissions userid groupid modification_date modification_time dirname

Files within a directory are order by filename by default.

Example:

hadoop fs -ls /user/hive/warehouse/*.db |awk '{print $3,$NF}'

Upvotes: 7

Aditya
Aditya

Reputation: 2415

If you have configured the hive to an external metastore like mysql or derby , you can query the metastore table DBS to get the information .

Query

select NAME,OWNER_NAME,OWNER_TYPE from DBS;

Output

+--------------+------------+------------+
| NAME         | OWNER_NAME | OWNER_TYPE |
+--------------+------------+------------+
| default      | public     | ROLE       |
| employee     | addy       | USER       |
| test         | addy       | USER       |

Upvotes: -1

Related Questions