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)


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