はじめに
CentOSの初期設定では、PostgreSQLはbaseリポジトリからインストールされるようになっている。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
$ yum list postgresql* 読み込んだプラグイン:fastestmirror Determining fastest mirrors * base: ftp.tsukuba.wide.ad.jp * extras: ftp.tsukuba.wide.ad.jp * updates: ftp.tsukuba.wide.ad.jp 利用可能なパッケージ postgresql.i686 8.4.20-5.el6_7 updates postgresql.x86_64 8.4.20-5.el6_7 updates postgresql-contrib.x86_64 8.4.20-5.el6_7 updates postgresql-devel.i686 8.4.20-5.el6_7 updates postgresql-devel.x86_64 8.4.20-5.el6_7 updates postgresql-docs.x86_64 8.4.20-5.el6_7 updates postgresql-jdbc.noarch 8.4.704-2.el6 base postgresql-libs.i686 8.4.20-5.el6_7 updates postgresql-libs.x86_64 8.4.20-5.el6_7 updates postgresql-odbc.x86_64 08.04.0200-1.el6 base postgresql-plperl.x86_64 8.4.20-5.el6_7 updates postgresql-plpython.x86_64 8.4.20-5.el6_7 updates postgresql-pltcl.x86_64 8.4.20-5.el6_7 updates postgresql-server.x86_64 8.4.20-5.el6_7 updates postgresql-test.x86_64 8.4.20-5.el6_7 updates |
PostgreSQLのyumリポジトリの追加
PostgreSQLは、公式の yum リポジトリを提供しているので、そのリポジトリを指定してインストールするように設定を変更する。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
$ sudo yum -y localinstall https://download.postgresql.org/pub/repos/yum/9.5/redhat/rhel-6-x86_64/pgdg-centos95-9.5-2.noarch.rpm 読み込んだプラグイン:fastestmirror ローカルパッケージ処理の設定をしています pgdg-centos95-9.5-2.noarch.rpm | 5.3 kB 00:00 /var/tmp/yum-root-kp_1VV/pgdg-centos95-9.5-2.noarch.rpm を調べています: pgdg-centos95-9.5-2.noarch /var/tmp/yum-root-kp_1VV/pgdg-centos95-9.5-2.noarch.rpm をインストール済みとして設定しています Loading mirror speeds from cached hostfile * base: ftp.tsukuba.wide.ad.jp * extras: ftp.tsukuba.wide.ad.jp * updates: ftp.tsukuba.wide.ad.jp 依存性の解決をしています --> トランザクションの確認を実行しています。 ---> Package pgdg-centos95.noarch 0:9.5-2 will be インストール --> 依存性解決を終了しました。 依存性を解決しました =================================================================================================================================================================== パッケージ アーキテクチャ バージョン リポジトリー 容量 =================================================================================================================================================================== インストールしています: pgdg-centos95 noarch 9.5-2 /pgdg-centos95-9.5-2.noarch 2.2 k トランザクションの要約 =================================================================================================================================================================== インストール 1 パッケージ 合計容量: 2.2 k インストール済み容量: 2.2 k パッケージをダウンロードしています: rpm_check_debug を実行しています トランザクションのテストを実行しています トランザクションのテストを成功しました トランザクションを実行しています インストールしています : pgdg-centos95-9.5-2.noarch 1/1 Verifying : pgdg-centos95-9.5-2.noarch 1/1 インストール: pgdg-centos95.noarch 0:9.5-2 完了しました! |
利用できるPostgreSQLの確認
これでyumからPostgreSQL9.5が参照できるようになる。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
$ yum list postgresql* 読み込んだプラグイン:fastestmirror Loading mirror speeds from cached hostfile * base: ftp.tsukuba.wide.ad.jp * extras: ftp.tsukuba.wide.ad.jp * updates: ftp.tsukuba.wide.ad.jp pgdg95 | 3.7 kB 00:00 pgdg95/primary_db | 127 kB 00:00 利用可能なパッケージ postgresql.i686 8.4.20-5.el6_7 updates postgresql.x86_64 8.4.20-5.el6_7 updates postgresql-contrib.x86_64 8.4.20-5.el6_7 updates postgresql-devel.i686 8.4.20-5.el6_7 updates postgresql-devel.x86_64 8.4.20-5.el6_7 updates postgresql-docs.x86_64 8.4.20-5.el6_7 updates postgresql-jdbc.noarch 9.4.1208-1.rhel6 pgdg95 postgresql-jdbc-javadoc.noarch 9.4.1208-1.rhel6 pgdg95 postgresql-libs.i686 8.4.20-5.el6_7 updates postgresql-libs.x86_64 8.4.20-5.el6_7 updates postgresql-odbc.x86_64 08.04.0200-1.el6 base postgresql-plperl.x86_64 8.4.20-5.el6_7 updates postgresql-plpython.x86_64 8.4.20-5.el6_7 updates postgresql-pltcl.x86_64 8.4.20-5.el6_7 updates postgresql-server.x86_64 8.4.20-5.el6_7 updates postgresql-test.x86_64 8.4.20-5.el6_7 updates postgresql94-jdbc.noarch 9.4.1207-1.rhel6 pgdg95 postgresql94-jdbc-javadoc.noarch 9.4.1207-1.rhel6 pgdg95 postgresql95.x86_64 9.5.2-1PGDG.rhel6 pgdg95 postgresql95-contrib.x86_64 9.5.2-1PGDG.rhel6 pgdg95 postgresql95-debuginfo.x86_64 9.5.2-1PGDG.rhel6 pgdg95 postgresql95-devel.x86_64 9.5.2-1PGDG.rhel6 pgdg95 postgresql95-docs.x86_64 9.5.2-1PGDG.rhel6 pgdg95 postgresql95-libs.x86_64 9.5.2-1PGDG.rhel6 pgdg95 postgresql95-odbc.x86_64 09.05.0100-1PGDG.rhel6 pgdg95 postgresql95-odbc-debuginfo.x86_64 09.03.0400-1PGDG.rhel6 pgdg95 postgresql95-plperl.x86_64 9.5.2-1PGDG.rhel6 pgdg95 postgresql95-plpython.x86_64 9.5.2-1PGDG.rhel6 pgdg95 postgresql95-pltcl.x86_64 9.5.2-1PGDG.rhel6 pgdg95 postgresql95-python.x86_64 4.2-1PGDG.rhel6 pgdg95 postgresql95-python-debuginfo.x86_64 4.2-1PGDG.rhel6 pgdg95 postgresql95-server.x86_64 9.5.2-1PGDG.rhel6 pgdg95 postgresql95-tcl.x86_64 2.0.0-1.rhel6 pgdg95 postgresql95-tcl-debuginfo.x86_64 2.0.0-1.rhel6 pgdg95 postgresql95-test.x86_64 9.5.2-1PGDG.rhel6 pgdg95 |
PostgreSQL9.5のインストール
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
$ sudo yum install postgresql95-server 読み込んだプラグイン:fastestmirror インストール処理の設定をしています Loading mirror speeds from cached hostfile * base: ftp.tsukuba.wide.ad.jp * extras: ftp.tsukuba.wide.ad.jp * updates: ftp.tsukuba.wide.ad.jp 依存性の解決をしています --> トランザクションの確認を実行しています。 ---> Package postgresql95-server.x86_64 0:9.5.2-1PGDG.rhel6 will be インストール --> 依存性の処理をしています: postgresql95-libs(x86-64) = 9.5.2-1PGDG.rhel6 のパッケージ: postgresql95-server-9.5.2-1PGDG.rhel6.x86_64 --> 依存性の処理をしています: postgresql95(x86-64) = 9.5.2-1PGDG.rhel6 のパッケージ: postgresql95-server-9.5.2-1PGDG.rhel6.x86_64 --> 依存性の処理をしています: postgresql95 = 9.5.2-1PGDG.rhel6 のパッケージ: postgresql95-server-9.5.2-1PGDG.rhel6.x86_64 --> 依存性の処理をしています: libpq.so.5()(64bit) のパッケージ: postgresql95-server-9.5.2-1PGDG.rhel6.x86_64 --> トランザクションの確認を実行しています。 ---> Package postgresql95.x86_64 0:9.5.2-1PGDG.rhel6 will be インストール ---> Package postgresql95-libs.x86_64 0:9.5.2-1PGDG.rhel6 will be インストール --> 依存性解決を終了しました。 依存性を解決しました =================================================================================================================================================================== パッケージ アーキテクチャ バージョン リポジトリー 容量 =================================================================================================================================================================== インストールしています: postgresql95-server x86_64 9.5.2-1PGDG.rhel6 pgdg95 4.5 M 依存性関連でのインストールをします。: postgresql95 x86_64 9.5.2-1PGDG.rhel6 pgdg95 1.3 M postgresql95-libs x86_64 9.5.2-1PGDG.rhel6 pgdg95 205 k トランザクションの要約 =================================================================================================================================================================== インストール 3 パッケージ 総ダウンロード容量: 6.0 M インストール済み容量: 24 M これでいいですか? [y/N]y パッケージをダウンロードしています: (1/3): postgresql95-9.5.2-1PGDG.rhel6.x86_64.rpm | 1.3 MB 00:03 (2/3): postgresql95-libs-9.5.2-1PGDG.rhel6.x86_64.rpm | 205 kB 00:00 (3/3): postgresql95-server-9.5.2-1PGDG.rhel6.x86_64.rpm | 4.5 MB 00:06 ------------------------------------------------------------------------------------------------------------------------------------------------------------------- 合計 421 kB/s | 6.0 MB 00:14 rpm_check_debug を実行しています トランザクションのテストを実行しています トランザクションのテストを成功しました トランザクションを実行しています インストールしています : postgresql95-libs-9.5.2-1PGDG.rhel6.x86_64 1/3 インストールしています : postgresql95-9.5.2-1PGDG.rhel6.x86_64 2/3 インストールしています : postgresql95-server-9.5.2-1PGDG.rhel6.x86_64 3/3 Verifying : postgresql95-server-9.5.2-1PGDG.rhel6.x86_64 1/3 Verifying : postgresql95-9.5.2-1PGDG.rhel6.x86_64 2/3 Verifying : postgresql95-libs-9.5.2-1PGDG.rhel6.x86_64 3/3 インストール: postgresql95-server.x86_64 0:9.5.2-1PGDG.rhel6 依存性関連をインストールしました: postgresql95.x86_64 0:9.5.2-1PGDG.rhel6 postgresql95-libs.x86_64 0:9.5.2-1PGDG.rhel6 完了しました! |
インストールされたPostgreSQLの確認
1 2 3 4 5 |
$ yum list installed | grep pos postfix.x86_64 2:2.6.6-6.el6_7.1 @updates postgresql95.x86_64 9.5.2-1PGDG.rhel6 @pgdg95 postgresql95-libs.x86_64 9.5.2-1PGDG.rhel6 @pgdg95 postgresql95-server.x86_64 9.5.2-1PGDG.rhel6 @pgdg95 |
データベースの初期化
1 2 |
$ sudo service postgresql-9.5 initdb Initializing database: [ OK ] |
PostgreSQLの起動
1 2 |
$ sudo service postgresql-9.5 start Starting postgresql-9.5 service: [ OK ] |
PostgreSQLの初期起動を設定
1 2 3 4 |
$ chkconfig --list -略- postgresql-9.5 0:off 1:off 2:off 3:off 4:off 5:off 6:off -略- |
1 |
$ sudo chkconfig postgresql-9.5 on |
1 2 |
$ chkconfig --list postgresql-9.5 postgresql-9.5 0:off 1:off 2:on 3:on 4:on 5:on 6:off |
postgresユーザに変更して操作を行う
PostgreSQLは、OSユーザとして管理権限を持っている
1 2 |
$ sudo su - postgres -bash-4.1$ |
作成されているデータベースの確認
1 2 3 4 5 6 7 8 9 10 |
-bash-4.1$ psql -l List of databases Name | Owner | Encoding | Collate | Ctype | Access privileges -----------+----------+----------+-------------+-------------+----------------------- postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | template0 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres + | | | | | postgres=CTc/postgres template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres + | | | | | postgres=CTc/postgres (3 rows) |
以上、PostgreSQLのインストールから、データベースの確認が出来るまでの手順を示した。
