一、环境介绍
系统平台:CentOS release 6.6 (Final)
Postgresql:postgresql-9.6.6
SELINUX=disabled
Iptables关闭
二、安装过程
1.安装依赖包
1
2
|
yum -y
install
gcc*
yum -y
install
readline-devel
|
2. 源码包获取
1
|
wget http:
//ftp
.postgresql.org
/pub/source/v9
.6.6
/postgresql-9
.6.6.
tar
.gz
|
3. 解压
1
|
tar
zxf postgresql-9.6.6.
tar
.gz
|
5.创建用户、设置密码
1
2
|
adduser postgres
passwd
postgres
|
6. 编译安装
1
2
3
4
|
cd
postgresql-9.6.6
.
/configure
--prefix=
/home/postgres/pgsql
gmake
gmake
install
|
7.设置环境变量
1
|
vim
/etc/profile
|
添加一行
1
2
|
PATH=$PATH:$HOME
/bin
:
/home/postgres/pgsql/bin
source
/etc/profile
|
8.创建数据库目录
1
|
mkdir
/home/postgres/pgsql/data
|
创建数据库操作历史记录文件
1
|
touch
/home/postgres/pgsql/
.pgsql_history
|
更改所属组
1
|
chown
-R postgres:postgres
/home/postgres/pgsql/
*
|
9.切换到postgre用户,初始化数据库
1
2
3
|
su
- postgres
/home/postgres/pgsql/bin/initdb
-D
/home/postgres/pgsql/data
exit
|
10.编译启动命令
从postgres解压后的文件夹里拷贝linux到/etc/init.d/
1
2
|
cp
/root/postgresql-9
.6.6
/contrib/start-scripts/linux
/etc/init
.d
/postgresql
vim
/etc/init
.d
/postgresql
|
修改下面两行:
1
2
|
prefix=
/home/postgres/pgsql
PGDATA=
"/home/postgres/pgsql/data"
|
保存退出
添加可执行权限
1
|
chmod
+x
/etc/init
.d
/postgresql
|
11.启动postgres数据库
1
|
/etc/init
.d
/postgresql
start
|
12.测试使用
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
[root@MidApp ~]
#su - postgres
[postgres@MidApp ~]$ psql
psql (9.6.6)
Type
"help"
for
help.
postgres=
# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+----------+-------------+-------------+-----------------------
postgres | postgres | UTF8 | en_US.utf-8 | en_US.utf-8 |
template0 | postgres | UTF8 | en_US.utf-8 | en_US.utf-8 | =c
/postgres
+
| | | | | postgres=CTc
/postgres
template1 | postgres | UTF8 | en_US.utf-8 | en_US.utf-8 | =c
/postgres
+
| | | | | postgres=CTc
/postgres
(3 rows)
postgres=
# \q
|
本文转自 青苗飞扬 51CTO博客,原文链接:http://blog.51cto.com/qingmiao/2046357