VagrantのCentOS7にPostgresql95を導入します

先日来、Vagrantを使ってアレコレしていて、Postgresqlの暗号化の環境を作ろうと、postgresql-9.5のインストールをしてみました。

環境:MacOS + Vagrant + CentOS7

ターゲット:Postgresql-9.5

目次

セットアップを開始します!

1)yumのレポジトリを取得します。

デフォルトではPostgresql-9.3だったんで、9.5の環境をいれます。

$ wget wget yum.postgresql.org/9.5/redhat/rhel-7-x86_64/pgdg-centos95-9.5-3.noarch.rpm
# rpm -ivh pgdg-centos95-9.5-3.noarch.rpm

2)インストールします

# yum install postgresql95-server postgresql95-devel postgresql95-contrib

=================================================
Package Arch Version Repository Size
=================================================
Installing:
postgresql95-contrib  x86_64  9.5.6-2PGDG.rhel7  pgdg95 530 k
postgresql95-devel   x86_64  9.5.6-2PGDG.rhel7  pgdg95 1.7 M
postgresql95-server  x86_64  9.5.6-2PGDG.rhel7  pgdg95 4.1 M
Installing for dependencies:
libxslt      x86_64  1.1.28-5.el7        base   242 k
postgresql95   x86_64  9.5.6-2PGDG.rhel7    pgdg95  1.3 M
postgresql95-libs x86_64  9.5.6-2PGDG.rhel7    pgdg95  219 k

Transaction Summary
=================================================
Install 3 Packages (+3 Dependent packages)

3)無事インストールできたんで一発スタートさせてみます!

# systemctl start postgresql-9.5
Job for postgresql-9.5.service failed. See ‘systemctl status postgresql-9.5.service’ and ‘journalctl -xn’ for details.

てなエラーが表示されます(^^;

# systemctl status postgresql-9.5.service
postgresql-9.5.service – PostgreSQL 9.5 database server
Loaded: loaded (/usr/lib/systemd/system/postgresql-9.5.service; disabled)
Active: failed (Result: exit-code) since Sat 2017-04-01 11:10:31 JST; 29s ago
Process: 4188 ExecStartPre=/usr/pgsql-9.5/bin/postgresql95-check-db-dir ${PGDATA} (code=exited, status=1/FAILURE)

Apr 01 11:10:31 centos-7.1-x86-64.shared systemd[1]: Starting PostgreSQL 9.5 database server…
Apr 01 11:10:31 centos-7.1-x86-64.shared postgresql95-check-db-dir[4188]: “/var/lib/pgsql/9.5/data/” is missing or empty.
Apr 01 11:10:31 centos-7.1-x86-64.shared postgresql95-check-db-dir[4188]: Use “/usr/pgsql-9.5/bin/postgresql95-setup initdb” to initialize the database cluster.
Apr 01 11:10:31 centos-7.1-x86-64.shared postgresql95-check-db-dir[4188]: See /usr/share/doc/postgresql95/README.rpm-dist for more information.
Apr 01 11:10:31 centos-7.1-x86-64.shared systemd[1]: postgresql-9.5.service: control process exited, code=exited status=1
Apr 01 11:10:31 centos-7.1-x86-64.shared systemd[1]: Failed to start PostgreSQL 9.5 database server.
Apr 01 11:10:31 centos-7.1-x86-64.shared systemd[1]: Unit postgresql-9.5.service entered failed state.

早い話がinitdbしろってことです(^^;

4)initdbします

# /usr/pgsql-9.5/bin/postgresql95-setup initdb
Initializing database … OK

5)Postgresqlをスタートします。

# systemctl start postgresql-9.5

これだけ(^^;

6)中身拝見!

# su – postgres
-bash-4.2$ psql
psql (9.5.6)
Type “help” for help.

postgres=# \d
No relations found.
postgres=# \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)

ロケールが”en_US”になってますねぇ。。

コレ取っちゃいましょう!

7)ロケールを削除する

initdbのパラメータで”–no-locale”なんてやってましたけど、「postgresql95-setup」の場合は環境変数にinitdbのパラメータを設定する必要があるそうです。

# /usr/pgsql-9.5/bin/postgresql95-setup help

Usage: /usr/pgsql-9.5/bin/postgresql95-setup {initdb|upgrade} [SERVICE_NAME]

Script is aimed to help sysadmin with basic database cluster administration.

The SERVICE_NAME is used for selection of proper unit configuration file; For
more info and howto/when use this script please look at the docu file
. The ‘postgresql’
string is used when no SERVICE_NAME is explicitly passed.

Available operation mode:
initdb Create a new PostgreSQL database cluster. This is usually the
first action you perform after PostgreSQL server installation.
upgrade Upgrade PostgreSQL database cluster to be usable with new
server. Use this if you upgraded your PostgreSQL server to
newer major version (currently from 9.4 to 9.5).

Environment:
PGSETUP_INITDB_OPTIONS Options carried by this variable are passed to
subsequent call of initdb binary (see man
initdb(1)). This variable is used also during
‘upgrade’ mode because the new cluster is actually
re-initialized from the old one.
PGSETUP_PGUPGRADE_OPTIONS Options in this variable are passed next to the
subsequent call of pg_upgrade. For more info
about possible options please look at man
pg_upgrade(1).
PGSETUP_DEBUG Set to ‘1’ if you want to see debugging output.

# export PGSETUP_INITDB_OPTIONS=”–encoding=UTF-8 –no-locale”
# /usr/pgsql-9.5/bin/postgresql95-setup initdb
Initializing database … OK

# su – postgres
Last login: Sat Apr 1 11:45:10 JST 2017 on pts/0
-bash-4.2$ psql
psql (9.5.6)
Type “help” for help.

postgres=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+----------+---------+-------+-----------------------
postgres | postgres | UTF8 | C | C |
template0 | postgres | UTF8 | C | C | =c/postgres +
 |  |  |  |  | postgres=CTc/postgres
template1 | postgres | UTF8 | C | C | =c/postgres +
 |  |  |  |  | postgres=CTc/postgres
(3 rows)

コレで取り敢えずは終了!

再起動してくださいね!

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です