CentOS6.5+PostgreSQL9.5安装参考

来源:互联网 发布:福建金税三期软件下载 编辑:程序博客网 时间:2024/06/06 14:10

1基本需求:centos6.5上安装postgres9.5

主机

postgres9.5安装目录

pg安装前源码及相关包

CentOS6.5

软件:/pgres;数据库实例:/pgres/data

/pgsolf


2安装过程

2.1安装操作系统(略)

2.2创建文件夹/pgsolf,拷贝以下文件(root操作)

[root@localhost]# mkdir  /pgsolf

ncurses-devel-5.7-3.20090208.el6.x86_64.rpm

readline-devel-6.0-4.el6.x86_64.rpm

zlib-devel-1.2.3-29.el6.x86_64.rpm

postgresql-9.5beta1.tar.gz

解压数据库包

tar  -xvzf   postgresql-9.5beta1.tar.gz

2.3安装依赖rpm包(一般缺少以上几个)

rpm  -ivh  *.rpm

2.4创建pg数据库安装目录

mkdir  -R   /pgres

2.5编译安装(root操作)

 [root@localhost pgsolf]#cd   /pgsolf/postgresql-9.5beta1

 [root@localhostpostgresql-9.5beta1]# ls

aclocal.m4 config.status  contrib    GNUmakefile     INSTALL  src

config     configure      COPYRIGHT  GNUmakefile.in  Makefile

config.log configure.in   doc        HISTORY         README

指定安装目录:

 [root@localhostpostgresql-9.5beta1] ./configure  --prefix=/pgres

编译:[root@localhostpostgresql-9.5beta1]# make

安装: [root@localhostpostgresql-9.5beta1]# make  install

创建用户设置密码:

 [root@localhostpostgresql-9.5beta1]useradd  postgres

 [root@localhostpostgresql-9.5beta1] passwd  postgres

创建数据库存放目录与设置权限

[root@localhost pgres]# mkdir -p /pgres/data

[root@localhost pgres]# chown  -R postgres:postgres  /pgres/data

 

2.6初始化实例(postgres操作)

[root@localhost bin]# su -  postgres

[root@localhost bin]#cd /pgres/bin

[postgres@localhost ~]$ ./initdb  -D  /pgres/data


初步使用:

启动数据库:./pg_ctl -D /pgres/data  start

查看postgres进程:#ps -ef | grep postgres

停止postgresql数据库: ./pg_ctl -D /pgres/data stop -m fast

创建用户数据库

[postgres@localhost bin]$ ./createdb  test

[postgres@localhost bin]$ ./psql  test

Type "help" for help.

test=#

 

2.7设置postgres环境变量(方便操作)

切换用户:su  -  postgres

修改.bash_profile文件完成后保存退出(Esc>:>wq)

#vi /home/postgres/.bash_profile

export PGHOME=/pgres

export PGDATA=/pgres/data

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

export PATH

#source /home/postgres/.bash_profile

查看环境变量配置:echo $PGHOME

2.8设置pg服务为linux服务并开机自启(root操作)

pg的开机自启动脚本位于PostgreSQL源码目录的contrib/start-scripts路径下     //linux文件即为linux系统上的启动脚本


1) 复制linux文件到/etc/init.d目录下并更名

#cp linux/etc/init.d/postgresql

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

prefix设置为pg软件的安装路径: /pgres

PGDATA设置为pg的数据目录路径:/pgres/data

3)修改/etc/init.d/postgresql文件mod

#chmod a+x  /etc/init.d/postgresql

4)root执行测试

#service postgresql start

#service postgresql stop


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

#chkconfig --add postgresql

 

0 0
原创粉丝点击