星空网 > 软件开发 > 数据库

Linux下的PostgreSQL简单安装手册

1. 安装环境

 

    linux版本: CentOS release 6.2 (Final)
    pg版本    : postgresql-9.5.0
 




2. pg数据库下载地址

 

  --http://www.postgresql.org/ftp/source/

 

3. 安装依赖包

 

>yum install gcc*>yum  install readline-devel* 





 





4. 安装postgres
 
1). 解压压缩包
[root@oracle2 software]# tar jxvf postgresql-9.5.0.tar.bz2 
 
2). 进入postgresql-9.5.0文件夹 
[root@oracle2 software]# cd postgresql-9.5.0
[root@oracle2 postgresql-9.5.0]# ls
aclocal.m4  configure     contrib    doc             HISTORY  Makefile  src
config      configure.in  COPYRIGHT  GNUmakefile.in  INSTALL  README
 
3). 编译postgresql源码
[root@oracle2 postgresql-9.5.0]# ./configure --prefix=/opt/pgsql          --安装路径

表3-3 PostgreSQL配置脚本选项


选项描述
–prefix=prefix安装到prefix指向的目录;默认为/usr/local/pgsql
–bindir=dir安装应用程序到dir;默认为prefix/bin
–with-docdir=dir安装文档到dir;默认为prefix/doc
–with-pgport=port设置默认的服务器端网络连接服务TCP端口号
–with-tcl为服务端提供Tcl存储过程支持
–with-perl为服务端提供Perl存储过程支持
–with-python为服务端提供Python存储过程支持

 
[root@oracle2 postgresql-9.5.0]# make

 
[root@oracle2 postgresql-9.5.0]# make install

 
到达这步;会提示你“PostgreSQL installation complete.” OK
 






5. 创建用户postgres 

 





groupadd -g 701 postgres    
useradd -m -g postgres -u 701 postgres 


 
6. 建postgresql数据库的数据主目录
 





这个数据库主目录是随实际情况而不同,这里我们的主目录是在/home/postgres/data目录下:
mkdir data
chown postgres:postgres data

 

7. 配置环境变量

 





vi .bash_profile  里面添加如下内容:
export PGHOME=/opt/pgsql

export PGDATA=/home/postgres/data              

export PATH=$PATH:$HOME/bin:$PGHOME/bin

alias pg_start="pg_ctl start -l /home/postgres/log/pg_server.log"

alias pg_stop="pg_ctl stop -l /home/postgres/log/pg_server.log"

 
 






8. 使用initdb初使用化数据库
 
initdb
 
 

9.  配置服务
 
$ vi postgresql.conf
修改内容
listen_addresses = 'localhost,127.0.0.1,192.168.8.21'
port = 5432
password_encryption = on
#listen_addresses = 'localhost,127.0.0.1,168.8.21''可以写成 listen_addresses = '*' 监听所有的网络
$ vi pg_hba.conf
找到最下面这一行 ,这样局域网的人才能访问
# IPv4 local connections:
host all all 127.0.0.1/32 trusthost all all 192.168.1.0/16 trust
 



10. 设置PostgreSQL开机自启动

 


PostgreSQL的开机自启动脚本位于PostgreSQL源码目录的contrib/start-scripts路径下
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的数据目录路径:

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

#chkconfig --add postgresql

11. 查看资料

   




        --http://www.cnblogs.com/marsprj/archive/2013/02/08/2893519.html
        --http://postgres.cn/index.php/home
 
作者 : li0924

时间 : 2016-01-04

本文版权归作者所有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接.











原标题:Linux下的PostgreSQL简单安装手册

关键词:linux

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

fba香港:https://www.goluckyvip.com/tag/20159.html
新品开发方式:https://www.goluckyvip.com/tag/2016.html
fba箱唛:https://www.goluckyvip.com/tag/20160.html
fba箱重:https://www.goluckyvip.com/tag/20161.html
fba箱子:https://www.goluckyvip.com/tag/20162.html
fba箱子标签:https://www.goluckyvip.com/tag/20163.html
无锡旅游景点竹海 - 无锡的竹海:https://www.vstour.cn/a/363178.html
5月贾汪好玩的地方 贾汪哪有好玩的地方:https://www.vstour.cn/a/363179.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流