[[PostgreSQL]]

~
*ログイン・ログアウト [#a7f2a35b]
 # su postgres
 $ psql
 $ ¥q

*バージョン確認 [#n1b571ff]
 # su postgres
 $ psql
 $ select version();
 
  PostgreSQL 8.1.23 on i686-pc-linux-gnu, compiled by GCC gcc (GCC) 3.2.2 20030222 (Red Hat Linux 3.2.2-5)
(1 row)

*PostgreSQL 起動 [#s49b8d04]
 [postgres@www ~]$ pg_ctl start -D /home/postgres/data -w
 -D initdbしたディレクトリ、起動中の場合はps aux | grep postgresで確認可能。
 -w 起動もしくは停止処理が終了するのを待ちます。60秒でタイムアウトします。停止処理のデフォルトです。

*PostgreSQL停止 [#ha608020]
 [postgres@www ~]$ pg_ctl stop -D /home/postgres/data
 
*PostgreSQL再起動 [#ke01e354]
 [postgres@www ~]$ pg_ctl restart -D /home/postgres/data
 
*PostgreSQL設定ファイル再読み込み [#ocf771da]
 [postgres@www ~]$ pg_ctl reload -D /home/postgres/data

*ユーザーの確認 [#b2a5b411]
 [postgres@www ~]$ psql
 postgres=# select * from pg_user;
 usename  | usesysid | usecreatedb | usesuper | usecatupd |  passwd  | valuntil | useconfig
 ----------+----------+-------------+----------+-----------+----------+----------+-----------
  postgres |       10 | t           | t        | t         | ******** |          |

*ユーザー作成 [#d9bbb0a8]
 [postgres@www ~]$ createuser -U postgres -P
 Enter name of role to add: hogeuser
 Enter password for new role:
 Enter it again:
 Shall the new role be a superuser? (y/n) n
 Shall the new role be allowed to create databases? (y/n) n
 Shall the new role be allowed to create more new roles? (y/n) n
 
 [postgres@www ~]$ psql
 postgres=# select * from pg_user;
  usename  | usesysid | usecreatedb | usesuper | usecatupd |  passwd  | valuntil | useconfig
 ----------+----------+-------------+----------+-----------+----------+----------+-----------
  postgres |       10 | t           | t        | t         | ******** |          |
  hogeuser |    16390 | f           | f        | f         | ******** |          |
 (2 rows) 

*データベースの確認 [#i74e089e]
 その1
 [postgres@www ~]$ psql -l
    Name    |  Owner   | Encoding  | Collation | Ctype |   Access privileges
 -----------+----------+-----------+-----------+-------+-----------------------
  postgres  | postgres | SQL_ASCII | C         | C     |
  template0 | postgres | SQL_ASCII | C         | C     | =c/postgres          +
            |          |           |           |       | postgres=CTc/postgres
  template1 | postgres | SQL_ASCII | C         | C     | =c/postgres          +
            |          |           |           |       | postgres=CTc/postgres
 
 その2
 [postgres@www ~]$ psql
 postgres=# select oid, datname from pg_database;
   oid  |  datname
 -------+-----------
      1 | template1
  11866 | template0
  11874 | postgres
 (3 rows)
 oidは/home/postgres/data/baseの下にある。

*データベースの作成 [#z3a8038e]
 [postgres@www ~]$ createdb -U postgres testdb01;
 [postgres@www ~]$ psql -l
                              List of databases
    Name    |  Owner   | Encoding  | Collation | Ctype |   Access privileges
 -----------+----------+-----------+-----------+-------+-----------------------
  postgres  | postgres | SQL_ASCII | C         | C     |
  template0 | postgres | SQL_ASCII | C         | C     | =c/postgres          +
            |          |           |           |       | postgres=CTc/postgres
  template1 | postgres | SQL_ASCII | C         | C     | =c/postgres          +
            |          |           |           |       | postgres=CTc/postgres
  testdb01  | postgres | SQL_ASCII | C         | C     |
 (4 rows)

*データベースの表示 [#qe39bee8]
 [postgres@www ~]$ psql
 postgres=# ¥l
                               List of databases
    Name    |  Owner   | Encoding  | Collation | Ctype |   Access privileges
 -----------+----------+-----------+-----------+-------+-----------------------
  postgres  | postgres | SQL_ASCII | C         | C     |
  template0 | postgres | SQL_ASCII | C         | C     | =c/postgres          +
            |          |           |           |       | postgres=CTc/postgres
  template1 | postgres | SQL_ASCII | C         | C     | =c/postgres          +
            |          |           |           |       | postgres=CTc/postgres
  testdb01  | postgres | SQL_ASCII | C         | C     |
 (4 rows)

*データベースの選択 [#sbd6e62c]
 postgresq# ¥c testdb
 You are now connected to database "testdb".

*テーブル一覧表示 [#p5e262ed]
 testdb# ¥dt

トップ   編集 差分 履歴 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS