Linux
PostgreSQL
oracle
Yum
postgres

How to install PostgreSQL 9.x on Oracle Linux 7.x

yum install repos

# yum install https://download.postgresql.org/pub/repos/yum/9.6/redhat/rhel-7-x86_64/pgdg-oraclelinux96-9.6-3.noarch.rpm
Loaded plugins: langpacks, ulninfo
pgdg-oraclelinux96-9.6-3.noarch.rpm                      | 4.8 kB     00:00     
Examining /var/tmp/yum-root-nMPTUf/pgdg-oraclelinux96-9.6-3.noarch.rpm: pgdg-oraclelinux96-9.6-3.noarch
Marking /var/tmp/yum-root-nMPTUf/pgdg-oraclelinux96-9.6-3.noarch.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package pgdg-oraclelinux96.noarch 0:9.6-3 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package              Arch     Version Repository                          Size
================================================================================
Installing:
 pgdg-oraclelinux96   noarch   9.6-3   /pgdg-oraclelinux96-9.6-3.noarch   2.7 k

Transaction Summary
================================================================================
Install  1 Package

Total size: 2.7 k
Installed size: 2.7 k
Is this ok [y/d/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : pgdg-oraclelinux96-9.6-3.noarch                              1/1 
  Verifying  : pgdg-oraclelinux96-9.6-3.noarch                              1/1 

Installed:
  pgdg-oraclelinux96.noarch 0:9.6-3                                             

Complete!

yum install

# yum install postgresql96-server postgresql96-contrib postgresql96-devel
Loaded plugins: langpacks, ulninfo
pgdg96                                                                     | 4.1 kB  00:00:00     
(1/2): pgdg96/7Server/x86_64/group_gz                                      |  249 B  00:00:00     
(2/2): pgdg96/7Server/x86_64/primary_db                                    | 164 kB  00:00:02     
Resolving Dependencies
--> Running transaction check
---> Package postgresql96-contrib.x86_64 0:9.6.5-1PGDG.rhel7 will be installed
--> Processing Dependency: postgresql96-libs(x86-64) = 9.6.5-1PGDG.rhel7 for package: postgresql96-contrib-9.6.5-1PGDG.rhel7.x86_64
--> Processing Dependency: postgresql96(x86-64) = 9.6.5-1PGDG.rhel7 for package: postgresql96-contrib-9.6.5-1PGDG.rhel7.x86_64
--> Processing Dependency: libpq.so.5()(64bit) for package: postgresql96-contrib-9.6.5-1PGDG.rhel7.x86_64
---> Package postgresql96-devel.x86_64 0:9.6.5-1PGDG.rhel7 will be installed
---> Package postgresql96-server.x86_64 0:9.6.5-1PGDG.rhel7 will be installed
--> Running transaction check
---> Package postgresql96.x86_64 0:9.6.5-1PGDG.rhel7 will be installed
---> Package postgresql96-libs.x86_64 0:9.6.5-1PGDG.rhel7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

==================================================================================================
 Package                       Arch            Version                      Repository       Size
==================================================================================================
Installing:
 postgresql96-contrib          x86_64          9.6.5-1PGDG.rhel7            pgdg96          565 k
 postgresql96-devel            x86_64          9.6.5-1PGDG.rhel7            pgdg96          1.8 M
 postgresql96-server           x86_64          9.6.5-1PGDG.rhel7            pgdg96          4.3 M
Installing for dependencies:
 postgresql96                  x86_64          9.6.5-1PGDG.rhel7            pgdg96          1.4 M
 postgresql96-libs             x86_64          9.6.5-1PGDG.rhel7            pgdg96          312 k

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

Total download size: 8.3 M
Installed size: 36 M
Is this ok [y/d/N]: y
Downloading packages:
(1/5): postgresql96-9.6.5-1PGDG.rhel7.x86_64.rpm                           | 1.4 MB  00:00:02     
(2/5): postgresql96-devel-9.6.5-1PGDG.rhel7.x86_64.rpm                     | 1.8 MB  00:00:00     
(3/5): postgresql96-libs-9.6.5-1PGDG.rhel7.x86_64.rpm                      | 312 kB  00:00:00     
(4/5): postgresql96-server-9.6.5-1PGDG.rhel7.x86_64.rpm                    | 4.3 MB  00:00:00     
(5/5): postgresql96-contrib-9.6.5-1PGDG.rhel7.x86_64.rpm                   | 565 kB  00:00:04     
--------------------------------------------------------------------------------------------------
Total                                                             2.0 MB/s | 8.3 MB  00:00:04     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : postgresql96-libs-9.6.5-1PGDG.rhel7.x86_64                                     1/5 
  Installing : postgresql96-9.6.5-1PGDG.rhel7.x86_64                                          2/5 
  Installing : postgresql96-server-9.6.5-1PGDG.rhel7.x86_64                                   3/5 
  Installing : postgresql96-contrib-9.6.5-1PGDG.rhel7.x86_64                                  4/5 
  Installing : postgresql96-devel-9.6.5-1PGDG.rhel7.x86_64                                    5/5 
  Verifying  : postgresql96-server-9.6.5-1PGDG.rhel7.x86_64                                   1/5 
  Verifying  : postgresql96-contrib-9.6.5-1PGDG.rhel7.x86_64                                  2/5 
  Verifying  : postgresql96-libs-9.6.5-1PGDG.rhel7.x86_64                                     3/5 
  Verifying  : postgresql96-devel-9.6.5-1PGDG.rhel7.x86_64                                    4/5 
  Verifying  : postgresql96-9.6.5-1PGDG.rhel7.x86_64                                          5/5 

Installed:
  postgresql96-contrib.x86_64 0:9.6.5-1PGDG.rhel7  postgresql96-devel.x86_64 0:9.6.5-1PGDG.rhel7 
  postgresql96-server.x86_64 0:9.6.5-1PGDG.rhel7  

Dependency Installed:
  postgresql96.x86_64 0:9.6.5-1PGDG.rhel7       postgresql96-libs.x86_64 0:9.6.5-1PGDG.rhel7      

Complete!

initialize database

# export PGSETUP_INITDB_OPTIONS="--encoding=UTF-8 --no-locale"
# /usr/pgsql-9.6/bin/postgresql96-setup initdb
Initializing database ... OK

# systemctl enable postgresql-9.6.service
Created symlink from /etc/systemd/system/multi-user.target.wants/postgresql-9.6.service to /usr/lib/systemd/system/postgresql-9.6.service.
[root@almascience ~]# systemctl start postgresql-9.6.service
[root@almascience ~]# su - postgres
Last login: Fri Oct  6 15:05:44 JST 2017 on pts/1
[postgres@almascience ~]$ psql
psql (9.6.5)
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)

postgres=#