postgreSQLをインストールする手順

postgresSQLをCentOS 5.5(x86-64)へインストールする手順のメモ。

1.インストールされているか確認する。

これは、以下のコマンドを発行することで確認できます。

[sourcecode language="bash"]

psql --version

-bash: psql: command not found

[/sourcecode]

2.yumで取得できるバージョンを確認する。

[sourcecode language="bash"]

yum list | grep postgresql

postgresql-server.x86_64                   8.1.22-1.el5_5.1            updates

[/sourcecode]

3.yumで取得したいバージョンのpotgresSQLを取得するためprmファイルを取得する。

yumでインストールできるバージョンは結構古いようです。最新版を取得するため、rpmファイルをダウンロードしてインストールを行います。

  1. http://www.postgresql.org/download/linux#yumへアクセスする。
  2. CentOS, Fedora and RHEL Yum Repositoryよりrpmファイルをダウンロードする。
  3. ダウンロードしたrpmファイルをインストールする。また、インストールできたか確認する。

[sourcecode language="bash"]

rpm -ivh /tmp/pgdg-centos-9.0-2.noarch.rpm

警告: /tmp/pgdg-centos-9.0-2.noarch.rpm: ヘッダ V3 DSA signature: NOKEY, key ID 442df0f8 準備中...                ########################################### [100%] 1:pgdg-centos            ########################################### [100%]

  ls -l /etc/yum.repos.d/

合計 28 -rw-r--r-- 1 root root 2331  1月 21 21:31 CentOS-Base.repo -rw-r--r-- 1 root root  626  4月 26  2010 CentOS-Media.repo -rw-r--r-- 1 root root  739 11月 13 12:55 mirrors-rpmforge -rw-r--r-- 1 root root  717 11月 13 12:55 mirrors-rpmforge-extras -rw-r--r-- 1 root root  728 11月 13 12:55 mirrors-rpmforge-testing -rw-r--r-- 1 root root  428  3月  3  2010 pgdg-90-centos.repo -rw-r--r-- 1 root root 1113 11月 13 12:55 rpmforge.repo

[/sourcecode]

4.yumの設定ファイルを変更する。

先ほどインストールしたrpmファイルを使用するようにyumの設定ファイル?(/etc/yum.repos.d/CentOS-Base.repo)を変更します。変更箇所は以下の通りです。

[base]セクションと[update]セクションに

[sourcecode language="bash"]

exclude=postgresql*

[/sourcecode]

を追加します。

5.2と同様のコマンドを実行して取得できるpostgreSQLを確認します。

6.yumでインストールを行います。

[sourcecode language="bash"]

yum install postgresql-server

(省略)

Dependencies Resolved


Package                  Arch        Version                 Repository   Size

Installing: postgresql90-server      x86_64      9.0.2-2PGDG.rhel5       pgdg90      4.8 M Installing for dependencies: postgresql90             x86_64      9.0.2-2PGDG.rhel5       pgdg90      1.4 M postgresql90-libs        x86_64      9.0.2-2PGDG.rhel5       pgdg90      217 k

Transaction Summary

Install       3 Package(s) Upgrade       0 Package(s)

Total download size: 6.4 M

(省略)

Downloading Packages: (1/3): postgresql90-libs-9.0.2-2PGDG.rhel5.x86_64.rpm    | 217 kB     00:02 (2/3): postgresql90-9.0.2-2PGDG.rhel5.x86_64.rpm         | 1.4 MB     00:06

(3/3): postgresql90-server-9.0.2-2PGDG.rhel5.x86_64.rpm  | 4.8 MB     00:13

Total                                           244 kB/s | 6.4 MB     00:26 Running rpm_check_debug Running Transaction Test Finished Transaction Test Transaction Test Succeeded Running Transaction Installing     : postgresql90-libs                                        1/3 Installing     : postgresql90                                             2/3 Installing     : postgresql90-server                                      3/3

Installed: postgresql90-server.x86_64 0:9.0.2-2PGDG.rhel5

Dependency Installed: postgresql90.x86_64 0:9.0.2-2PGDG.rhel5 postgresql90-libs.x86_64 0:9.0.2-2PGDG.rhel5

Complete!

[/sourcecode]

7.以上でインストールは完了!

続いて設定です。

1.postgreSQLユーザの確認

postgreSQLが正常にインストールされている場合、postgresというユーザが作成されているので確認する。

[sourcecode language="bash"]

id postgres

uid=26(postgres) gid=26(postgres) 所属グループ=26(postgres) [/sourcecode]

また、バージョンコマンドでインストールされているバージョンを確認する。

[sourcecode language="bash"]

psql --version

psql (PostgreSQL) 9.0.2 コマンドライン編集機能のサポートが組み込まれています。 <h4>2.OS起動時にpostgreSQLも起動するように設定する。</h4>

chkconfig postgresql-9.0 on

chkconfig --list postgresql-9.0

postgresql-9.0  0:off   1:off   2:on    3:on    4:on    5:on    6:off

[/sourcecode]

3.postgreSQLのサービスを起動する。 次にpostgreSQLのサービスを起動します。

[sourcecode language="bash"]

service postgresql-9.0 start

/var/lib/pgsql/9.0/data is missing. Use "service postgresql initdb" to initialize the cluster first. [失敗]

[/sourcecode]

よくわからないのですが、サービスの起動に失敗したようです…。メッセージに記載のあるinitdbコマンドを実行してどうなるか確認します。

[sourcecode language="bash"]

service postgresql<span style="color: #ff0000;"><strong>-9.0</strong></span> initdb

データベースを初期化中:                                    [  OK  ]

[/sourcecode]

初期化は正常に終了した模様…。大丈夫でしょうかね。

気を取り直して、もう一度サービスの起動を行います。

[sourcecode language="bash"]

service postgresql-9.0 start

postgresql-9.0 サービスを開始中:                           [  OK  ]

[/sourcecode]

今回は無事にサービスが起動しました!

4.postgreSQLへログインする。

postgreSQLへログインするため、次のコマンドを実行します。

[sourcecode language="bash"]

su - postgres

-bash-3.2$

[/sourcecode]

これでログインまでが正常に行えました。とりあえずここまでにしましょう。