CentOS下安裝postgresql 9.4

 

1、前言mysql

      PostgreSQL一般也簡稱Postgres,是一個關係型數據庫管理系統,適用於各類Linux操做系統、Windows、Solaris、BSD和Mac OS X。PostgreSQL遵循PostgreSQL許可,是一個開源軟件。PostgreSQL由PostgreSQL全球開發組開發,由極少數的公司志願組成並進行監督管理,這些公司有紅帽、EnterpriseDB等。linux

      PostgreSQL的知名度愈來愈大,這是理所固然的:它是如此可靠、高效。與傳統企業級關係型數據庫相比,PostgreSQL徹底基於社區驅動,有着豐富的工具和文檔,造成了一個完善的生態系統。sql

      目前搜索的大部分CentOS下安裝均是用於Centos6.X的部分命令已經有很大變化,本文主要記錄在Linux Centos 7.1下安裝PostgreSQL的過程。數據庫

2、安裝PostgreSQL源centos

CentOS 6.x 32bitbash

sudo rpm -Uvh http://yum.postgresql.org/9.4/redhat/rhel-6-i386/pgdg-centos94-9.4-1.noarch.rpm

CentOS 6.x 64bittcp

sudo rpm -Uvh http://yum.postgresql.org/9.4/redhat/rhel-6-x86_64/pgdg-centos94-9.4-1.noarch.rpm

CentOS 7 64bit工具

sudo rpm -Uvh http://yum.postgresql.org/9.4/redhat/rhel-7-x86_64/pgdg-centos94-9.4-1.noarch.rpm

      在添加源的步驟中並無太多的區別,主要是源的地址有必定的變化。post

3、執行安裝命令操作系統

 
sudo yum update
sudo yum install postgresql94-server postgresql94-contrib

4、驗證是否安裝成功

sudo rpm -aq| grep postgres

執行結果以下:

postgresql94-libs-9.4.1-1PGDG.rhel7.x86_64
postgresql94-server-9.4.1-1PGDG.rhel7.x86_64
postgresql94-9.4.1-1PGDG.rhel7.x86_64
postgresql94-contrib-9.4.1-1PGDG.rhel7.x86_64

5、初始化數據庫

CentOS 6.x 系統

sudo service postgresql-9.4 initdb

CentOS 7 系統

sudo /usr/pgsql-9.4/bin/postgresql94-setup initdb

在初始化數據庫時能夠指定參數 --PGDATA=「/data」,該參數是用於指明數據庫的數據文件的存放路徑,默認是在/var/lib/pgsql/9.4/data路徑下。

若是我在CentOS 7下執行 service postgresql-9.4 initdb 將會報以下問題

The service command supports only basic LSB actions (start, stop, restart, try-restart, reload, force-reload, status). For other actions, please try to use systemctl.

6、啓動服務並設置爲開機啓動

CentOS 6.x 系統

 
sudo service postgresql-9.4 start
sudo chkconfig postgresql-9.4 on

CentOS 7 系統

 
sudo systemctl enable postgresql-9.4
sudo systemctl start postgresql-9.4

7、開放防火牆端口

CentOS 6.x 系統

vi /etc/sysconfig/iptables

按下I進入輸入模式,在文件中加入一下語句

-A INPUT -m state --state NEW -m tcp -p tcp --dport 5432 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT

輸入完成後按ESC退出編輯模式,輸入:wq退出VI編輯界面。

重啓防火牆服務

sudo service iptables restart

CentOS 7 系統

 
sudo firewall-cmd --permanent --add-port=5432/tcp
sudo firewall-cmd --permanent --add-port=80/tcp
sudo firewall-cmd --reload

8、訪問PostgreSQL

su - postgres

輸出結果以下:

上一次登陸:一 5月 18 15:17:29 CST 2015pts/0 上
-bash-4.2$

輸入命令psql將看到PostgrSQL的版本信息。

psql (9.4.1)
輸入 "help" 來獲取幫助信息.

9、設置postgres用戶密碼

postgres=# \password postgres

以上操做基本完成整個PostgreSQL的安裝。

相關文章
相關標籤/搜索