LoginSignup
1
1

More than 5 years have passed since last update.

postgresqlでデータベースの一覧をSQLで取得する

Posted at

短いTIPSなので、さっそく本題に。

psql -d "postgres" -h {host} -U postgres
SELECT 
  d.datname AS "Name",
  a.rolname AS "Owner",
  pg_encoding_to_char(d.encoding) AS "Encoding",
  d.datcollate AS "Collation",
  d.datctype AS "Ctype",
  d.datacl AS "Access privileg"
FROM pg_database d
  JOIN pg_authid a ON a.OID = d.datdba
;

こんな感じでリストが取得できるはずです。

Name Owner Encoding Collation Ctype Access privileges
postgres postgres UTF8 en_US.UTF-8 en_US.UTF-8
template0 postgres UTF8 en_US.UTF-8 en_US.UTF-8 {=c/postgres,postgres=CTc/postgres}
template1 postgres UTF8 en_US.UTF-8 en_US.UTF-8 {=c/postgres,postgres=CTc/postgres}

ではでは。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1