PostgreSQL 9.3.2 源码安装

PostgreSQL 是一种非常出色的开源关系数据库,但由于种种原因,知名度与MySQL相差不少,特别是在国内,但这两年,Postgres进步很大,特别是从8.3以后,速度有了大的提升以及加了很多feature进来。



1.下载源码(最新的开发版本已经到9.4了,有兴趣的同学可以一试)

postgresql

version 9.3.2

link:

http://ftp.postgresql.org/pub/source/v9.3.2/postgresql-9.3.2.tar.bz2

size :16M


2.检查依赖的库和头文件,这里强调一下readline,由于OS为centos 6.5的base +尽可能全的devel package 。所以readline相关的已经安装了,readline是一个非常cool的,可以使在psql客户端中读历史命令。


3.编译安装源码

./configure --prefix=/opt/Postgres/V93

make && make install

mkdir /pgdata /pglog


4.创建组和用户

grouadd -g 1000 postgres

useradd -g 1000 -u 1000 postgres


5. 创建实例所需的目录

mkdir /pgdata

mkdir /pglog

chown postgres:postgres /pgdata

chown postgres:postgres /pglog


6. 定制环境变量

vi .bash_profile

PATH=/opt/Postgres/V93/bin:$PATH

PGDATA=/pgdata

export PATH PGDATA


PGDATA就是数据库的数据目录,如果不在环境变量里指定,也可以在pg_ctl的启动命令里加上-D 参数(关于postgresql的启动,有几种方法,至少不比茴香豆的茴少 :-) ,以后的文章会单独介绍)

7. 创建数据库

su 到postgres用户,initdb


8.启动数据库

pg_ctl start

9验证

psf -ef|grep postgres

postgres 30035     1  0 14:37 pts/0    00:00:00 /opt/Postgres/V93/bin/postgres

postgres 30037 30035  0 14:37 ?        00:00:00 postgres: checkpointer process

postgres 30038 30035  0 14:37 ?        00:00:00 postgres: writer process

postgres 30039 30035  0 14:37 ?        00:00:00 postgres: wal writer process

postgres 30040 30035  0 14:37 ?        00:00:00 postgres: autovacuum launcher process

postgres 30041 30035  0 14:37 ?        00:00:00 postgres: stats collector process

postgres 30044 30004  0 14:38 pts/0    00:00:00 psql

postgres 30060 30035  0 14:42 ?        00:00:00 postgres: postgres postgres [local] idle


以上是postgres启动最基本,也是最重要的几个进程


psql -p 5432 postgres

(其实-p 与后面的postgres都可以省略,因为我们都是用默认的配置,所以psql默认就是用5432端口,而数据库如果默认也是postgres)


postgres=# select version();

                                               version

--------------------------------------------------------------------------------------------------------

PostgreSQL 9.3.2 on i686-pc-linux-gnu, compiled by gcc (GCC) 4.1.2 20080704 (Red Hat 4.1.2-46), 32-bit

(1 row)


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章