PostgreSQL
オープンソースのデータベース。
高機能なRDBMS(リレーショナルデーターベース管理システム)
1.インストール(Linux)
@PostgreSQLがインストールされているか確認
(最近のLinuxにはPostgreSQLが入っている)
[root@hostname root]# rpm -aq|grep postgresql
postgresql-7.2.1-5
postgresql-devel-7.2.1-5
postgresql-libs-7.2.1-5
postgresql-server-7.2.1-5
[root@hostname root]#
|
上記のように表示されれば、インストールされている。
新しいバージョンにしたい場合はRPMをダウンロード。
APostgreSQLのRPMをダウンロード
ftp://ftp6.jp.postgresql.org/postgresql/binary/
Bインストール
[root@hostname src]# rpm -Uhv postgresql-*.rpm
Preparing... ########################################### [100%]
1:postgresql-jdbc ########################################### [ 20%]
2:postgresql-libs ########################################### [ 40%]
3:postgresql ########################################### [ 60%]
4:postgresql-devel ########################################### [ 80%]
5:postgresql-server ########################################### [100%]
[root@hostname src]#
|
2.データーベースの起動
root権限にてコマンド実行
# /etc/rc.d/init.d/postgresql start
[root@hostname src]# /etc/rc.d/init.d/postgresql start
Starting postgresql service: [ OK ]
[root@hostname src]#
|
3.データーベースの作成
@postgresユーザーに変更
[root@hostname src]# su - postgres
bash-2.05a$
|
Aデーターベースの作成
# createdb -E EUC_JP データベース名
『jspdb』を作成
bash-2.05a$ createdb -E EUC_JP jspdb
CREATE DATABASE
bash-2.05a$
|
4.対話型PostgreSQLクライアント
@起動
# psql データベース名
bash-2.05a$ psql jspdb
Welcome to psql, the PostgreSQL interactive terminal.
Type: \copyright for distribution terms
\h for help with SQL commands
\? for help on internal slash commands
\g or terminate with semicolon to execute query
\q to quit
jspdb=#
|
Aテーブルの作成
SQL文実行
※ 対話型ツール起動中は、一般的なSQL文にて命令。
jspdb=# CREATE TABLE HELLO_WORLD_TABLE (
jspdb(# NO INTEGER NOT NULL,
jspdb(# LANGUAGE VARCHAR(50),
jspdb(# MESSAGE VARCHAR(100),
jspdb(# PRIMARY KEY(NO)
jspdb(# );
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index 'hello_world_table_pkey' for table 'hello_world_table'
CREATE
jspdb=#
|
コマンドラインから、シェルを実行させることも可能
bash-2.05a$ psql db_name < *.sql (→db_name:データベース名)
B終了
\q
5.PostgreSQLの停止方法
# /etc/rc.d/init.d/postgresql stop
[root@hostname javahello]# /etc/rc.d/init.d/postgresql stop
PostgreSQLサービスを停止中: [ OK ]
[root@hostname javahello]#
|
6.PostgreSQLをTCP/IPで接続
@PostgreSQLの本体のpostmasterというプログラム実行する際に、「-i」オプションを付ける。
※ /etc/rc.d/init.d/postgresqlスクリプトの160行目付近にある文を変更
『su -l postgres -s /bin/sh -c "/usr/bin/pg_ctl -D $PGDATA -p /usr/bin/postmaster -o '-p ${PGPORT}' start > /dev/null 2>&1" < /dev/null』
↓
『su -l postgres -s /bin/sh -c "/usr/bin/pg_ctl -D $PGDATA -p /usr/bin/postmaster -o '-p ${PGPORT} -i' start > /dev/null 2>&1" < /dev/null 』
APostgreSQLを再起動。
# /etc/rc.d/init.d/postgresql restart
Bセキュリティ設定変更。
/var/lib/pgsql/data の pg_hba.conf内
TYPE DATABASEのhostの設定のコメントアウトを外して、有効化
※ セキュリティの観点からは危険。本来は、権限を制御するべき。
7.JDBCドライバをCLASSPATHへの追加
/usr/share/pgsql/配下のJDBCドライバに、CLASSPATHを設定
※検索でいらした方への注意
当コーナーは、管理人の苦労により、一応作ってみたあくまで参考用設定方法であり、実はこのサイトはレビュー・紹介等を扱ったゲーム系サイトなので、二個以上戻ると、ゲームサイトへ出ます。
会社で就業中に調べている方は、くれぐれも二個以上戻らないように。
|