Cobalt Qube3J の設定に関するメモ(2002/01/15) 
 

PostgreSQLとは

商用データベースは多数ありますが、いくら安くなったとは言ってもとても個人では購入できる金額ではありません。カリフォルニア大学Berkeley校で開発された Postgres というリレーショナルデータベースシステムは、フリーでかつSunやDEC、Linuxなど多数のOSで動作します。日本語の扱いは、各Postgres のバージョンを参照してみてください。

日本PostgreSQL本家は、ここです。

Postgreのインストール

Cobalt Qube3Jには、既に「postgresql-7.0.2-2C1」パッケージが入っていますので、特に Postgres のパッケージをインストールする必要はありません。但し、postgres ユーザでデータベースの初期化を行わなければなりませんので、その手順を以下に記述します。

postgres ユーザで操作するのですが、既に postgres ユーザは作られています。ただし postgres ユーザは、root ユーザからでしかなることができません。

# su - postgres
[postgres pgsql]$ initdb --pgdata=/var/lib/pgsql/data

initdb: You must identify where the the data for this database
system will reside. Do this with either a --pgdata invocation
option or a PGDATA environment variable.

[postgres pgsql]$ initdb --pgdata=/var/lib/pgsql/data
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 /var/lib/pgsql/data
Creating database system directory /var/lib/pgsql/data/base
Creating database XLOG directory /var/lib/pgsql/data/pg_xlog
Creating template database in /var/lib/pgsql/data/base/template1
Creating global relations in /var/lib/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/bin/postmaster -D /var/lib/pgsql/data
or
  /usr/bin/pg_ctl -D /var/lib/pgsql/data start

 

利用者情報の登録

一般ユーザが Postgres のアクセスツールである psql をそのまま使おうとすると以下のエラーメッセージが表示されます。

[hoge hoge]$ psql hogedb
psql: FATAL 1: SetUserId: user 'hoge' is not in 'pg_shadow'

Postgres の利用者ユーザとして hoge ユーザを登録します。

[postgres pgsql]$ createuser hoge
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

ついでに hoge ユーザをデータベースアクセスできるように登録します。

[postgres pgsql]$ psql hogedb
hogedb=# grant all on hogedb.* to hoge
hogedb=# \q

hoge ユーザを登録後、再度 psql を実行します。

[hoge hoge]$ psql hogedb
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

hogedb=>

データベースを操作する

簡単ではありますが、テーブルを作成しデータを挿入し、それを検索してみる SQL を実行してみます。

hogedb=> create table t2 (code integer, name text);
CREATE
hogedb=> insert into t2(code,name) values(111,'hoge');
INSERT 19018 1
hogedb=> select * from t2;
 code | name
------+------
 111  | hoge
(1 row)

リンク

Cobalt + PostgreSQL

      Cobalt Qube に PostgreSQL を導入する方法が記載されています。

      他にも有益な情報が書かれており勉強になります。

PostgreSQL アドミニストレータズガイド

      PostgreSQL を導入する方法が書かれており、導入後の設定も詳しく書かれています。

PostgreSQLで作るLunixデータベース(1,2,3)

      ここは、勉強になりますぅぅ(きっと)。

←topへ