Cài đặt các package hỗ trợ:
# yum install -y gcc make systemd-devel zlib-devel readline-devel
Tạo postgres user
# useradd -m -s /bin/bash postgres
# usermod -aG wheel postgres
# passwd postgres
Chuyển qua user postgres
# su postgres
Tiến hành Download source code PostgreSQL
wget https://ftp.postgresql.org/pub/source/v12.0/postgresql-12.0.tar.gz
(Hoặc bạn có thể download từ windows PC rồi dùng WinSCP copy lên server linux)
Tiến hành giải nén:
$ gunzip postgresql-12.1.tar.gz
$ tar xf postgresql-12.1.tar
$ cd postgresql-12.1

Thực hiện build
### Thực hiện cấu hình:
./configure --with-icu --with-openssl --with-systemd
Chú ý: --with-systemd : hỗ trợ build với systemd

Make a build
$ make

Kiểm tra trước khi cài đặt
$ make check

Tiến hành cài đặt
$ sudo make install

Cấu hình biến môi trường cho postgres server:
$ DATA_DIR=/usr/local/pgsql/data
$ sudo mkdir $DATA_DIR
$ sudo chown postgres $DATA_DIR
$ echo 'export PATH=$PATH:/usr/local/pgsql/bin' > /etc/profile.d/postgres.sh
Khởi tạo database cluster
$ initdb --encoding=UTF8 --locale=C -D $DATA_DIR

Như vậy bạn đã cài xong postgres 12 cho server centos linux
Bài viết sau chúng tôi sẽ hướng dẫn bạn cấu hình master-slave server cho postgres 12 nhé