CentOS 6.6安装postgresql9.6.6

时间:2023-03-09 04:58:52
CentOS 6.6安装postgresql9.6.6

一、环境介绍

系统平台:CentOS release 6.6 (Final)

Postgresql:postgresql-9.6.6

二、安装过程

1.安装依赖包

yum -y install gcc*

CentOS 6.6安装postgresql9.6.6

yum -y install readline-devel

CentOS 6.6安装postgresql9.6.6

2.源码包获取

wget http://ftp.postgresql.org/pub/source/v9.6.6/postgresql-9.6.6.tar.gz

如果出现这个错误,说明没有安装wget

CentOS 6.6安装postgresql9.6.6

可执行如下命令,安装

yum -y install wget

3.解压

tar zxf postgresql-9.6..tar.gz

4.创建用户、设置密码

adduser postgres
passwd postgres

5.编译安装

cd postgresql-9.6.
./configure --prefix=/home/postgres/pgsql
gmake
gmake install

CentOS 6.6安装postgresql9.6.6

6.设置环境变量

vim /etc/profile

7.创建数据库目录

mkdir /home/postgres/pgsql/data

创建数据库操作历史记录文件

touch /home/postgres/pgsql/.pgsql_history

更改所属组

chown -R postgres:postgres /home/postgres/pgsql/*

8.切换到postgre用户,初始化数据库

su - postgres
/home/postgres/pgsql/bin/initdb -D /home/postgres/pgsql/data
exit

9.编译启动命令

从postgres解压后的文件夹里拷贝linux到/etc/init.d/

cp /root/postgresql-9.6./contrib/start-scripts/linux /etc/init.d/postgresql
vim /etc/init.d/postgresql

修改下面两行:

prefix=/home/postgres/pgsql
PGDATA="/home/postgres/pgsql/data"

保存退出

添加可执行权限

chmod +x /etc/init.d/postgresql

10.启动postgres数据库

/etc/init.d/postgresql start