標籤:postgresql 安裝
一、簡介
PostgreSQL是目前世界上最豐富的資料類型的支援,其中有些資料類型可以說連商務資料庫都不具備, 比如 IP 類型和幾何類型等;其次,PostgreSQL 是全功能的自由軟體資料庫,很長時間以來,PostgreSQL 是唯一支援事務、子查詢、多版本並行控制系統(MVCC)、資料完整性檢查等特性的唯一的一種自由軟體的資料庫管理系統。
二、Linux下安裝
1) 環境:RedHat Enterprise 6.5 x64(2.6.32-431.el6.x86_64)
PostgreSQL 9.4.4
SeLinux=disabled
防火牆關閉
2) 下載安裝包:http://www.postgresql.org/download/,選擇Redhat
650) this.width=650;" src="http://s3.51cto.com/wyfs02/M01/74/12/wKiom1YSgRixDZtWAAD9f6y-XpY077.jpg" title="1.png" width="420" height="104" border="0" hspace="0" vspace="0" style="width:420px;height:104px;" alt="wKiom1YSgRixDZtWAAD9f6y-XpY077.jpg" />
3) 將下載的包上傳到Linux伺服器
[[email protected]]# lspostgresql94-9.4.4-1PGDG.rhel6.x86_64.rpm //PostgreSQL用戶端程式postgresql94-contrib-9.4.4-1PGDG.rhel6.x86_64.rpm //PostgreSQL第三方的支援庫postgresql94-libs-9.4.4-1PGDG.rhel6.x86_64.rpm //PostgreSQL庫檔案postgresql94-server-9.4.4-1PGDG.rhel6.x86_64.rpm //PostgreSQL Server程式
4)按照以下順序依次安裝
[[email protected] software]# rpm -ivh postgresql94-libs-9.4.4-1PGDG.rhel6.x86_64.rpmwarning: postgresql94-libs-9.4.4-1PGDG.rhel6.x86_64.rpm: Header V4 DSA/SHA1 Signature, key ID 442df0f8: NOKEYPreparing... ########################################### [100%] 1:postgresql94-libs ########################################### [100%][[email protected] software]# rpm -ivh postgresql94-9.4.4-1PGDG.rhel6.x86_64.rpmwarning: postgresql94-9.4.4-1PGDG.rhel6.x86_64.rpm: Header V4 DSA/SHA1 Signature, key ID 442df0f8: NOKEYPreparing... ########################################### [100%] 1:postgresql94 ########################################### [100%][[email protected] software]# rpm -ivh postgresql94-server-9.4.4-1PGDG.rhel6.x86_64.rpmwarning: postgresql94-server-9.4.4-1PGDG.rhel6.x86_64.rpm: Header V4 DSA/SHA1 Signature, key ID 442df0f8: NOKEYPreparing... ########################################### [100%] 1:postgresql94-server ########################################### [100%][[email protected] software]# rpm -ivh postgresql94-contrib-9.4.4-1PGDG.rhel6.x86_64.rpmwarning: postgresql94-contrib-9.4.4-1PGDG.rhel6.x86_64.rpm: Header V4 DSA/SHA1 Signature, key ID 442df0f8: NOKEYPreparing... ########################################### [100%] 1:postgresql94-contrib ########################################### [100%]
5)啟動PostgreSQL資料庫
在第一次啟動PostgreSQL資料庫服務時,提示需要先初始化
[[email protected] software]# /etc/init.d/postgresql-9.4 start/var/lib/pgsql/9.4/data is missing. Use "service postgresql-9.4 initdb" to initialize the cluster first. [FAILED]
#初始化資料庫:
[[email protected]]# service postgresql-9.4 initdbInitializingdatabase: [ OK ]
#啟動服務:
[[email protected]]# service postgresql-9.4 startStartingpostgresql-9.4 service: [ OK ]
#將服務加入啟動列表中
[[email protected]]# chkconfig postgresql-9.4 on
#預設安裝完PostgreSQL之後,其賬戶為postgres,修改其密碼:
[[email protected]]# su postgresbash-4.1$ psqlpsql (9.4.4)Type"help" for help. postgres=# alteruser postgres with password ‘postgres‘;ALTER ROLEpostgres=# select *from pg_shadow; usename | usesysid | usecreatedb | usesuper | usecatupd | userepl | passwd | valuntil | useconfig----------+----------+-------------+----------+-----------+---------+-------------------------------------+----------+----------- postgres | 10 | t | t | t | t | md53175bce1d3201d16594cebf9d7eb3f9d| |(1 row)
6)測試資料庫
postgres=# createdatabase testdb;CREATE DATABASEpostgres=# \ctestdb;You are nowconnected to database "testdb" as user "postgres".testdb=# createtable test(id integer,name text);CREATE TABLEtestdb=# insert intotest(id,name) values(111,‘alex‘);INSERT 0 1testdb=# select *from test; id |name-----+------ 111 | alex(1 row)
三、Windows下安裝
1)環境:Windows Server 2008 Enterprise x64
2)下載安裝包:http://www.postgresql.org/download/,選擇Windows
3)將安裝包上傳到遠程Windows伺服器上
650) this.width=650;" src="http://s3.51cto.com/wyfs02/M01/74/10/wKioL1YShB2iP-YfAAAeRycbMeE767.jpg" title="15.png" alt="wKioL1YShB2iP-YfAAAeRycbMeE767.jpg" />
#右鍵-“以管理員方式運行”,開始安裝
650) this.width=650;" src="http://s3.51cto.com/wyfs02/M02/74/10/wKioL1YShGaDhhsKAADpiKaKU4A345.jpg" title="3.png" width="456" height="348" border="0" hspace="0" vspace="0" style="width:456px;height:348px;" alt="wKioL1YShGaDhhsKAADpiKaKU4A345.jpg" />
#選擇軟體安裝目錄,這裡我是預設
650) this.width=650;" src="http://s3.51cto.com/wyfs02/M00/74/13/wKiom1YShJCi-25BAACbtDGyz2A269.jpg" title="4.png" width="456" height="351" border="0" hspace="0" vspace="0" style="width:456px;height:351px;" alt="wKiom1YShJCi-25BAACbtDGyz2A269.jpg" />
#選擇資料存放目錄,因為我是用來學習,所以預設,現實中要根據需要單獨建立資料檔案夾
650) this.width=650;" src="http://s3.51cto.com/wyfs02/M00/74/10/wKioL1YSg3TQwBvaAACU63bn7Vw169.jpg" style="width:456px;height:348px;" title="5.png" width="456" height="348" border="0" hspace="0" vspace="0" alt="wKioL1YSg3TQwBvaAACU63bn7Vw169.jpg" />
#設定資料庫預設賬戶postgres的密碼
650) this.width=650;" src="http://s3.51cto.com/wyfs02/M01/74/12/wKiom1YSg2HCQMROAACbbGUHcfY044.jpg" style="width:456px;height:348px;" title="6.png" width="456" height="348" border="0" hspace="0" vspace="0" alt="wKiom1YSg2HCQMROAACbbGUHcfY044.jpg" />
#設定連接埠號碼,PostgreSQL資料庫預設連接埠號碼是5432,可以根據需要進行修改,這裡預設
650) this.width=650;" src="http://s3.51cto.com/wyfs02/M01/74/10/wKioL1YSg3SQ9fxFAACA04knzN0944.jpg" style="width:456px;height:351px;" title="7.png" width="456" height="351" border="0" hspace="0" vspace="0" alt="wKioL1YSg3SQ9fxFAACA04knzN0944.jpg" />
#選擇語言,為防止以後出現不必要的錯誤,我這裡選擇English:UnitedState
650) this.width=650;" src="http://s3.51cto.com/wyfs02/M02/74/12/wKiom1YSg2HiMCvfAACOwxafHyc756.jpg" style="width:456px;height:345px;" title="8.png" width="456" height="345" border="0" hspace="0" vspace="0" alt="wKiom1YSg2HiMCvfAACOwxafHyc756.jpg" />
#開始進行安裝配置
650) this.width=650;" src="http://s3.51cto.com/wyfs02/M02/74/10/wKioL1YSg3Wy9KPKAACBgTYGJqQ004.jpg" style="width:456px;height:351px;" title="9.png" width="456" height="351" border="0" hspace="0" vspace="0" alt="wKioL1YSg3Wy9KPKAACBgTYGJqQ004.jpg" />
650) this.width=650;" src="http://s3.51cto.com/wyfs02/M00/74/12/wKiom1YSg2LzCw-SAACqN2UE5eo660.jpg" style="width:456px;height:351px;" title="10.png" width="456" height="351" border="0" hspace="0" vspace="0" alt="wKiom1YSg2LzCw-SAACqN2UE5eo660.jpg" />
#安裝完成,詢問是否安裝Stack Builder,可以選擇不安裝,這個是用來下載安裝一些額外的工具的
650) this.width=650;" src="http://s3.51cto.com/wyfs02/M00/74/10/wKioL1YSg3bwgJEMAAEzGj6rpBc717.jpg" style="width:456px;height:351px;" title="11.png" width="456" height="351" border="0" hspace="0" vspace="0" alt="wKioL1YSg3bwgJEMAAEzGj6rpBc717.jpg" />
#安裝完成後的目錄如下:
650) this.width=650;" src="http://s3.51cto.com/wyfs02/M01/74/12/wKiom1YSg2TRtDnbAACuUxnvnsA516.jpg" style="width:138px;height:242px;" title="12.png" width="138" height="242" border="0" hspace="0" vspace="0" alt="wKiom1YSg2TRtDnbAACuUxnvnsA516.jpg" />
Application Stacker Builder:用來下載安裝額外的工具,以後用到會介紹
pgAdmin III:第三方的PostgreSQL串連工具
SQL Shell(psql):psql訪問工具,也是一種工具
4)測試資料庫,開啟SQL Sell工具
650) this.width=650;" src="http://s3.51cto.com/wyfs02/M01/74/10/wKioL1YSg3fCn2FaAAE-3PfrRRA587.jpg" style="width:465px;height:298px;" title="13.png" width="465" height="298" border="0" hspace="0" vspace="0" alt="wKioL1YSg3fCn2FaAAE-3PfrRRA587.jpg" />
其中Server為本地,可忽略
Database:為需要串連的資料庫名稱
Port:連接埠號碼,如果安裝的時候修改過,就要使用修改之後的連接埠
Username:預設postgres
使用者postgres的口令:安裝的時候設定過
650) this.width=650;" src="http://s3.51cto.com/wyfs02/M02/74/12/wKiom1YSg2TAXxgXAAMtlXTlOIY236.jpg" style="width:556px;height:227px;" title="14.png" width="556" height="227" border="0" hspace="0" vspace="0" alt="wKiom1YSg2TAXxgXAAMtlXTlOIY236.jpg" />
OK,接下來開啟pgAdmin III,可以看到剛剛建立的資料庫及表
本文出自 “鷹之眼” 部落格,請務必保留此出處http://eagle2014.blog.51cto.com/7992740/1700303
【PostgreSQL學習之旅】第一篇:Linux和Windows下安裝PostgreSQL9.4