centos 7.4 + postgresql 10.x + yum

os: centos 7.4.1708
postgrsql: 10

os 调整

# vi /etc/rc.local
#禁用透明大页
if test -f /sys/kernel/mm/transparent_hugepage/enabled; then
   echo never > /sys/kernel/mm/transparent_hugepage/enabled
fi
if test -f /sys/kernel/mm/transparent_hugepage/defrag; then
   echo never > /sys/kernel/mm/transparent_hugepage/defrag
fi

#修改 io scheduler为deadline
echo deadline > /sys/block/sda/queue/scheduler 

保存后添加执行权限 chmod u+x /etc/rc.d/rc.local

os 关闭selinux

vi /etc/selinux/config
SELINUX=DISABLED
或者
vi /etc/sysconfig/selinux
SELINUX=DISABLED

os 资源限制

vi /etc/security/limits.conf

root soft nofile  655360 # The maximum number of open file descriptors
root hard nofile  655360
postgres soft nofile  655360
postgres hard nofile  655360

root soft nproc   655360 # The maximum number of processes available to a single user
root hard nproc   655360
postgres soft nproc   655360
postgres hard nproc   655360

* soft memlock unlimited # The maximum size that may be locked into memory
* hard memlock unlimited
* soft core    unlimited # The maximum size of core files created
* hard core    unlimited
* soft stack   unlimited  
* hard stack   unlimited 

os 修改内核参数

vi /etc/sysctl.conf
#kernel.shmmax =
#kernel.shmall =
kernel.shmmni = 4096

#kernel.sem = 250 32000 100 128 #这个设置在很多场合都报错了,有公式计算
kernel.sem = 50100 64128000 50100 1280 
fs.aio-max-nr = 1048576
fs.file-max = 7672460


net.ipv4.ip_local_port_range = 9000 65000
# 禁用整个系统所有接口的IPv6
net.ipv6.conf.all.disable_ipv6 = 1

net.ipv4.tcp_keepalive_time = 60
net.ipv4.tcp_keepalive_probes = 9
net.ipv4.tcp_keepalive_intvl =20
net.ipv4.tcp_retries2 = 5

net.core.rmem_default = 1048576
net.core.rmem_max = 4194304
net.core.wmem_default = 262144
net.core.wmem_max = 1048576

vm.overcommit_memory = 2
vm.overcommit_ratio = 90 
vm.swappiness = 1

使用 sysctl -p 立即生效

os yum安装依赖包

# uname -a
Linux tpg-1 3.10.0-693.11.1.el7.x86_64 #1 SMP Mon Dec 4 23:52:40 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

# cat /etc/redhat-release 
CentOS Linux release 7.4.1708 (Core) 

# yum install git tree sysstat wget make cmake gcc gcc-c++ lrzsz flex bison unixODBC

# yum install smartmontools coreutils glib2 perl perl-devel perl-ExtUtils-Embed zlib zlib-devel openldap openldap-devel flex readline readline-devel systemtap systemtap-sdt-devel python python-devel tcl tcl-devel sgml-common docbook* stylesheets openjade sgml-tools libxslt libxslt-devel libxml2 libxml2-devel openssl openssl-devel pam pam-devel libicu libicu-devel uuid uuid-devel


os 安装 postgresql 10 的yum source

参考:
https://www.postgresql.org/download/linux/redhat/

[root@tpg-1 ~]# yum install https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-7-x86_64/pgdg-centos10-10-1.noarch.rpm


安装 postgresql 10

[root@tpg-1 ~]# yum install postgresql10*


==============================================================================================================================================
 Package                                 Arch                Version                                Repository                           Size
==============================================================================================================================================
Installing:
 postgresql10                            x86_64              10.1-1PGDG.rhel7                       pgdg10-updates-testing              1.5 M
 postgresql10-contrib                    x86_64              10.1-1PGDG.rhel7                       pgdg10-updates-testing              587 k
 postgresql10-debuginfo                  x86_64              10.1-1PGDG.rhel7                       pgdg10-updates-testing               18 M
 postgresql10-devel                      x86_64              10.1-1PGDG.rhel7                       pgdg10-updates-testing              2.0 M
 postgresql10-docs                       x86_64              10.1-1PGDG.rhel7                       pgdg10-updates-testing               14 M
 postgresql10-libs                       x86_64              10.1-1PGDG.rhel7                       pgdg10-updates-testing              347 k
 postgresql10-odbc                       x86_64              10.00.0000-1PGDG.rhel7                 pgdg10-updates-testing              280 k
 postgresql10-plperl                     x86_64              10.1-1PGDG.rhel7                       pgdg10-updates-testing               55 k
 postgresql10-plpython                   x86_64              10.1-1PGDG.rhel7                       pgdg10-updates-testing               72 k
 postgresql10-pltcl                      x86_64              10.1-1PGDG.rhel7                       pgdg10-updates-testing               33 k
 postgresql10-server                     x86_64              10.1-1PGDG.rhel7                       pgdg10-updates-testing              4.3 M
 postgresql10-tcl                        x86_64              2.3.1-1.rhel7                          pgdg10-updates-testing              336 k
 postgresql10-tcl-debuginfo              x86_64              2.3.1-1.rhel7                          pgdg10-updates-testing              7.6 k
 postgresql10-test                       x86_64              10.1-1PGDG.rhel7                       pgdg10-updates-testing              1.6 M
Installing for dependencies:
 libicu                                  x86_64              50.1.2-15.el7                          base                                6.9 M
 libicu-devel                            x86_64              50.1.2-15.el7                          base                                702 k
 libtool-ltdl                            x86_64              2.4.2-22.el7_3                         base                                 49 k
 libxslt                                 x86_64              1.1.28-5.el7                           base                                242 k
 tcl                                     x86_64              1:8.5.13-8.el7                         base                                1.9 M
 unixODBC                                x86_64              2.3.1-11.el7                           base                                413 k

Transaction Summary
==============================================================================================================================================
Install  14 Packages (+6 Dependent packages)


Installed:
  postgresql10.x86_64 0:10.1-1PGDG.rhel7                                  postgresql10-contrib.x86_64 0:10.1-1PGDG.rhel7                      
  postgresql10-debuginfo.x86_64 0:10.1-1PGDG.rhel7                        postgresql10-devel.x86_64 0:10.1-1PGDG.rhel7                        
  postgresql10-docs.x86_64 0:10.1-1PGDG.rhel7                             postgresql10-libs.x86_64 0:10.1-1PGDG.rhel7                         
  postgresql10-odbc.x86_64 0:10.00.0000-1PGDG.rhel7                       postgresql10-plperl.x86_64 0:10.1-1PGDG.rhel7                       
  postgresql10-plpython.x86_64 0:10.1-1PGDG.rhel7                         postgresql10-pltcl.x86_64 0:10.1-1PGDG.rhel7                        
  postgresql10-server.x86_64 0:10.1-1PGDG.rhel7                           postgresql10-tcl.x86_64 0:2.3.1-1.rhel7                             
  postgresql10-tcl-debuginfo.x86_64 0:2.3.1-1.rhel7                       postgresql10-test.x86_64 0:10.1-1PGDG.rhel7                         

Dependency Installed:
  libicu.x86_64 0:50.1.2-15.el7   libicu-devel.x86_64 0:50.1.2-15.el7   libtool-ltdl.x86_64 0:2.4.2-22.el7_3   libxslt.x86_64 0:1.1.28-5.el7  
  tcl.x86_64 1:8.5.13-8.el7       unixODBC.x86_64 0:2.3.1-11.el7       

Complete!

postgresql-10.service

[root@tpg-1 ~]# find / -name "postgresql-10.service"
/usr/lib/systemd/system/postgresql-10.service

[root@tpg-1 ~]# /usr/pgsql-10/bin/postgresql-10-setup initdb
[root@tpg-1 ~]# systemctl enable postgresql-10
[root@tpg-1 ~]# systemctl start postgresql-10


postgres 的配置文件

postgresql 是在 yum install postgresql10* 自动创建的,信息如下

# cat /etc/passwd |grep -i postgres
postgres:x:26:26:PostgreSQL Server:/var/lib/pgsql:/bin/bash
# cat /etc/group |grep -i postgres
postgres:x:26:
# id postgres
uid=26(postgres) gid=26(postgres) groups=26(postgres)


postgres 用户原始的配置文件

-bash-4.2$ cat ~/.bash_profile
[ -f /etc/profile ] && source /etc/profile
PGDATA=/var/lib/pgsql/10/data
export PGDATA
# If you want to customize your settings,
# Use the file below. This is not overridden
# by the RPMS.
[ -f /var/lib/pgsql/.pgsql_profile ] && source /var/lib/pgsql/.pgsql_profile


postgres 用户修改后的配置文件

-bash-4.2$ cat ~/.bash_profile
[ -f /etc/profile ] && source /etc/profile
export PGHOME=/usr/pgsql-10
export PGDATA=/var/lib/pgsql/10/data

export MANPATH=$PGHOME/share/man:$MANPATH
export LD_LIBRARY_PATH=$PGHOME/lib
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/lib:/usr/lib:/usr/local/lib
export PATH=$PGHOME/bin:$PATH

export TEMP=/tmp
export TMPDIR=/tmp

export PS1="[e[32;1m][u@h W]$>[e[0m]"

# If you want to customize your settings,
# Use the file below. This is not overridden
# by the RPMS.
[ -f /var/lib/pgsql/.pgsql_profile ] && source /var/lib/pgsql/.pgsql_profile


没有使用建议的 /var/lib/pgsql/.pgsql_profile 这个配置文件

最后根据情况调整 postgresql.conf 的参数值

原文地址:https://www.cnblogs.com/ctypyb2002/p/9793090.html