centos环境源码安装postgresql9.4

源码安装简要步骤

  • 下载PostgreSQL 源码包 
    下载根目录地址:http://ftp.postgresql.org/ 
    本人选择的是当前最新版本v9.4.1:http://ftp.postgresql.org/pub/source/v9.4.1/ 
    本人下载的源码压缩包地址如下:
$ /usr/local/postgresql
  • 1
  • 解压源码包
$ tar -zxvf postgresql-9.4.1.tar.gz
  • 1
  • 进入解压后的目录
$ cd postgresql-9.4.1
  • 1

  • 开始编译安装PostgreSQL 数据库
$ ./configure
  • 1
  • 执行gmake
$ gmake
  • 1

  - 执行gmake install

$ gmake install
  • 1

- 设置环境变量

$ vi .bash_profile
#### 把 PATH=$PATH:$HOME/bin 改成下面内容 ####
$ PATH=$PATH:$HOME/bin:/usr/local/pgsql/bin
  • 1
  • 2
  • 3
  • 让环境变量生效
$ source .bash_profile
  • 1
  • 添加用户postgres
$ adduser postgres
  • 1

  - 更改用户目录(可选操作)

$ vi /etc/passwd
#### 把 postgres:x:528:528::/home/postgres:/bin/bash 改成下面内容 ####
$ postgres:x:528:528::/usr/local/pgsql:/bin/bash
#### 将.bash_profile 移动到新的用户目录并修改权限 ####
$ cp /home/postgres/.bash_profile /usr/local/pgsql/
$ chown postgres.postgres .bash_profile
#### 删除用户目录 ####
$ rm -rf postgres/
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 新建数据目录
$ mkdir /usr/local/pgsql/data
  • 1
  • 更改权限
$ chown postgres /usr/local/pgsql/data
  • 1
  • 切换到postgres 用户
$ su - postgres
  • 1

  - 初始化数据库

$ /usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data/
  • 1

  - 回到root 用户

$ exit
  • 1
  • 复制安装目录下的linux文件到/etc/init.d/
$ cd postgresql-9.4.1
$ cp contrib/start-scripts/linux /etc/init.d/postgresql
  • 1
  • 2

- 添加执行权限

$ chmod +x /etc/init.d/postgresql
  • 1
  • 启动数据库
$ service postgresql restart
  • 1

- 让数据库开机启动

$ chkconfig --add postgresql 
$ chkconfig postgresql on
  • 1
  • 2
  • 测试使用
$ su - postgres
$ createdb test
$ psql test
test=$ create table test(id int);
  • 1
  • 2
  • 3
  • 4


源码安装相关问题及解决方案

  • ./configure时,提示error: readline library not found  该情况,一般是未安装readline-devel,虽然提示中有建议使用 –without readline,但是装下又何妨,万一后面出点乱子,找个问题都难找,还是装一下吧。
yum install readline-devel
  • 1
  • 直接执行gmake install,默认安装在哪?
$ /usr/local/pgsql
  • 1
  • 执行postgresql命令、修改postgresql配置文件(postgresql.conf、pg_hba.conf),文件和目录在哪?
$ /usr/local/pgsql/data
  • 1
  • postgresql默认只允许本机访问,需要远程连接、外网访问,如何配置?  先配置监听地址
$ vi /usr/local/pgsql/data/postgresql.conf
#### 取消掉下面一行的前面的#注释,并将值改为* ####
$ listen_addresses = '*'
  • 1
  • 2
  • 3

再配置支持远程连接

$ vi /usr/local/pgsql/data/pg_hba.conf
#### 直接配置为不限制IP,即0.0.0.0,注意:/后面也必须为0!!! ####
$ 将 127.0.0.1/8 改为 0.0.0.0/0

come from:http://www.centoscn.com/image-text/install/2015/0407/5110.html
posted @ 2016-11-16 17:09  seasonzone  阅读(397)  评论(0编辑  收藏  举报