Windows web server --- PostgreSQL 8.2.x---   18Jan2008   >>TOP

データベースを作成するのにインストールしておくと便利である。PHPとの連携もよく使いやすい。

PostgresSQL 8.2.x インストール

ソースの入手先: http://www.postgresql.jp/
マニュアル: PostgreSQL
postgresql-8.2.6-1-ja.zip をダウンロードして,解凍すると以下の3つのファイルができる。
  • README.txt
  • postgresql-8.2-ja.msi
  • upgrade.bat
インストールする前に古いバージョンが既にインストールされている場合は,まずアンインストールを行い,C:\Program Files\ にある PostgreSQLフォルダを削除する。
postgresユーザが削除されてない可能性があるのでコマンドプロンプトを開き以下のコマンドで削除しておく。
net user postgres /delete

インストール
postgresql-8.2-ja.msi をダブルクリックしてインストールを開始する。

  1. ダウンロードした postgresql-8.2-ja.msi をダブルクリック
  2. 次へ (をクリック) [Fig.1]
  3. 次へ (をクリック) [Fig.2]
  4. 次へ (をクリック) [Fig.3]
  5. 次へ (をクリック) [Fig.4]
  6. はい (をクリック) [Fig.5]
  7. OK (をクリック) [Fig.6]
  8. パスワードを入力(ここでは postgres としておく)し,次へ (をクリック) [Fig.7]
  9. 次へ (をクリック) [Fig.8]
  10. 次へ (をクリック) [Fig.9]
  11. 次へ (をクリック) [Fig.10]
    しばらく待つ [Fig.11]
  12. 終わる (をクリック) [Fig.12]

データベースの操作
  • スタート ⇒ すべてのプログラム ⇒ PostgreSQL 8.2 ⇒コマンド・プロンプト(選ぶ)
    (太字は入力部)

  • sampledbというデータベースの作成例:
    createdb -U postgres sampledb
    (Password:postgres)
    CREATE DATABASE

  • sampledbにアクセス:
    psql -U postgres sampledb
    (Password for user postgres:postgres)
    Welcome to psql 8.2.6, the PostgreSQL interactive terminal.

    Type: \copyright for distribution terms
    \h for help with SQL commands
    \? for help with psql commands
    \g or terminate with semicolon to execute query
    \q to quit

    sampledb=#

  • sampledb内にテーブル(table1)を作成:
    sampledb=# CREATE TABLE table1(id integer primary key,
    sampledb(# name varchar(50),
    sampledb(# comment text)
    sampledb-# WITH OIDS;
    NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "table1_pkey" for
    table "table1"
    CREATE TABLE
    sampledb=#

  • sampledb内のtable1を削除:
    sampledb=# DROP TABLE table1;
    DROP TABLE
    sampledb=#
  • データベースから抜ける
    sampledb=# \q

  • sampledbというデータベースの削除例:
    dropdb -U postgres sampledb
    (Password:postgres)
    DROP DATABASE