PostgreSQLのデータベース一覧を表示する方法を以下に記します。
以下のコマンドでデータベース一覧をコマンドライン上で表示することができます。
psql -l
ホスト名やポート番号を指定する場合は以下のようになります。
psql -l -p ポート番号 -h ホスト名
$ psql -l
データベース一覧
名前 | 所有者 | エンコーディング | 照合順序 | Ctype(変換演算子) | アクセス権
-----------+----------+------------------+-------------+-------------------+-----------------------
foo | postgres | UTF8 | ja_JP.UTF-8 | ja_JP.UTF-8 |
postgres | postgres | UTF8 | ja_JP.UTF-8 | ja_JP.UTF-8 |
template0 | postgres | UTF8 | ja_JP.UTF-8 | ja_JP.UTF-8 | =c/postgres
: postgres=CTc/postgres
template1 | postgres | UTF8 | ja_JP.UTF-8 | ja_JP.UTF-8 | =c/postgres
: postgres=CTc/postgres
(4 行)
psqlのプロンプト上でデーターベース一覧を表示する場合は、以下のコマンドを実行します。
\l
$ psql postgres
psql (8.4.13)
"help" でヘルプを表示します.
postgres=# \l
データベース一覧
名前 | 所有者 | エンコーディング | 照合順序 | Ctype(変換演算子) | アクセス権
-----------+----------+------------------+-------------+-------------------+-----------------------
foo | postgres | UTF8 | ja_JP.UTF-8 | ja_JP.UTF-8 |
postgres | postgres | UTF8 | ja_JP.UTF-8 | ja_JP.UTF-8 |
template0 | postgres | UTF8 | ja_JP.UTF-8 | ja_JP.UTF-8 | =c/postgres
: postgres=CTc/postgres
template1 | postgres | UTF8 | ja_JP.UTF-8 | ja_JP.UTF-8 | =c/postgres
: postgres=CTc/postgres
(4 行)
以下のSQLでもデータベース一覧を表示することができます。
SELECT * FROM pg_database;
postgres=# SELECT * FROM pg_database;
datname | datdba | encoding | datcollate | datctype | datistemplate | datallowconn | datconnlimit | datlastsysoid | datfrozenxid | dattablespace | datco
nfig | datacl
-----------+--------+----------+-------------+-------------+---------------+--------------+--------------+---------------+--------------+---------------+------
-----+-------------------------------------
template1 | 10 | 6 | ja_JP.UTF-8 | ja_JP.UTF-8 | t | t | -1 | 11563 | 648 | 1663 |
| {=c/postgres,postgres=CTc/postgres}
template0 | 10 | 6 | ja_JP.UTF-8 | ja_JP.UTF-8 | t | f | -1 | 11563 | 648 | 1663 |
| {=c/postgres,postgres=CTc/postgres}
postgres | 10 | 6 | ja_JP.UTF-8 | ja_JP.UTF-8 | f | t | -1 | 11563 | 648 | 1663 |
|
foo | 10 | 6 | ja_JP.UTF-8 | ja_JP.UTF-8 | f | t | -1 | 11563 | 648 | 1663 |
|
(4 行)