Postgresql学习01-PG14.2-Linux平台源码编译安装和配置开机自启

一、postgresql-14.2-源码包下载链接

https://ftp.postgresql.org/pub/source/v14.2/postgresql-14.2.tar.gz

二、环境简介

名称
cpuIntel® Core™ i7-7700HQ CPU @ 2.80GHz
操作系统Red Hat Enterprise Linux Server release 7.9 (Maipo)
pg数据目录/opt/pg14-2
pg安装目录/opt/pg14-2/data

三、安装

1、关闭 SELinux

编辑/etc/selinux/config,修改参数SELINUX=disabled。

2、创建用户和组

groupadd postgres -g 2000

useradd postgres -g 2000 -u 2000

echo "postgres"|passwd --stdin postgres

3、修改操作系统limits

编辑/etc/security/limits.conf添加如下参数:

postgres soft nofile 1048576
postgres hard nofile 1048576
postgres soft nproc 131072
postgres hard nproc 131072
postgres soft stack 10240
postgres hard stack 32768
postgres soft core 6291456
postgres hard core 6291456

4、编译安装

yum -y install readline readline-devel zlib zlib-devel gettext gettext-devel openssl openssl-devel pam pam-devel libxml2 libxml2-devel libxslt libxslt-devel perl perl-devel tcl-devel uuid-devel gcc gcc-c++ make flex bison perl-ExtUtils*

cd /opt/postgresql-14.2

./configure --prefix=/opt/pg14-2 --enable-debug --enable-dtrace

gmake world -j 4

gmake install-world

注: --enable-debug --enable-dtrace,不调试可以不加。

如果大家想调试PG代码,最好在configure之后,把src/Makefile.global中的编译优化去掉,再进行gmake或make,因为优化后可能和源码的位置对不上,不利于大家学习PG代码,不调试的小伙伴可以不加下面这步。

vim src/Makefile.global

我只是把原来的CXXFLAGS、CFLAGS内容注释了,具体如下:

#CFLAGS = -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -g -O2

CFLAGS = -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -g

#CXXFLAGS = -Wall -Wpointer-arith -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -g -O2

CXXFLAGS = -Wall -Wpointer-arith -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -g

5、修改用户组

chown -R postgres:postgres /opt/pg14-2

6、初始化库

su - postgres

cd /opt/pg14-2/bin

./initdb -D/opt/pg14-2/data -X/opt/pg14-2/pgwal

7、修改配置文件

(1)编辑pg_hba.conf,添加如下内容:

host    all             all             0.0.0.0/0               md5

(2)编辑postgresql.conf,修改如下参数:

listen_addresses = '*'

8、启动数据库

su - postgres

cd /opt/pg14-2/bin

./pg_ctl -D /opt/pg14-2/data -l /opt/pg14-2/data/logfile restart

9、psql连接数据库

su - postgres

cd /opt/pg14-2/bin

./psql

select version();

在这里插入图片描述

10、数据库环境变量

编辑/home/postgres/.bashrc,添加如下内容:

export PGPORT=5432
export PGUSER=postgres
export PGDATABASE=postgres
export PGHOME=/opt/pg14-2
export PGDATA=/opt/pg14-2/data
export PATH=$PGHOME/bin:$PATH

11、配置数据库自启

cp /opt/postgresql-14.2/contrib/start-scripts/linux /etc/init.d/pg14-2

vim /etc/init.d/pg14-2

修改如下内容:
在这里插入图片描述

chmod 755 /etc/init.d/pg14-2

chkconfig --add pg14-2

chkconfig --list

在这里插入图片描述

  • 3
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值