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

PostgreSQL-12.6 源码安装

原创 .key 2021-12-02
1000

官网地址:https://www.postgresql.org/

源码包下载地址:https://www.postgresql.org/ftp/source/

中文社区地址:http://www.postgres.cn/index.php/v2/home

1. 修改hosts配置文件

[root@postgres ~]# vim /etc/hosts ...... 192.168.117.147 postgres

2. 关闭安全策略

#临时关闭selinux setenforce 0 #永久关闭selinux,重启后生效 sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config #关闭防火墙 systemctl stop firewalld systemctl disable firewalld

3. 创建数据库用户和组

[root@postgres ~]# useradd postgres [root@postgres ~]# passwd postgres

4. 安装依赖包

[root@postgres ~]# yum -y groupinstall "Development Tools" "Legacy UNIX Compatibility" [root@postgres ~]# yum -y install bison flex readline* zlib-devel gcc* make

5. 创建目录并授权

[root@postgres ~]# mkdir /usr/local/pg12 [root@postgres ~]# mkdir -p /pgdata/12/data [root@postgres ~]# chown -R postgres: /pgdata/ /usr/local/pg12/ [root@postgres ~]# chmod -R 700 /pgdata/

6. 系统参数配置

[root@postgres ~]# vim /etc/sysctl.conf ...... kernel.shmmax = 68719476736 kernel.shmall = 4294967296 kernel.shmmni = 4096 kernel.sem = 50100 64128000 50100 1280 fs.file-max = 7672460 net.ipv4.ip_local_port_range = 9000 65000 net.core.rmem_default = 1048576 net.core.rmem_max = 4194304 net.core.wmem_default = 262144 net.core.wmem_max = 1048576 [root@postgres ~]# sysctl -p [root@postgres ~]# vim /etc/security/limits.conf ...... soft nofile 131072 hard nofile 131072 soft nproc 131072 hard nproc 131072 soft core unlimited hard core unlimited soft memlock 50000000 hard memlock 50000000

7. 源码安装

# 上传安装包[root@postgres opt]# ls postgresql-12.6.tar.gz [root@postgres opt]# tar -xf postgresql-12.6.tar.gz [root@postgres opt]# mv postgresql-12.6/ postgres/[root@postgres opt]# cd postgres/ [root@postgres postgres]# ./configure --prefix=/usr/local/pg12 --with-pgport=1921 [root@postgres postgres]# gmake world [root@postgres postgres]# gmake install-world

8. 设置环境变量               

[root@postgres ~]# su - postgres [postgres@postgres ~]$ vim .bash_profile ...... export PGDATA=/pgdata/12/data export LANG=en_US.utf8 export PGHOME=/usr/local/pg12 export LD_LIBRARY_PATH=$PGHOME/lib:/lib64:/usr/lib64:/usr/local/lib64:/lib:/usr/lib:/usr/local/lib:$LD_LIBRARY_PATH export DATE=`date +"%Y%m%d%H%M"` export PATH=$PGHOME/bin:$PATH:. export MANPATH=$PGHOME/share/man:$MANPATH export PGUSER=postgres [postgres@postgres ~]$ source .bash_profile [postgres@postgres ~]$ psql --version psql (PostgreSQL) 12.6

9. 初始化数据

[postgres@postgres ~]$ initdb -A md5 -D $PGDATA -E utf8 --locale=C -W #输入两次密码: Enter new superuser password: Enter it again:

10. 启动数据库

[postgres@postgres ~]$ pg_ctl -D $PGDATA -l logfile start waiting for server to start.... done server started

11. 停止数据库和重启数据库

[postgres@postgres ~]$ pg_ctl -D $PGDATA stop -ms [postgres@postgres ~]$ pg_ctl -D $PGDATA stop -mf(推荐使用这种) [postgres@postgres ~]$ pg_ctl -D $PGDATA stop -mi [postgres@postgres ~]$ pg_ctl -D $PGDATA -l logfile restart -mf

「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论