まず,PostgreSQL を起動するところから始めます.話が前後しますが,Linux (Fedora Core 6) を使用して開発を進めます.rpm や yum などを使用して,postgresql と postgresql-server がインストールされていることを確認してください.
$ rpm -q postgresql
postgresql-8.1.8-1.fc6
$ rpm -q postgresql-server
postgresql-server-8.1.8-1.fc6と実行してそれぞれが表示されればインストールされています.もしインストールされていない場合は,yum コマンドを使用して postgresql-server をインストールすれば,postgresql などの関連するパッケージも同時にインストールされます.スーパーユーザー(root)で
# yum -y install postgresql-serverと実行すればインストールされるはずです.
インストールしただけではまだ PostgreSQL は使用できません.システムの初期化時にサーバーが立ち上がるように設定します.スーパーユーザ(root)にて.
# chkconfig postgresql on
# chkconfig --list postgresql
postgresql 0:off 1:off 2:on 3:on 4:on 5:on 6:off
# (cd /; env - /etc/rc.d/init.d/postgresql start)
データベースを初期化中: [ OK ]
postgresql サービスを開始中: [ OK ]これで PostgreSQL が使用可能になりました.ちなみに "cd /" とするのは,プログラムから作業ディレクトリ(カレントディレクトリ)を切り離すためで,"env - " と付けるのは,ユーザの環境変数の設定が影響を与えないようにするためです.最近のサーバープログラム(デーモン)はよくできていますので,これらの心配は必要ないかもしれません.歴史的に UNIX のデーモンにはカレントディレクトリを掴んだままであったり,起動時の環境変数が動作に影響するものがありました.それを避けるための方策です.さらに余談ですが,"env" コマンドは引数に "-" を付けるとすべての環境変数を無効にします.逆に "env hogehoge=gerogero command" とすると,指定した環境変数 (この場合は "hogehoge") を export した状態で実行してくれます.
次に,PostgreSQL の実行環境の設定を確認します.私の環境では PostgreSQL の設定ファイルは "/var/lib/pgsql/data" にあります.このなかで,pg_hba.conf ファイルを編集します.ユーザの確認に IDENT を使用しないようにするためです.PostgreSQL を良く知っている方は,それなりに設定してください.とりあえず,どのユーザでも使用できるように設定します.
*** pg_hba.conf.org 2007-03-19 17:33:48.000000000 +0900
--- pg_hba.conf 2007-03-19 17:33:48.000000000 +0900
***************
*** 64,70 ****
# TYPE DATABASE USER CIDR-ADDRESS METHOD
# "local" is for Unix domain socket connections only
! local all all ident sameuser
# IPv4 local connections:
host all all 127.0.0.1/32 ident sameuser
# IPv6 local connections:
--- 64,71 ----
# TYPE DATABASE USER CIDR-ADDRESS METHOD
# "local" is for Unix domain socket connections only
! #local all all ident sameuser
! local all all trust
# IPv4 local connections:
host all all 127.0.0.1/32 ident sameuser
# IPv6 local connections:ここでは,ローカルユーザはすべて信用するように設定しました.この設定ファイルを変更した後,PostgreSQL を再起動しておきます.
次に,データベースにアクセスするためのユーザを作成します.PostgreSQL にアクセスするためのユーザを作成するには, "postgres" ユーザになる必要があります.
$ sudo su - postgres
-bash-3.1$ createuser -SdRW ssbm
Password: <= ここでパスワードを入力します.今回は "ssbm" を入力しました.
CREATE ROLE
-bash-3.1$ 続けてデータベースを作成しておきます.
-bash-3.1$ psql
Welcome to psql 8.1.8, 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
postgres=# CREATE DATABASE ssbmdb OWNER ssbm;
CREATE DATABASE
postgres=# \q
-bash-3.1$ exit
logout
$
この後,開発用のユーザに戻って,データベースのテーブルを作成します.
createPostgreSQLTables.sql:
CREATE TABLE users (
user_id SERIAL,
user_email TEXT NOT NULL,
user_password TEXT,
user_name TEXT,
user_surname TEXT,
PRIMARY KEY(user_id),
UNIQUE (user_email)
);
CREATE TABLE roles (
role_id SERIAL,
role_name TEXT NOT NULL,
role_refcount INTEGER DEFAULT 1,
PRIMARY KEY(role_id),
UNIQUE (role_name)
);
CREATE TABLE bookmarks (
bookmark_id SERIAL,
bookmark_uri TEXT NOT NULL,
bookmark_title TEXT NOT NULL,
bookmark_refcount INTEGER DEFAULT 1,
PRIMARY KEY(bookmark_id),
UNIQUE (bookmark_uri)
);
CREATE TABLE tags (
tag_id SERIAL,
tag_name TEXT NOT NULL,
tag_refcount INTEGER DEFAULT 1,
PRIMARY KEY(tag_id),
UNIQUE (tag_name)
);
CREATE TABLE user_roles (
user_role_id SERIAL,
user_id INTEGER,
role_id INTEGER,
PRIMARY KEY(user_role_id, user_id, role_id),
FOREIGN KEY(user_id) REFERENCES users(user_id),
FOREIGN KEY(role_id) REFERENCES roles(role_id)
);
CREATE TABLE user_bookmarks (
user_bookmark_id SERIAL,
user_id INTEGER,
bookmark_id INTEGER,
user_bookmark_ts TIMESTAMP WITH TIME ZONE DEFAULT now(),
user_bookmark_comment TEXT,
PRIMARY KEY(user_bookmark_id),
FOREIGN KEY(user_id) REFERENCES users(user_id),
FOREIGN KEY(bookmark_id) REFERENCES bookmarks(bookmark_id)
);
CREATE TABLE user_bookmark_tags (
user_bookmark_tag_id SERIAL,
user_bookmark_id INTEGER,
tag_id INTEGER,
PRIMARY KEY(user_bookmark_tag_id, user_bookmark_id, tag_id),
FOREIGN KEY(user_bookmark_id)
REFERENCES user_bookmarks(user_bookmark_id),
FOREIGN KEY(tag_id) REFERENCES tags(tag_id)
);
CREATE TABLE user_bookmark_roles (
user_bookmark_role_id SERIAL,
user_bookmark_id INTEGER,
role_id INTEGER,
PRIMARY KEY(user_bookmark_role_id, user_bookmark_id, role_id),
FOREIGN KEY(user_bookmark_id)
REFERENCES user_bookmarks(user_bookmark_id),
FOREIGN KEY(role_id) REFERENCES roles(role_id)
);
CREATE TABLE role_owners (
role_owner_id SERIAL,
role_id INTEGER,
user_id INTEGER,
PRIMARY KEY(role_owner_id, role_id, user_id),
FOREIGN KEY(role_id) REFERENCES roles(role_id),
FOREIGN KEY(user_id) REFERENCES users(user_id)
);
CREATE TABLE user_profiles (
user_profile_id SERIAL,
user_id INTEGER,
user_profile_publish INTEGER DEFAULT 0,
user_profile_nickname TEXT,
user_profile_nickname_publish INTEGER DEFAULT 0,
user_profile_surname TEXT,
user_profile_name TEXT,
user_profile_name_publish INTEGER DEFAULT 0,
user_profile_birthday DATE,
user_profile_birthday_publish INTEGER DEFAULT 0,
user_profile_age_publish INTEGER DEFAULT 0,
user_profile_email TEXT,
user_profile_email_publish INTEGER DEFAULT 0,
user_profile_introduce TEXT,
user_profile_introduce_publish INTEGER DEFAULT 0,
user_profile_updatetime
TIMESTAMP WITH TIME ZONE DEFAULT now(),
PRIMARY KEY(user_profile_id, user_id),
FOREIGN KEY(user_id) REFERENCES users(user_id)
);
CREATE TABLE informations (
information_id SERIAL,
information_title TEXT,
information_content TEXT,
information_date DATE,
information_ts TIMESTAMP WITH TIME ZONE DEFAULT now(),
information_publish INTEGER DEFAULT 0,
PRIMARY KEY(information_id)
);
CREATE TABLE sideinfos (
information_id SERIAL,
information_title TEXT,
information_content TEXT,
information_date DATE,
information_ts TIMESTAMP WITH TIME ZONE DEFAULT now(),
information_publish INTEGER DEFAULT 0,
PRIMARY KEY(information_id)
);
CREATE TABLE adminstatus (
adminstatus_id SERIAL,
adminstatus_info_start INTEGER,
adminstatus_info_num INTEGER,
adminstatus_sideinfo_start INTEGER,
adminstatus_sideinfo_num INTEGER,
PRIMARY KEY(adminstatus_id)
);
--
INSERT INTO users (user_email, user_password, user_name, user_surname)
VALUES (
'admin',
'd033e22ae348aeb5660fc2140aec35850c4da997',
'Administrator',
'Secure-SBM'
);
INSERT INTO roles (role_name) VALUES ( 'admin' );
INSERT INTO roles (role_name) VALUES ( 'public' );
INSERT INTO bookmarks (bookmark_uri, bookmark_title)
VALUES ( 'http://www.tyzoh.jp/', 'Tyzoh (タイゾウ)');
INSERT INTO bookmarks (bookmark_uri, bookmark_title)
VALUES (
'http://www.tyzoh.jp/modules/weblog/',
'Tyzohブログ Tyzoh (タイゾウ)'
);
INSERT INTO tags (tag_name, tag_refcount) VALUES ( 'tyzoh', 2 );
INSERT INTO user_roles (user_id, role_id) VALUES ( 1, 1 );
INSERT INTO user_roles (user_id, role_id) VALUES ( 1, 2 );
INSERT INTO user_bookmarks (
user_id, bookmark_id, user_bookmark_ts, user_bookmark_comment
) VALUES ( 1, 1, DEFAULT, '技術サイト' );
INSERT INTO user_bookmarks (
user_id, bookmark_id, user_bookmark_ts, user_bookmark_comment
) VALUES ( 1, 2, DEFAULT, '技術ブログ' );
INSERT INTO user_bookmark_tags (user_bookmark_id, tag_id) VALUES ( 1, 1 );
INSERT INTO user_bookmark_tags (user_bookmark_id, tag_id) VALUES ( 2, 1 );
INSERT INTO user_bookmark_roles (user_bookmark_id, role_id) VALUES ( 1, 2 );
INSERT INTO user_bookmark_roles (user_bookmark_id, role_id) VALUES ( 2, 2 );
INSERT INTO role_owners (role_id, user_id) VALUES ( 1, 1 );
INSERT INTO role_owners (role_id, user_id) VALUES ( 2, 1 );
INSERT INTO user_profiles (
user_id,
user_profile_publish,
user_profile_nickname_publish,
user_profile_name_publish,
user_profile_birthday,
user_profile_birthday_publish,
user_profile_age_publish,
user_profile_email_publish,
user_profile_introduce_publish
) VALUES ( 1, 0, 0, 0, 'now', 0, 0, 0, 0 );
INSERT INTO informations (
information_title,
information_content,
information_date,
information_publish
) VALUES (
'Secure-SBM リリース',
'Secure-SBM Version 0.1 alpha をリリースしました.<br />
バグ出しにご協力ください.',
'now',
1
);
INSERT INTO sideinfos (
information_title,
information_content,
information_date,
information_publish
) VALUES (
'管理者用のページ',
'管理者用のページは<a href="/admin">こちら</a>から',
'now',
1
);
INSERT INTO sideinfos (
information_title,
information_content,
information_date,
information_publish
) VALUES (
'Ver.0.1 alpha リリース',
'SecureSBM Version 0.1 alpha 版をリリースしました.
バグ出しにご協力ください.',
'now',
1
);
INSERT INTO adminstatus (
adminstatus_info_start,
adminstatus_info_num,
adminstatus_sideinfo_start,
adminstatus_sideinfo_num
) VALUES ( 1, 1, 1, 2 );
/*
This Program is distributed under version 1.0 of the Rinza Public
License Agreement, that is bundled with this package in the file
LICENSE, and is available through the website at the following URL:
http://www.tyzoh.jp/rinza/licenses/LICENSE-1.0.txt.
The Initial Developer of the Original Program is Nihon Unisys, Ltd.
The Original Program is copyrighted (C) 2006-2007 by Nihon Unisys, Ltd.
with all rights reserved.
There is NO WARRANTY OF ANY KIND by the Initial Developer of the
Original Program.
*/この sql を使用して,データベースを作成します.
$ psql -U ssbm ssbmdb < createPostgreSQLTables.sql
CREATE TABLE
...(省略)
NOTICE: CREATE TABLE will create implicit sequence
"bookmark_roles_bookmark_role_id_seq" for serial column
"bookmark_roles.bookmark_role_id"
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index
"bookmark_roles_pkey" for table "bookmark_roles"
CREATE TABLE
INSERT 0 1
...(省略)
INSERT 0 1
$
以下のような 2 行は無視してかまいません.
NOTICE: CREATE TABLE will create implicit sequence
"users_user_id_seq" for serial column "users.user_id"
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index
"users_pkey" for table "users"しかし,他のメッセージがないことは確認しておく必要があります.
作成したテーブルと,登録した内容に間違いがないかどうか,この時点で確認しておきます.
$ cat showPostgreSQLTables.sql
SELECT * FROM users;
SELECT * FROM roles;
SELECT * FROM bookmarks;
SELECT * FROM tags;
SELECT * FROM user_roles;
SELECT * FROM user_bookmarks;
SELECT * FROM user_bookmark_tags;
SELECT * FROM user_bookmark_roles;
SELECT * FROM role_owners;
SELECT * FROM user_profiles;
SELECT * FROM informations;
SELECT * FROM sideinfos;
SELECT * FROM adminstatus;
$ psql -U ssbm ssbmdb < showPostgreSQLTables.sql
user_id | user_email | user_password
| user_name | user_surname
---------+----------------------------+------------------------------------------+
---------------+--------------
1 | admin |
d033e22ae348aeb5660fc2140aec35850c4da997 | Administrator | Secure-SBM
(1 row)
...(省略)
$ タグ:Secure-SBM
いかちょー (2007-05-01 23:28) | コメント(0)| トラックバック(37)
トラックバックURL:
Soma online sales. - Buy soma online order soma and get cheap soma. (2011年5月23日 05:17)
Link domain purchase online soma a biz. Soma online next day. Online pharmacy... 続きを読む
Buy amoxicillin no prescription required. - Can i buy amoxicillin in canada. (2011年5月24日 06:16)
Buy amoxicillin no prescription required. Buy liquid amoxicillin. Can i buy a... 続きを読む
Online prescription fioricet. - Online prescription fioricet. (2011年5月31日 06:34)
Online pharmacy fioricet drug. Purchase fioricet online without prescription.... 続きを読む
Buy tramadol. - Buy tramadol. (2011年6月11日 05:44)
Where buy tramadol click here. Buy cheap tramadol mg tablets only in us onlin... 続きを読む
Vicodin no prescription. - Purchase vicodin. (2011年6月11日 07:45)
Vicodin. Vicodin drug information. 続きを読む
Hydrocodone and oxycodone. - Oxycodone vs hydrocodone. (2011年6月13日 06:18)
Oxycodone vs hydrocodone. Pharmacy no prescription hydrocodone alprozolam oxy... 続きを読む
Tylenol with codeine. - Tylenol w codeine 3. (2011年6月14日 06:17)
Tylenol with codeine side effects. Codeine pain tylenol 4. Tylenol with codeine. 続きを読む
Xanax forte. - Xanax forte. (2011年6月16日 06:17)
Xanax forte. 続きを読む
Buy norco 1000 no prescription. - Buy norco online. (2011年6月20日 07:01)
Buy norco 1000 no prescription. Buy norco. 続きを読む
Hydrocodone codeine. - Hydrocodone codeine. (2011年6月21日 06:28)
Hydrocodone codeine. 続きを読む
Free homemade porn videos. - Free homemade porn. (2011年10月24日 21:57)
Free homemade porn. 続きを読む
Big boobs alert. - Big boobs. (2011年10月25日 03:42)
Free galleries big boobs. Big boobs. Free big boobs. Lana's big boobs. Big bl... 続きを読む
Free gay sex. - Free gay sex. (2011年10月25日 15:06)
Free gay sex. 続きを読む
Free animal sex videos. - Free animal sex vidieos. (2011年10月26日 03:46)
Free animal sex. Free animal sex stories. Free animal sex videos. 続きを読む
Exclusive sex. - Exclusive sex. (2011年10月27日 04:06)
Exclusive sex. 続きを読む
Tit torture. - Ebony tit torture. (2011年10月27日 22:05)
Tit torture. Tit torture burning. Tit torture clamps. Free tit torture. 続きを読む
Silver daddies. - Silver daddies. (2011年10月28日 12:38)
Silver daddies. 続きを読む
Free blowjob pics. - Asian blowjob. (2011年10月29日 11:40)
Britney blowjob. Blowjob pics. Cow blowjob. Blowjob. Chloe sevigny blowjob. 続きを読む
Free adult movies. - Adult porn movies free. (2011年10月29日 23:02)
Adult xxx movies for free. Free adult movies. Free asian adult movies. 続きを読む
Vicodin abuse. - Vicodin. (2011年10月30日 11:47)
Buy vicodin online. Vicodin online. 続きを読む
Free gay male sex videos. - Gay sex videos. (2011年10月30日 23:35)
Free gay sex videos. Free hardcore gay sex videos. Gay sex videos. Free gay s... 続きを読む
Free femdom videos. - Free femdom videos. (2011年11月 1日 16:26)
Free femdom videos. Free femdom-videos.com 15. 続きを読む
Amateur porn. - Amateur college porn. (2011年11月 3日 14:09)
Free hardcore amateur gay porn pics. Free amateur-porn-clips. 続きを読む
Free xxx amateurs videos. - Free xxx amateurs videos. (2011年11月 4日 03:17)
Free xxx amateurs videos. 続きを読む
Free adult video. - Adult free video clip. (2011年11月 4日 14:09)
Free amateur adult sex video. Free adult video. Adult amateur free homemade s... 続きを読む
Hot free gay sex. - Free gay sex video clips. (2011年11月 5日 13:09)
Free gay sex movies. Free gay sex galleries. Sex male gay free. Free gay sex ... 続きを読む
Silverdaddies. - Silverdaddies. (2011年11月 7日 15:44)
Silverdaddies. 続きを読む
Health insurance. - Long term disability insurance. (2011年11月 8日 14:05)
Bike insurance. Medical insurance. Automobile insurance. Auto insurance. Holi... 続きを読む
Silver daddies. - Silver daddies. (2011年11月 9日 03:07)
Silver daddies. 続きを読む
Free scat xxx movies. - Free scat xxx movies. (2011年11月10日 03:19)
Free scat xxx movies. 続きを読む
Blowjob. - Blowjob. (2011年11月10日 23:48)
Blowjob. 続きを読む
No underwear. - Britney spears no underwear. (2011年11月11日 15:45)
Britney spears no underwear. Britney no photo spear underwear wearing. Britne... 続きを読む
Buy viagra online gay sex movies. - Gay viagra stories. (2011年11月15日 15:38)
Gay viagra stories. Gay viagra. Gay men viagra vs cialis. 続きを読む
Animal tubes. - Animal tubes. (2011年11月16日 15:34)
Animal tubes. 続きを読む
Free lesbian bdsm videos. - Free bdsm videos. (2011年11月17日 04:42)
Free bdsm videos. Bdsm free videos. 続きを読む
Naked women. - Naked women. (2011年11月20日 04:46)
Naked women. 続きを読む
Silverdaddies. - Silverdaddies. (2011年11月21日 16:19)
Silverdaddies. 続きを読む
月別アーカイブ
Copyright (C) 2004-2011 Nihon Unisys, Ltd. All Rights Reserved.
Powered by Movable Type Open Source