暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

PG 单实例安装与配置优化实践

IT那活儿 2024-08-12
123

点击上方“IT那活儿”公众号--专注于企业全栈运维技术分享,不管IT什么活儿,干就完了!!!



此安装为虚拟机安装,如有生产需要,仅供借鉴,请根据生产需要以及官方文档进行修改配置文件及参数,谨慎使用。






环境准备



1.1 基础环境

  • 操作系统:CentOS7;
  • CPU内存:1G;
  • 磁盘:20G
  • 缓存:虚拟机测试大小没有限制,正式环境请参考官网设置合适数值;

1.2 环境检查

检查防火墙确认关闭,关闭开机自启
systemctl status firewalld.service
禁用开机自启防火墙:
systemctl disable firewalld.service
关闭防火墙:
systemctl stop firewalld.service
systemctl status firewalld.service

禁用/etc/sysconfig/selinux:




参数用户配置



2.1 参数配置

修改内核参数:
cat >> etc/sysctl.conf <<EOF
fs.aio-max-nr = 3145728
fs.file-max = 6815744
kernel.shmall = 131072000
kernel.shmmax = 536870912000
kernel.shmmni = 4096
kernel.sem = 250 32000 100 128
net.ipv4.ip_local_port_range = 9000 65500
net.core.rmem_default = 262144
net.core.rmem_max = 4194304
net.core.wmem_default = 262144
net.core.wmem_max = 1048576

#大页参数
vm.nr_hugepages = 1064   --根据实际内存设置适配值
EOF

执行sysctl -p 使内核参数生效:
注:此处未添加大页参数,自己的虚拟机配置不够。
设置资源限制: --应在用户配置完成后添加。
cat >> /etc/security/limits.conf <<EOF
postgre soft nproc 20480
postgre hard nproc 65536
postgre soft nofile 20480
postgre hard nofile 65536
postgre hard memlock unlimited
postgre soft memlock unlimited
EOF

2.2 用户配置

创建用户与组:
groupadd -g 5432 postgre && useradd -u 5432 -g postgre postgre && echo postgre|passwd --stdin postgre
Id postgre

创建安装目录并授予权限: --可自行定义安装位置。
mkdir -p /usr/local/postgre/{db,data} && chown -R postgre:postgre /usr/local/postgre && chmod -R 775 /usr/local/postgre
安装依赖包:
yum -y install gcc readline-devel zlib-devel
配置环境变量: --给postgre用户配置环境变量。

cat >> .bash_profile <<EOF
export PGHOME=/usr/local/postgre/db
export PGDATA=/usr/local/postgre/data
export PGPORT=5432
export PGUSER=postgre
export PGLOG=\$PGDATA/postgre12.5.log
export PATH=\$PGHOME/bin:\$PATH
export LANG=en_US.utf8
export LD_LIBRARY_PATH=\$PGHOME/lib:\$LD_LIBRARY_PATH

alias pgstop='pg_ctl -D \$PGDATA -l \$PGLOG stop'
alias pgstart='pg_ctl -D \$PGDATA -l \$PGLOG start'
alias cdlog='cd \$PGDATA/log'
EOF
source .bash_profile




安装部署



3.1 解压编译源码安装包

tar -zxf /home/postgre/postgresql-12.5.tar.gz -C /home/postgre && cd /home/postgre/postgresql-12.5 && ./configure --prefix=$PGHOME && make && make install
3.2 初始化数据库
initdb -E utf8 -D $PGDATA
3.3 启停PG数据库
pg_ctl -D $PGDATA -l $PGLOG  start
pg_ctl -D $PGDATA -l $PGLOG  stop
至此PG数据库单实例安装已完成。

END


本文作者:成 龙(上海新炬中北团队)

本文来源:“IT那活儿”公众号

文章转载自IT那活儿,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论