| トップ | Solaris | FreeBSD | Gentoo | CentOS | Fedora | Windows | Tips | 自宅サーバの動作確認 | サイト内検索(Namazu) | サイト内検索(HE) |
「PostgreSQL」だけならpostgresql-serverのインストールのみで構いません。
自分の場合、PHPとの連携も行いたかったので、php-pgsqlもインストールしました。
[root@Fedora ~]# yum -y install postgresql-server php-pgsql <= 「PostgreSQL」関連のインストール [root@Fedora ~]# yum clean packages <= ダウンロードしたパッケージの削除 |
文字コードの設定
「PostgreSQL」の文字コードをUNICODEで利用し、文字列カラムに対して並べ替え(ORDER BY)を使う場合、 「ロケールなし」の初期化を行う必要があります。
[root@Fedora ~]# su - postgres <= 「PostgreSQL」の管理者に変更 -bash-3.1$ rm -rf /var/lib/pgsql/data -bash-3.1$ initdb --encoding=UNICODE --no-locale -D /var/lib/pgsql/data <= 初期化 |
[root@Fedora ~]# /etc/rc.d/init.d/postgresql start |
「PostgreSQL」の自動起動
Fedoraを起動する際に自動的に「PostgreSQL」を起動するようにします。
[root@Fedora ~]# chkconfig postgresql on |
「PostgreSQL」管理者の設定
Fedora上のパスワードの設定
[root@Fedora ~]# passwd postgres
Changing password for user postgres.
New UNIX password: <= パスワード
Retype new UNIX password: <= パスワード(確認)
「PostgreSQL」上のパスワードの設定
[root@Fedora ~]# su - postgres <= 「PostgreSQL」の管理者に変更
-bash-3.1$ psql template1 <= 「PostgreSQL」に接続
Welcome to psql 8.1.3, 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
template1=# alter user postgres with password '設定するパスワード'; <= 「PostgreSQL」上のpostgresユーザのパスワードを設定
ALTER ROLE
template1=# \q <= 終了
|
一般ユーザの設定
[root@Fedora ~]# su - postgres <= 「PostgreSQL」の管理者に変更 -bash-3.1$ createuser -dPE kaz <= kazを「PostgreSQL」に登録 Enter password for new role: <= パスワード Enter it again: <= パスワード(確認) Shall the new role be a superuser? (y/n) n Shall the new role be allowed to create more new roles? (y/n) n CREATE ROLE |
「postgresql.conf」ファイルの設定
[root@Fedora ~]# su - postgres <= 「PostgreSQL」の管理者に変更 -bash-3.1$ vi /var/lib/pgsql/data/postgresql.conf <= 設定ファイルの編集 #listen_addresses = 'localhost' # what IP address(es) to listen on; ↓ listen_addresses = 'localhost,192.168.0.1' # what IP address(es) to listen on; <= 外部からの接続を受け付ける listen_addresses = '*' # what IP address(es) to listen on; <= すべての接続を受け付ける場合 |
「pg_hba.conf」ファイルの設定
[root@Fedora ~]# su - postgres <= 「PostgreSQL」の管理者に変更 -bash-3.1$ vi /var/lib/pgsql/data/pg_hba.conf <= 設定ファイルの編集 最終行に追加 host all all 192.168.0.0 255.255.255.0 trust <= 内部からのアクセスは許可 host all all 0.0.0.0 0.0.0.0 md5 <= 上記以外のアクセスはパスワードにより許可 |
「PostgreSQL」を再起動し、設定を反映させます。
[root@Fedora ~]# /etc/rc.d/init.d/postgresql restart |