コマンド
表示系は末尾に+をつけると詳細表示になる
db接続
//psql -U ユーザ名 データベース名
# psql -U postgres testdb
Welcome to psql 8.3.15, the PostgreSQL interactive terminal.
遠隔接続
# psql -h 10.3.2.223 -p 5432 -U postgres -W  sampledb
データベースリスト出力
# \list
        List of databases
   Name    |  Owner   | Encoding
-----------+----------+----------
 sampledb  |  testuser    | UTF8
データベースに接続
# \c sampledb
You are now connected to database "sampledb".
テーブル確認
# \d
                List of relations
 Schema |       Name        |   Type   |  Owner
--------+-------------------+----------+----------
 public | goods             | table    | postgres
 public | goods_id_seq      | sequence | postgres
 public | items             | table    | postgres
 public | items_id_seq      | sequence | postgres
 public | schema_migrations | table    | postgres
(5 rows)
インデックス確認
# \di
                                   List of relations
 Schema |           Name           | Type  |  Owner   |       Table       | Description
--------+--------------------------+-------+----------+-------------------+-------------
 public | goods_pkey               | index | postgres | goods             |
 public | items_pkey               | index | postgres | items             |
 public | unique_schema_migrations | index | postgres | schema_migrations |
(3 rows)
表領域リスト出力
# \db
       List of tablespaces
    Name    |  Owner   | Location
------------+----------+----------
 pg_default | postgres |
 pg_global  | postgres |
(2 rows)
データベースサイズ確認
select datid,datname from pg_stat_database;
 datid |  datname
-------+-----------
     1 | template1
 11510 | template0
 11511 | postgres
 16385 | sampledb
(4 rows)
OS側で確認
# cd /usr/local/pgsql/data
# ls base
1  11510  11511  16385
パスワードリセット
# alter role postgres with password 'password';
外部接続設定
下記設定ファイルを記載し、リスタート
参考:http://rina.jpn.ph/~rance/linux/postgresql/connect.html
/usr/local/pgsql/data/postgresql.conf
listen_addresses = 'localaddr' ← DBサーバのインタフェースIP
port 5432
どのサーバ
/usr/local/pgsql/data/pg_hba.conf
host    all         all         10.3.2.0/24           md5
サーバリスタート
# /etc/rc.d/init.d/pgsql restart