Postgresql 9.5.0源码安装

来源:互联网 发布:java项目经验案例2017 编辑:程序博客网 时间:2024/05/18 03:08
  1. 下载PostgreSQL 源码包
    #wget http://ftp.postgresql.org/pub/source/v9.5.0/postgresql-9.5.0.tar.bz2

  2. 解压源码包
    # tar xjf postgresql-9.5.0.tar.bz2

  3. 进入解压后的目录
    # cd postgresql-9.5.0

  4. 查看INSTALL 文件
      INSTALL 文件中Short Version 部分解释了如何安装PostgreSQL 的命令,Requirements 部分描述了安装PostgreSQL 所依赖的lib,比较长,先configure 试一下,如果出现error,那么需要检查是否满足了Requirements 的要求。
    这里写图片描述

  5. 开始编译安装PostgreSQL 数据库。
    # ./configure
    *报错:
    configure: error: readline library not found
    If you have readline already installed, see config.log for details on the
    failure. It is possible the compiler isnt looking in the proper directory.
    Use –without-readline to disable readline support.
    解决:
    #yum install *readline**

  6. 再次configure:
    # ./configure
    configure 成功,无错误。
    这里写图片描述

  7. 执行gmake
    # gmake
    gmake 成功,Ready to install.
    这里写图片描述

  8. 执行gmake install
    # gmake install
    gmake install 成功
    这里写图片描述
    到这一步,PostgreSQL 源码编译安装完成,下面开始配置PostgreSQL.

  9. 设置环境变量
    # vi .bash_profile
    把 PATH=$PATH:$HOME/bin
    改成 PATH=$PATH:$HOME/bin:/usr/local/pgsql/bin
    保存退出。

  10. 让环境变量生效:
    # source .bash_profile

  11. 添加用户postgres
    # adduser postgres
    更改用户目录(可选操作)
    # vi /etc/passwd
    把 postgres:x:528:528::/home/postgres:/bin/bash
    改成 postgres:x:528:528::/usr/local/pgsql:/bin/bash

  12. 将.bash_profile 移动到新的用户目录并修改权限
    # cp /home/postgres/.bash_profile /usr/local/pgsql/
    # chown postgres.postgres /usr/local/pgsql/.bash_profile

  13. 删除用户目录:
    # rm -rf postgres/

  14. 初始化数据库
    14.1 新建数据目录
    # mkdir /usr/local/pgsql/data
    14.2 更改权限
    # chown postgres /usr/local/pgsql/data
    14.3 切换到postgres 用户
    # su - postgres
    14.4 init db
    $ /usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data/
    到这里数据的初始化就完成了。

  15. 系统服务
    15.1 回到root 用户
    $ exit
    15.2 复制安装目录下的linux文件到/etc/init.d/
    进入postgresql 的安装目录(即刚刚使用tar命令解压的目录)
    # cd postgresql-9.2.4
    # cp contrib/start-scripts/linux /etc/init.d/postgresql
    15.3 添加执行权限
    # chmod +x /etc/init.d/postgresql
    15.4 启动数据库
    #/etc/init.d/postgresql start
    #ps -ef | grep postgres
    15.5 让数据库开机启动
    # chkconfig –add postgresql
    # chkconfig postgresql on
    # chkconfig –list | grep postgres
    15.6 创建数据库操作的历史记录文件
    # touch /usr/local/pgsql/.pgsql_history
    #chown postgres:postgres /usr/local/pgsql/.pgsql_history

  16. 测试使用
    # su - postgres
    $ createdb test
    $ psql test
    test=# create table test(id int);
    test=# \dt
    这里写图片描述
    源码编译安装成功。

参考文献:
1、http://www.cnblogs.com/mchina/archive/2012/06/06/2539003.html
2、http://www.oschina.net/question/565065_66639

0 0
原创粉丝点击