Linux安裝PostgreSQL 9.4過程筆記,但願對你們有用。sql
1、前言數據庫
PostgreSQL一般也簡稱Postgres,是一個關係型數據庫管理系統,適用於各類Linux操做系統、Windows、Solaris、BSD和Mac OS X。PostgreSQL遵循PostgreSQL許可,是一個開源軟件。PostgreSQL由PostgreSQL全球開發組開發,由極少數的公司志願組成並進行監督管理,這些公司有紅帽、EnterpriseDB等。centos
PostgreSQL的知名度愈來愈大,這是理所固然的:它是如此可靠、高效。與傳統企業級關係型數據庫相比,PostgreSQL徹底基於社區驅動,有着豐富的工具和文檔,造成了一個完善的生態系統。bash
目前搜索的大部分CentOS下安裝均是用於Centos6.X的部分命令已經有很大變化,本文主要記錄在Linux Centos 7.1下安裝PostgreSQL的過程。tcp
2、安裝PostgreSQL源工具
CentOS 6.x 32bitpost
rpm -Uvh http://yum.postgresql.org/9.4/redhat/rhel-6-i386/pgdg-centos94-9.4-1.noarch.rpm操作系統
CentOS 6.x 64bit3d
rpm -Uvh http://yum.postgresql.org/9.4/redhat/rhel-6-x86_64/pgdg-centos94-9.4-1.noarch.rpmrest
CentOS 7 64bit
rpm -Uvh http://yum.postgresql.org/9.4/redhat/rhel-7-x86_64/pgdg-centos94-9.4-1.noarch.rpm
在添加源的步驟中並無太多的區別,主要是源的地址有必定的變化。
3、執行安裝命令
yum update
yum install postgresql94-server postgresql94-contrib
4、驗證是否安裝成功
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 系統
service postgresql-9.4 initdb
CentOS 7 系統
/usr/pgsql-9.4/bin/postgresql94-setup initdb
若是我在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 系統
service postgresql-9.4 start
chkconfig postgresql-9.4 on
CentOS 7 系統
systemctl enable postgresql-9.4
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編輯界面。
重啓防火牆服務
service iptables restart
CentOS 7 系統
firewall-cmd --permanent --add-port=5432/tcp
firewall-cmd --permanent --add-port=80/tcp
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的安裝。