Postgresql數據庫的安裝指引


1、解壓數據庫































cd /usr/local/src






























tar -jxvf postgresql-8.4.14.tar.bz2


























































2、進入數據庫文件





























  cd postgresql-8.4.14



























  將數據庫安裝指定到特定的目錄postgresql





































  (postgresql文件夾是新建)






  ./configure --prefix=/usr/local/postgresql/























































有可能出現以下報錯提示找不到readline,但readline已經安裝,說明缺少了readline-devel可通過yum安裝

A、配置/etc/yum.repos.d/rhel-debuginfo.repo (注意linux版本不一樣配置也會有所不同)





[base]

































name=Server Local Sources


























baseurl=file:///media/rhel/Server























enable=1
































gpcheck=1
































gpgkey=file:///media/rhel/RPM-GPG-KEY-redhat-release















B、掛載光驅的系統盤






























  新建一個目錄用於掛載點:mkdir /media/rhel



















   mount /dev/cdrom /media/rhel























C、驗證掛載是否成功查看df -Th
























D、yum安裝相關軟件




























yum makecache 清理緩存


























yum install readline -devel

























  yum install read*



























3、編譯&安裝































gmake

































gmake install



































































4、增加postgresql專用用戶


























  useradd postgres

































































5、切換postgres用戶之前,先建立數據目錄data並賦給postgres用戶













  mkdir /postgresql/data


























  chown postgres /usr/local/postgresql/data




















  su - postgres


































































6、初始化目錄數據





























/usr/local/postgresql/bin/initdb -D /usr/local/postgresql/data











/usr/local/postgresql/bin/postgres -D /usr/local/postgresql/data >logfile 2>&1 &









































7、啓動postgresql數據庫



























/usr/local/postgresql/bin/postgres -D /usr/local/postgresql/data










啓動報如下錯誤






























LOG: could not translate host name "localhost", service "5432" to address: Name or service not known
WARNING: could not create listen socket for "localhost"














FATAL: could not create any TCP/IP sockets



















解決辦法是:修改/etc/hosts

























增加了  127.0.0.1       localhost localhost.localdomain














8、再次啓動postgresql



























/usr/local/postgresql/bin/postgres -D /usr/local/postgresql/data  













出現如下提示,說明數據庫安裝成功
























LOG:database system was shut down at 2012-12-10 10:22:40 CST












LOG:database system is ready to accept connections
















LOG:autovacuum launcher started




























































8、以後臺服務方式啓動之前,切換到root在/usr/local/postgresql/data/創建logfile文件,並賦用戶postgres
$su - root






























touch /usr/local/postgresql/data/logfile



















chown postgres logfile


























/usr/local/postgresql/bin/postgres -D /usr/local/postgresql/data >logfile 2>&1 &











































































9、數據庫的啓動與關閉



























 $ cd /usr/local/postgresql/bin























  ./pg_ctl -D /usr/local/postgresql/data start

















  ./pg_ctl -D /usr/local/postgresql/data stop


















10、創建數據庫及連接數據庫

























/usr/local/pgsql/bin/createdb test






















/usr/local/pgsql/bin/psql test


























11、數據庫的一些相關配置



























允許遠程連接






























postgresql因爲安全方面的考慮,默認情況下只接受本機的連接。爲了管理的方便,我們需要開通遠程連接。
修改data/postgresql.conf,增加:























122248753.png





































修改監聽端口:






























122349307.png





































修改data/pg_hba.conf,增加md5那一行:





















122439806.png





































然後重啓posgtres。




























修改配置後馬上生效不重啓:

























cd /usr/local/postgresql/bin

























pg_ctl reload
































12、把Postgres服務設置爲自動啓動























進入postgresql的源代碼解壓目錄:cd /usr/local/src/postgresql-8.4.14










#cp contrib/start-scripts/linux /etc/init.d/postgresql















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























#cd /etc/init.d/





























#chkconfig --add postgresql

























#chkconfig postgresql --level 345 on
























13、在postgresql中創建用戶,並設置數據庫






















create database test owner test;























這樣就設置了一個數據庫叫test,並且它的擁有者是一個叫test的用戶













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