PostgreSQL データベースソフトウェアの詳細は、Postgres のマニュアルを参照してください。
PostgreSQL ソフトウェアのインストール後、データベースサーバーを起動できます。
PostgreSQL データベースソフトウェアをダウンロードし、コンパイルし、インストールします。データベースプロセスの所有者になるユーザーを作成します。通常、このユーザーは postgres です。環境に、PostgreSQL bin ディレクトリと必要な LD_LIBRARY_PATH 設定を追加します。
postgres ユーザーのホームディレクトリを作成します。
この例では、ホームディレクトリは /space/postgres/data になります。
% mkdir -p /space/postgres/data % useradd -d /space/postgres postgres % chown postgres /space/postgres/data % su - postgres |
PostgreSQL のマニュアルの説明に従って、データベースの設定を続行します。
> initdb -D /space/postgres/data creating directory /space/postgres/data... ok creating directory /space/postgres/data/base... ok creating directory /space/postgres/data/global... ok creating directory /space/postgres/data/pg_xlog... ok creating directory /space/postgres/data/pg_clog... ok creating template1 database in /space/postgres/data/base/1... ok creating configuration files... ok initializing pg_shadow... ok enabling unlimited row size for system tables... ok initializing pg_depend... ok creating system views... ok loading pg_description... ok creating conversions... ok setting privileges on built-in objects... ok vacuuming database template1... ok copying template1 to template0... ok Success. You can now start the database server using: postmaster -D /space/postgres/data or pg_ctl -D /space/postgres/data -l logfile start |
pg_hba.conf ファイルに、次のような変更を加えます。
その結果、データベースのスーパーユーザー postgres に、パスワード不要の無制限のアクセス権が付与されます。そして、その他のデータベースユーザーには、md5 暗号パスワードの使用が義務付けられます。末尾の 0 を除く nnn.nnn.nnn の部分は、実際のサブネットアドレスで置き換えます。また、ホスト IP アドレスに同様の行を追加して、ホスト単位でアクセス規則を追加することもできます。
# TYPE DATABASE USER IP-ADDRESS IP-MASK METHOD local all postgres trust local all all md5 # IPv4-style local connections: #host all all nnn.nnn.nnn.0 255.255.255.0 md5
postgresql.conf ファイルに次の変更を加えることにより、ほかのホストからの TCP/IP アクセスを有効にします。
shared_buffers の値が max_connections の値の 2 倍以上であることを確認します。
tcpip_socket = true max_connections = 40 (increase if necessary)
データベースを起動します。
この例の -i は TCP/IP 通信、-S はサイレントモードを有効にします。
> postmaster -S -i |
インストールを検証します。
postgres ユーザーになり、次のコマンドを実行します。
% su - postgres > createuser -P test_user Enter password for new user: Enter it again: 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 > createdb -O test_user -E UNICODE test CREATE DATABASE |
データベースのスーパーユーザーになり、コマンドを実行します。
> psql test
Welcome to psql 7.3, 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
|
test=# create table test (x int, y text);
CREATE TABLE
test=# insert into test values (1, 'one');
INSERT 16982 1
test=# insert into test values (2, 'two');
INSERT 16983 1
test=# select * from test;
x | y
---+------
1 | one
2 | two
(2 rows)
test=# \q
> psql -U test_user test
Password:
Welcome to psql 7.4.1, 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
test=>
|
データベースのテストが正常に完了したら、次のタスク、「PostgreSQL データベースを設定する方法」に進みます。
データベースのスーパーユーザー、たとえば postgres としてログインします。
# su - postgres |
> createuser -P arco_write Enter password for new user: Enter it again: 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 |
アカウンティングおよびレポート用のデータベースを作成します。
> createdb -O arco_write arco CREATE DATABASE |
データベースを読み取るためのデータベースユーザーを作成します。
arco_read ユーザーを使用しない場合、次の手順で使用する特権スクリプトの内容を修正する必要があります。
> createuser -P arco_read Enter password for new user: Enter it again: Shall the new user be allowed to create databases? (y/n) n Shall the new user be allowed to create more new users? (y/n) n CREATE USER |