Установка PostgreSQL 9.6 (ванильный)

В CentOS 7, по умолчанию, достуна версия postgres 9.2.

[root@2rim ~]# yum info postgresql-server
Загружены модули: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirror.yandex.ru
 * epel: mirror.nl.leaseweb.net
 * extras: centos.mirror.far.fi
 * updates: centos.mirror.far.fi
Доступные пакеты
Название: postgresql-server
Архитектура: x86_64
Версия: 9.2.18
Выпуск: 1.el7
Объем: 3.8 M
Источник: base/7/x86_64
Аннотация: The programs needed to create and run a PostgreSQL server
Ссылка: http://www.postgresql.org/
Лицензия: PostgreSQL
Описание: PostgreSQL is an advanced Object-Relational database management system (DBMS).
        : The postgresql-server package contains the programs needed to create
        : and run a PostgreSQL server, which will in turn allow you to create
        : and maintain PostgreSQL databases.

 

Установка репозитория 

Страница официального репозитория https://yum.postgresql.org/https://yum.postgresql.org/repopackages.php

yum install https://download.postgresql.org/pub/repos/yum/9.6/redhat/rhel-7-x86_64/pgdg-centos96-9.6-3.noarch.rpm

Установка PostreSQL

Поглядим, что нам доступно:

[root@2rim ~]# yum search postgres | sed -n '/^postgresql96/p'

postgresql96.x86_64 : PostgreSQL client programs and libraries
postgresql96-contrib.x86_64 : Contributed source and binaries distributed with
postgresql96-debuginfo.x86_64 : Debug information for package postgresql96
postgresql96-devel.x86_64 : PostgreSQL development header files and libraries
postgresql96-docs.x86_64 : Extra documentation for PostgreSQL
postgresql96-libs.x86_64 : The shared libraries required for any PostgreSQL
postgresql96-odbc.x86_64 : PostgreSQL ODBC driver
postgresql96-plperl.x86_64 : The Perl procedural language for PostgreSQL
postgresql96-plpython.x86_64 : The Python procedural language for PostgreSQL
postgresql96-pltcl.x86_64 : The Tcl procedural language for PostgreSQL
postgresql96-server.x86_64 : The programs needed to create and run a PostgreSQL
postgresql96-tcl.x86_64 : A Tcl client library for PostgreSQL
postgresql96-tcl-debuginfo.x86_64 : Debug information for package
postgresql96-test.x86_64 : The test suite distributed with PostgreSQL

Установим пакеты:

yum install postgresql96 postgresql96-server postgresql96-libs postgresql96-contrib postgresql96-devel -y

После установки в системе появится новый пользователь - postgres, а также каталог для баз данных: /var/lib/pgsql/9.6/data

Посмотрим домашний каталог пользователя:

su - postgres

-bash-4.2$ echo $HOME
/var/lib/pgsql

Инициализация кластера базы данных

При инициализации кластер создается с локалью аналогичной локали пользователя postgres. Какая локаль у пользователя postgres в системе:

-bash-4.2$ localectl status
   System Locale: LANG=en_US.UTF-8
       VC Keymap: us
      X11 Layout: n/a

Поменяем локаль. У пользователя postgres, во время смены локали, будет запрошен пароль root-а.

localectl set-locale LANG=ru_RU.UTF-8
-bash-4.2$ localectl status
   System Locale: LANG=ru_RU.UTF-8
       VC Keymap: us
      X11 Layout: n/a

Инициализируем (под пользователем postgres):

su - postgres

/usr/pgsql-9.6/bin/initdb -D /var/lib/pgsql/9.6/data

Старт и работа

systemctl start postgresql-9.6
systemctl enable postgresql-9.6
Created symlink from 
/etc/systemd/system/multi-user.target.wants/postgresql-9.6.service 
to /usr/lib/systemd/system/postgresql-9.6.service

Файлы базы данных находятся по умолчанию:

/var/lib/pgsql/9.6/data/base
  • /var/lib/pgsql/9.6/data/postgresql.conf - основной конфигурационный файл, содержащий параметры сервера баз данных.
  • /var/lib/pgsql/9.6/data/pg_hba.conf - файл, определяющий настройки доступа к серверу баз данных.

 

 

Автор: Александр