CentOS 7 源码编译安装 PostgreSQL 11.2

环境

系统版本 Centos7.6

工具:xshell6

PostgreSql: postgresql-11.2.tar.gz

 

安装部署


安装前准备

官网下载PostgreSQL 11.2源码地址:https://www.postgresql.org/ftp/source/v11.2/

选择postgresql-11.2.tar.gz

编译安装

tar -zxvf postgresql-11.2.tar.gz
cd postgresql-11.2
./configure --prefix=/usr/local/postgresql --without-readline
make && make install

 进入安装后的目录,查看目录结构

cd /usr/local/postgresql/

 安装服务器端包

yum -y install postgresql11

创建目录 data、log

mkdir /usr/local/postgresql/data
mkdir /usr/local/postgresql/log
chmod -R 775 /usr/local/postgresql/data

配置环境变量

vim /etc/profile

PGHOME=/usr/local/postgresql
export PGHOME
PGDATA=/usr/local/postgresql/data
export PGDATA
PATH=$PATH:$HOME/.local/bin:$HOME/bin:$PGHOME/bin
export PATH

使配置文件生效

source /etc/profile

创建用户

useradd postgres

将pg的数据目录全部赋给postgres用户,执行以下命令:

chown -R postgres:postgres /usr/local/postgresql/

初始化数据库

切换到postgres用户,执行如下命令:

su - postgres
/usr/local/postgresql/bin/initdb -D /usr/local/postgresql/data/

 

 

 

启动数据库

/usr/local/postgresql/bin/pg_ctl -D /usr/local/postgresql/data/ -l logfile start

查看数据库版本

psql -V

psql (PostgreSQL) 11.2
 

连接数据库

psql -U postgres -d postgres

配置文件

目录/usr/local/postgresql/data/下,pg_hba.conf和postgresql.conf两个文件。

vi /usr/local/postgresql/data/pg_hba.conf

 

vi /usr/local/postgresql/data/postgresql.conf

 修改listen_addresses = ‘*’;

登录数据库

psql -U postgres -d postgres

 

设置防火墙规则

firewall-cmd --zone=public --add-port=8432/tcp --permanent

firewall-cmd --reload

初始化 database

/usr/pgsql-11/bin/postgresql-11-setup initdb

重启数据库

systemctl restart postgresql-11

设置开机启动

自动启动
systemctl enable postgresql-11.service
启动
systemctl start postgresql-11.service
停止某服务
systemctl stop postgresql-11.service
不自动启动
systemctl disable postgresql-11.service
检查服务状态(服务详细信息)
systemctl status postgresql-11.service
检查服务状态(仅显示是否Active)
systemctl is-active postgresql-11.service
显示所有已启动的服务
systemctl list-units --type=service

 


参考

https://yq.aliyun.com/articles/715609

https://blog.csdn.net/llwy1428/article/details/95444151

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

DrugAI

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值