How To Build Postgresql 10 Until Tunning For Spesification Server On Centos 7



Now, i can to tell you and teach you installation postgresql on centos 7. and i can tell you step by step how can installation until finished.

One step, you can do setting sysctl because you must be do up kernel to handle task switching in multitasking.

[root@localhost /]# vi /etc/sysctl.d/99-sysctl.conf

fs.aio-max-nr=1048576
fs.file-max=6815744
kernel.shmall=4294967296
kernel.shmmax=68719476736
kernel.shmmni=819200
kernel.sem=4096 2147483647 2147483646 512000
vm.swappiness=5
net.core.rmem_max=16777216
net.core.wmem_max=16777216
net.core.rmem_default=16777216
net.core.wmem_default=16777216
net.core.optmem_max=40960
net.ipv4.tcp_mem=8388608 12582912 16777216
net.ipv4.tcp_rmem=4096 87380 16777216
net.ipv4.tcp_wmem=4096 87380 16777216
kernel.sched_autogroup_enabled=0

And don't forget, you must be the configure file limits, in here I want to define user postgres for soft and hard, why? I want to for enforcing hard and soft resource limits.These limits are set by the superuser and enforced by the Kernel.

[root@localhost /]# vi /etc/security/limits.conf

root soft nofile 1024
root hard nofile 65536
postgres soft nofile 1024
postgres hard nofile 65536

And then, you can insert session for required file pam_limits.so in configuration to “/etc/pam.d/login”, lets do that command.

[root@localhost /]# vi /etc/pam.d/login

#%PAM-1.0
auth [user_unknown=ignore success=ok ignore=ignore default=bad] pam_securetty.so
auth substack system-auth
auth include postlogin
account required pam_nologin.so
account include system-auth
password include system-auth
# pam_selinux.so close should be the first session rule
session required pam_selinux.so close
session required pam_loginuid.so
session optional pam_console.so
# pam_selinux.so open should only be followed by sessions to be executed in the user context
session required pam_selinux.so open
session required pam_namespace.so
session required pam_limits.so
session optional pam_keyinit.so force revoke
session include system-auth
session include postlogin
-session optional pam_ck_connector.so

And after setting for enforcing resource limits, In here I want build java installation version 8. you can do that before installation database postgresql.

[root@localhost /]# mkdir -p /usr/java
[root@localhost /]# cd /opt/
[root@localhost opt]# cp jdk-8u181-linux-x64.tar.gz /usr/java
[root@localhost opt]# cd /usr/java
[root@localhost java]# ls -lrt
[root@localhost java]# tar -zxvf jdk-8u181-linux-x64.tar.gz

Next, if you finished extract java, you must be the configuration file profile on the location “/etc/profile” with the command vi, and export function your build system java. So lets do that command.

[root@localhost java]# vi /etc/profile

export JAVA_HOME=/usr/java/jdk1.8.0_181
export PATH=$PATH:/usr/java/jdk1.8.0_181/bin
export _JAVA_OPTIONS="-Djava.net.preferIPv4Stack=true"

If you finished, you must be called script “source”, why the called script source? Because your configuration on file that is run. And the check version is java. Lets do that's the command.

[root@localhost /]# source /etc/profile
[root@Mufins-Node1 java]# java -version
Picked up _JAVA_OPTIONS: -Djava.net.preferIPv4Stack=true
java version "1.8.0_181"
Java(TM) SE Runtime Environment (build 1.8.0_181-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.181-b13, mixed mode)

After check your java is running. You can do installation package is needed. In here I wan install packege “openssl, screen, vnc, and repolist” dont forget download file rpm postgres 10 with the web postgresql. You can do this command installation:

[root@localhost /]# cd /
[root@localhost /]# yum install gcc glibc openssl openssl-devel -y
[root@localhost /]# yum repolist
[root@localhost /]# yum install tigervnc tiger vnc-devel
[root@localhost /]# yum install tigervnc tigervnc-devel
[root@localhost /]# yum install wget -y
[root@localhost /]# cd /opt
[root@localhost opt]# wget https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-7-x86_64/pgdg-redhat10-10-2.noarch.rpm
[root@localhost /]# cd /
[root@localhost /]# yum install readline-devel netstat net-tools libpq telnet screen mailx xinetd libcvirt libvirt bind-utils chrony net-tools libevent -y
[root@localhost /]# yum install screen
[root@localhost /]# yum install zlib-devel
[root@localhost /]# yum install openssl-devel

Next step, you must be login to shell linux with root, and create directory "PG10" in /DATA/

[root@localhost /]# mkdir -p /DATA/PG10/app
[root@localhost /]# mkdir -p /DATA/PG10/data

Next, you must be move location to folder /opt because in here your file tar must be extract. You can move directory to location file copy with command "cd". so extract file in here, because i can build installation in location "/DATA/PG10/app" with command extract tar.

[root@localhost /]# cd /opt/
[root@localhost opt]# tar zxvf postgresql-10.4.tar.gz

And after extract data you can move to directory in your extract, in here if finished extract, you can see that is a folder that extraction data file. So you can see show new folder after extract "postgresql-10.4".

[root@localhost opt]# cd /opt/postgresql-10.4

So, next step again, now can do installation postgres with choose file configure and running file with command "./file".

[root@localhost postgresql-10.4]# ./configure --prefix=/DATA/PG10/app/ --with-openssl
[root@localhost postgresql-10.4]# make
[root@localhost postgresql-10.4]# make install

And then, in here i can add new user with name "postgres" because i want configuration data postgres in here, in user postgres, dont be use another user. how can do add user ? with command "adduser hostname" and build new directory data postgres in "/DATA/PG10".

[root@localhost postgresql-10.4]# su
[root@localhost postgresql-10.4]# adduser postgres

After create new directory, you must be change owner to postgres because in here you must be owner always postgres can be processed

[root@localhost postgresql-10.4]# chown postgres:postgres -R /DATA

Next, you can move in user root to user postgres with command "su - postgres", so in here you can do initialitation database postgres with path binary postgres. and you can be link for log file.

[root@localhost postgresql-10.4]# su - postgres
[postgres@localhost postgresql-10.4]$ /DATA/PG10/app/bin/initdb -D /DATA/PG10/data

After initialitation database, you must be the setting configuration file “postgresql.conf”, in here I wanna be customize database postgresql. So lets do that the command. ( Attention: if you wanna tunning or customize you can do spesification server and version postgres, tunning with pg tune https://pgtune.leopard.in.ua/).

[postgres@localhost postgresql-10.4]$ cd /DATA/PG10/data
[postgres@localhost data]$ vi postgresql.conf

listen_addresses = '*' # setting for all listen ip addres
port = 5432 # setting default or you can do custome
max_connections = 3000 #you can do custome limit connection who is that to be connacted here
superuser_reserved_connections = 3 #acces for superuser
shared_buffers = 64256MB
work_mem = 1MB
maintenance_work_mem = 2GB
dynamic_shared_memory_type = posix
effective_io_concurrency = 2
max_worker_processes = 58
max_parallel_workers_per_gather = 29
max_parallel_workers = 58
wal_level = hot_standby
wal_buffers = 16MB
max_wal_size = 4GB
min_wal_size = 80MB
checkpoint_completion_target = 0.9
archive_mode = off
archive_command = ''
max_wal_senders = 3
wal_keep_segments = 32
hot_standby = on
random_page_cost = 4.0
effective_cache_size = 192768MB
default_statistics_target = 100
log_destination = 'stderr'
logging_collector = on
log_directory = 'logs'
log_filename = 'logmufinsmfilepsql-%Y-%m-%d.log'
log_rotation_age = 1d
log_line_prefix = '%t [%p] %a %u %d %r %e'

Save ctrl+cshift + ;wq!enter

Next step, you must be the start database with function pg_ctl on the binary your location database. So that is the run databse after setting. Lets do that the command.

[postgres@localhost postgresql-10.4]$ /DATA/PG10/app/bin/pg_ctl -D /DATA/PG10/data start

So after do that, you can use psql with command psql and follow new database name.

[postgres@localhost postgresql-10.4]$ /DATA/PG10/app/bin/psql -p 5432 -d postgres

Or if you want called function psql not location directory binary psql. You must be export location psql binary in file “.bash_profile” let's do the command in here.

[postgres@localhost postgresql-10.4]$ cd /home/postgres
[postgres@localhost ~]$ pwd
/home/postgres
[postgres@localhost ~]$ vi .bash_profile

# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/.local/bin:$HOME/bin
PATH=$PATH:/DATA/PG10/app/bin
export PATH

Save ctrl+cshift + ;wq!enter

[postgres@localhost ~]$ source /home/postgres/.bash_profile

And now you can do called function psql in all location it's no problem. Test do that.

[postgres@localhost ~]$ psql -p 5432 -d postgres

So, in here you can do edit file pg_hba.conf for configuration postgres, why? because if you want use postgresql (PGAdmin 4) you must be configuration in akses data for another ip.

[postgres@localhost ~]$ cd /DATA/PG10/data
[postgres@localhost data]$ vi pg_hba.conf

And the press button keyword "i" for insert, so add new ip in line "IPv4 Local connection"
# TYPE DATABASE USER CIDR-ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all trust
# IPv4 local connections:
#host all all 127.0.0.1/32 trust
host all all IP_PC_KITA/24 trust
# IPv6 local connections:
host all all ::1/128 trust

After added, then you can do press button "esc" in keyword and follow command shift+: --> press button "x" then enter. And you can reload to database connection (#don't be restart if database running transaction, you must be confirmation for all division if different division use this database).

[postgres@localhost data]$ pg_ctl -D /DATA/PG10/data reload
server signaled.

[postgres@localhost data]$

Comments