PostgreSQLの実験
Modified: 14 February 2002
RedHat Linux7.2 に同梱されているPostgrSQLを動作させて見ます。
PostgresSQLを起動する
initdb でデーターベースを初期化します。
$ initdb
This database system will be initialized with username "postgres".
This user will own all the data files and must also own the server process.
Fixing permissions on pre-existing data directory /usr/local/pgsql/data
Creating database XLOG directory /usr/local/pgsql/data/pg_xlog
Creating template database in /usr/local/pgsql/data/base/template1
Creating global relations in /usr/local/pgsql/data/base
Adding template1 database to pg_database
Creating view pg_user.
Creating view pg_rules.
Creating view pg_views.
Creating view pg_tables.
Creating view pg_indexes.
Loading pg_description.
Vacuuming database.
Success. You can now start the database server using:
/usr/local/pgsql/bin/postmaster -D /usr/local/pgsql/data
or
/usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data start
$これは失敗です。
initdb を再度実行し、データーベースを初期化します。
initdb を実行した後に出てくるメッセージどおり、以下のように実行すると、postgreSQLが起動します。
$ /usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data start
postmaster successfully started up.
DEBUG: Data Base System is starting up at Sat Jul 15 18:35:43 2000
DEBUG: Data Base System was shut down at Sat Jul 15 18:25:44 2000
DEBUG: Data Base System is in production state at Sat Jul 15 18:35:43 2000
$
PostgreSQLの自動起動
rc.local に以下の記述を加えます。
:
#
# PostgreSQL
#
su - postgres -c "/usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data start"
#
起動時には、データベースを管理するユーザで起動します。
ユーザを指定しないと、root でも起動には失敗します。(このへんはもっと研究する必要があります。)
PostgreSQLのテスト
PostgreSQLが正しく動作しているかどうかは、
$ cd /home/postgres/postgresql-7.0.2/src/test/regress
$ make all runtest > runtest.log
:
$
実行後、"runtest.log" を確認します。
cd input; make all; cd ..
make[1]: Entering directory `/home/postgres/postgresql-7.0.2
:
(((途中略)))
:
=============== Notes... =================
postmaster must already be running for the regression tests to succeed.
The time zone is set to PST8PDT for these tests by the client frontend.
Please report any apparent problems to ports@postgresql.org
See regress/README for more information.
=============== dropping old regression database... =================
DROP DATABASE
=============== creating new regression database... =================
CREATE DATABASE
=============== installing languages... =================
installing PL/pgSQL .. ok
=============== running regression queries... =================
boolean .. ok
char .. ok
name .. ok
varchar .. ok
text .. ok
int2 .. ok
int4 .. ok
int8 .. ok
oid .. ok
float4 .. ok
float8 .. ok
numeric .. ok
strings .. ok
numerology .. ok
point .. ok
lseg .. ok
box .. ok
path .. ok
polygon .. ok
circle .. ok
interval .. ok
timestamp .. ok
reltime .. ok
tinterval .. ok
inet .. ok
comments .. ok
oidjoins .. ok
type_sanity .. ok
opr_sanity .. ok
abstime .. ok
geometry .. ok
horology .. ok
create_function_1 .. ok
create_type .. ok
create_table .. ok
create_function_2 .. ok
copy .. ok
constraints .. ok
triggers .. ok
create_misc .. ok
create_aggregate .. ok
create_operator .. ok
create_index .. ok
create_view .. ok
sanity_check .. ok
errors .. ok
select .. ok
select_into .. ok
select_distinct .. ok
select_distinct_on .. ok
select_implicit .. ok
select_having .. ok
subselect .. ok
union .. ok
case .. ok
join .. ok
aggregates .. ok
transactions .. ok
random .. ok
portals .. ok
arrays .. ok
btree_index .. ok
hash_index .. ok
misc .. ok
select_views .. ok
alter_table .. ok
portals_p2 .. ok
rules .. ok
foreign_key .. ok
limit .. ok
plpgsql .. ok
temp .. ok
euc_jp .. ok
ACTUAL RESULTS OF REGRESSION TEST ARE NOW IN FILE regress.out
To run the optional big test(s) too, type 'make bigtest'
These big tests can take over an hour to complete
These actually are: numeric_big
全部、ok のようなので安心しました。必ずしもエラーが出たらだめということはないそうです。
ユーザの作成
$ createuser tomo
Shall the new user be allowed to create databases? (y/n) y
Shall the new user be allowed to create more new users? (y/n) n
CREATE USER
$
ユーザの削除
$ dropuser tomo
DROP USER
$
データベースの作成
$ createdb testdb
CREATE DATABASE
$
データベースの削除
$ dropdb testdb
DROP DATABASE
$
インタプリタを使ってみる
$ createdb testdb
CREATE DATABASE$ psql -l
List of databases
Database | Owner | Encoding
------------+----------+----------
regression | postgres | EUC_JP
template1 | postgres | EUC_JP
testdb | postgres | EUC_JP
(3 rows)psqlを起動して、登録して、その内容を表示してみる。
$ psql testdb
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
testdb=# create table addr (name text,address text);
CREATE
testdb=# insert into addr values('tomo','nara');
INSERT 277834 1
testdb=# insert into addr values('hiro','osaka');
INSERT 277835 1
testdb=# select * from addr;
name | address
------+---------
tomo | nara
hiro | osaka
(2 rows)
testdb=# \q
$