1. 安裝環境
linux版本: CentOS release 6.2 (Final)
pg版本 : postgresql-9.5.0
2. pg數據庫下載地址
--http://www.postgresql.org/ftp/source/
3. 安裝依賴包
yum install -y perl-ExtUtils-Embed readline-devel zlib-devel pam-devel libxml2-devel libxslt-devel openldap-devel python-devel gcc-c++ openssl-devel cmake
4. 安裝postgres
1). 解壓壓縮包[root@oracle2 software]# tar jxvf postgresql-9.5.0.tar.bz22). 進入postgresql-9.5.0文件夾[root@oracle2 software]# cd postgresql-9.5.0[root@oracle2 postgresql-9.5.0]# lsaclocal.m4 configure contrib doc HISTORY Makefile srcconfig configure.in COPYRIGHT GNUmakefile.in INSTALL README3). 編譯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 postgresuseradd -m -g postgres -u 701 postgres
6. 建postgresql數據庫的數據主目錄
這個數據庫主目錄是隨實際情況而不同,這里我們的主目錄是在/home/postgres/data目錄下:mkdir datachown postgres:postgres data
7. 配置環境變量
vi .bash_profile 里面添加如下內容:export PGHOME=/opt/pgsqlexport PGDATA=/home/postgres/dataexport PATH=$PATH:$HOME/bin:$PGHOME/binalias 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 linux2) 復制linux文件到/etc/init.d目錄下,更名為postgresql#cp linux /etc/init.d/postgresql3)修改/etc/init.d/postgresql文件的兩個變量prefix設置為postgresql的安裝路徑:/opt/pgsql-9.1.2PGDATA設置為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
本文版權歸作者所有,歡迎轉載,但未經作者同意必須保留此段聲明,且在文章頁面明顯位置給出原文連接.