0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

PostgreSQL 10.0 インストール手順

Posted at

検証環境として作成した手順
今回は OracleLinux6 + PostgreSQL10.0 をインストール

PostgreSQL のソースコード入手
https://www.postgresql.org/ftp/source/

出展:マニュアル
https://www.postgresql.org/docs/10/index.html

postgres用OSユーザー作成

# useradd postgres
# passwd postgres
ユーザー postgres のパスワードを変更。

インストールディレクトリ作成

# mkdir /usr/local/pgsql

ソースファイルを/usr/local/srcへ保存し、解凍しておく

# tar -xvf  postgresql-10.0.tar.bz2
# chown -R postgres:postgres postgresql-10.0
# ls -la
合計 19192
drwxr-xr-x.  3 root     root         4096 11月  7 15:01 2019 .
drwxr-xr-x. 13 root     root         4096 11月  7 14:54 2019 ..
drwxrwxrwx   6 postgres postgres     4096 10月  3 06:15 2017 postgresql-10.0
-rw-r--r--   1 root     root     19639147 11月  7 14:40 2019 postgresql-10.0.tar.bz2

必要パッケージのインストール

# yum -y install readline readline readline-devel
# yum -y install gcc
# yum -y install flex
# yum install zlib-devel
# yum install perl

makeコマンド確認

# make --version
GNU Make 3.81

コンパイル

$ cd ./postgresql-10.0
$ ls
COPYRIGHT       HISTORY  Makefile  aclocal.m4  configure     contrib  src
GNUmakefile.in  INSTALL  README    config      configure.in  doc
$ ./configre
$ make

インストール前のcheck コマンド

$ make check

インストール
sudoを有効にする

#visudo にて以下行を追加する。
postgres   ALL=(ALL)       ALL

$ sudo make install

■環境変数設定

$ vi ~/.bashrc
# .bashrc

# Source global definitions
if [ -f /etc/bashrc ]; then
        . /etc/bashrc
fi

# Uncomment the following line if you don't like systemctl's auto-paging feature:
# export SYSTEMD_PAGER=

# User specific aliases and functions
export PATH="$PATH":/usr/local/pgsql/bin
export POSTGRES_HOME=/usr/local/pgsql
export PGLIB=$POSTGRES_HOME/lib
export PGDATA=$POSTGRES_HOME/data
export MANPATH="$MANPATH":$POSTGRES_HOME/man
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH":"$PGLIB"

/usr/local/pgsql の所有者を変更する

$ sudo chown postgres:postgres /usr/local/pgsql

DB初期化

$ initdb

postgreSQLサーバーの起動

$ postgres -D /usr/local/pgsql/data/
2019-11-07 16:33:52.702 JST [6119] LOG:  listening on IPv6 address "::1", port 5432
2019-11-07 16:33:52.702 JST [6119] LOG:  listening on IPv4 address "127.0.0.1", port 5432
2019-11-07 16:33:52.752 JST [6119] LOG:  listening on Unix socket "/tmp/.s.PGSQL.5432"
2019-11-07 16:33:52.828 JST [6120] LOG:  database system was shut down at 2019-11-07 16:26:45 JST
2019-11-07 16:33:52.861 JST [6119] LOG:  database system is ready to accept connections
^C2019-11-07 16:34:02.694 JST [6119] LOG:  received fast shutdown request
2019-11-07 16:34:02.827 JST [6119] LOG:  aborting any active transactions
2019-11-07 16:34:02.827 JST [6119] LOG:  worker process: logical replication launcher (PID 6126) exited with exit code 1
2019-11-07 16:34:02.827 JST [6121] LOG:  shutting down
2019-11-07 16:34:03.273 JST [6119] LOG:  database system is shut down

起動スクリプトの作成

# install -o root -g root -m 755 /usr/local/src/postgresql-10.0/contrib/start-scripts/linux /etc/rc.d/init.d/pgsql
# chkconfig --add pgsql
# /etc/rc.d/init.d/pgsql start
Starting PostgreSQL: ok

ユーザーとDBの作成

$ createuser posuser
$ createdb -O posuser testdb
$ psql -l
                                  List of databases
   Name    |  Owner   | Encoding |   Collate   |    Ctype    |   Access privileges
-----------+----------+----------+-------------+-------------+-----------------------
 postgres  | postgres | UTF8     | ja_JP.UTF-8 | ja_JP.UTF-8 |
 template0 | postgres | UTF8     | ja_JP.UTF-8 | ja_JP.UTF-8 | =c/postgres          +
           |          |          |             |             | postgres=CTc/postgres
 template1 | postgres | UTF8     | ja_JP.UTF-8 | ja_JP.UTF-8 | =c/postgres          +
           |          |          |             |             | postgres=CTc/postgres
 testdb    | posuser  | UTF8     | ja_JP.UTF-8 | ja_JP.UTF-8 |

リモート接続設定

$ vi /usr/local/pgsql/data/pg_hba.conf
追記
host    all             all             0.0.0.0/0           md5

$ vi /usr/local/pgsql/data/postgresql.conf
追記
listen_addresses = '*'

インストール完了

$ psql
psql (10.0)
Type "help" for help.

postgres=# select version();
                                                   version

---------------------------------------------------------------------------------------------
----------------
 PostgreSQL 10.0 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-
23.0.1), 64-bit
(1 row)

以上。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?