Postgresql數據庫的安裝指引


一、解壓數據庫































cd /usr/local/src linux






























tar -jxvf postgresql-8.4.14.tar.bz2


























































二、進入數據庫文件





























  cd postgresql-8.4.14



























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





































  (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*



























三、編譯&安裝































gmake

































gmake install



































































四、增長postgresql專用用戶


























  useradd postgres

































































五、切換postgres用戶以前,先創建數據目錄data並賦給postgres用戶













  mkdir /postgresql/data


























  chown postgres /usr/local/postgresql/data




















  su - postgres


































































六、初始化目錄數據





























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











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









































七、啓動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














八、再次啓動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




























































八、之後臺服務方式啓動以前,切換到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 &











































































九、數據庫的啓動與關閉



























 $ cd /usr/local/postgresql/bin























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

















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


















十、建立數據庫及鏈接數據庫

























/usr/local/pgsql/bin/createdb test






















/usr/local/pgsql/bin/psql test安全


























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



























容許遠程鏈接






























postgresql由於安全方面的考慮,默認狀況下只接受本機的鏈接。爲了管理的方便,咱們須要開通遠程鏈接。
修改data/postgresql.conf,增長:























122248753.png





































修改監聽端口:






























122349307.png





































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





















122439806.png





































而後重啓posgtres。




























修改配置後立刻生效不重啓:

























cd /usr/local/postgresql/bin

























pg_ctl reloaddom
































十二、把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 onsocket
























1三、在postgresql中建立用戶,並設置數據庫ide






















create database test owner test;























這樣就設置了一個數據庫叫test,而且它的擁有者是一個叫test的用戶
相關文章
相關標籤/搜索