首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 其他教程 > 操作系统 >

linux 停postgresql 源码包安装

2013-10-27 
linux 下postgresql 源码包安装下载地址 postgresql 官网 http://www.postgresql.org/ftp/source/v9.3.1/

linux 下postgresql 源码包安装

下载地址 postgresql 官网 http://www.postgresql.org/ftp/source/v9.3.1/  这是暂时的最新版本

0.编译环境

  • Linux: CentOS 5.5
  • gcc: 4.1.2

    1. 安装PostgreSQL

    1) 解压postgresql-9.1.7.tar.bz2

    #tar jxvf postgresql-9.1.7.tar.bz2

    linux 停postgresql 源码包安装 

    2) 进入解压后的postgresql-9.1.7目录

    #cd postgresql-9.1.7

    linux 停postgresql 源码包安装

    3) 编译postgresql源码

    #./configure --prefix=/opt/pgsql-9.1.7

    linux 停postgresql 源码包安装

     #make

    linux 停postgresql 源码包安装

    #make install

    linux 停postgresql 源码包安装

    至此,完成postgresql的安装。进入/opt/pgsql-9.1.7目录可以看到安装后的postgresql的文件。

    #ls /opt/pgsql-9.1.7

    linux 停postgresql 源码包安装

    2.创建postgresql数据库

    1) 创建postgres用户

    #useradd postgres

    修改postgres密码

    #passwd postgres

    linux 停postgresql 源码包安装

    2) 设置postgres用户的环境变量

    切换到postgres用户

    #su - postgres

    linux 停postgresql 源码包安装

    进入postgres的主目录

    #cd ~

    linux 停postgresql 源码包安装

    编辑~/.bash_profile文件

    #vi ~/.bash_profile

    设置以下的环境变量

    export PGHOME=/opt/pgsql-9.1.7

    export PGDATA=~/data

    linux 停postgresql 源码包安装

    保存,退出vi。执行以下命令,使环境变量生效

    #source ~/.bash_profile

    linux 停postgresql 源码包安装

    3) 初始化postgres数据库

    #initdb

    linux 停postgresql 源码包安装

    至此,完成postgres数据库的初始化。

    4) 启动postgres数据库实例

    #pg_ctl start

    linux 停postgresql 源码包安装

    可以看到postgresql数据库实例已经启动,通过下面的命令可以查看系统中运行的postgres进程

    #ps -ef | grep postgres

    linux 停postgresql 源码包安装

    5) 连接postgresql数据库

    #psql -h 127.0.0.1 -d postgres -U postgres

    linux 停postgresql 源码包安装

    6) 停止postgresql数据库实例

    #pg_ctl stop

    #ps -ef |  grep postgres

    linux 停postgresql 源码包安装

    可以看到已经没有postgres进程

    3. 设置PostgreSQL开机自启动

    PostgreSQL的开机自启动脚本位于PostgreSQL源码目录的contrib/start-scripts路径下

    linux 停postgresql 源码包安装

    linux文件即为linux系统上的启动脚本

    1)修改linux文件属性,添加X属性

    #chmod a+x linux

    2) 复制linux文件到/etc/init.d目录下,更名为postgresql

    #cp linux /etc/init.d/postgresql

    3)修改/etc/init.d/postgresql文件的两个变量

    prefix设置为postgresql的安装路径:/opt/pgsql-9.1.2

    PGDATA设置为postgresql的数据目录路径:

    linux 停postgresql 源码包安装

    4) 执行service postgresql start,就可以启动PostgreSQL服务

    #service postgresql start

     linux 停postgresql 源码包安装

    5)设置postgresql服务开机自启动

    #chkconfig --add postgresql

    执行上面的命令,就可以实现postgresql服务的开机自启动。

热点排行