CentOS 安裝PostgreSQL 9.1

來源:互聯網
上載者:User

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

PostgreSQL的知名度越來越大,這是理所當然的:它是如此可靠、高效。與傳統企業級關係型資料庫相比,PostgreSQL完全基於社區驅動,有著豐富的工具和文檔,形成了一個完善的生態系統。

下面記錄的是CentOS上安裝PostgreSQL 9.1的過程:

1.添加PosgreSQL Yum Repository,訪問http://yum.pgrpms.org/reporpms/repoview/letter_p.group.html,下載並安裝和當前系統對應的rpm檔案。

[root@SNDA-192-168-15-161 src]# wget http://yum.pgrpms.org/9.1/redhat/rhel-6-x86_64/pgdg-centos91-9.1-4.noarch.rpm
--2012-08-25 16:56:19--  http://yum.pgrpms.org/9.1/redhat/rhel-6-x86_64/pgdg-centos91-9.1-4.noarch.rpm
Resolving yum.pgrpms.org... 98.129.198.114
Connecting to yum.pgrpms.org|98.129.198.114|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 5124 (5.0K) [application/x-redhat-package-manager]
Saving to: “pgdg-centos91-9.1-4.noarch.rpmâ€

100%[======================================>] 5,124       18.7K/s   in 0.3s

2012-08-25 16:56:19 (18.7 KB/s) - “pgdg-centos91-9.1-4.noarch.rpmâ€

[root@SNDA-192-168-15-161 src]# ls -l
total 17644
drwxr-xr-x  9 1001 1001     4096 Aug 18 19:47 nginx-1.2.1
-rw-r--r--  1 root root   718161 Jun  5 22:10 nginx-1.2.1.tar.gz
drwxr-xr-x  8 root root     4096 Aug 18 19:44 nginx_tcp_proxy_module
-rw-r--r--  1 root root     4164 Dec 19  2011 nodejs-stable-release.noarch.rpm
-rw-r--r--  1 root root  1484480 Aug 18 21:37 node-v0.9.0.tar.gz
drwxr-xr-x  7 1169 1169     4096 Aug 18 20:11 pcre-8.20
drwxr-xr-x  8 1169 1169    12288 Aug 18 20:14 pcre-8.30
-rw-r--r--  1 root root  1635262 Aug 18 20:13 pcre-8.30.tar.gz
-rw-r--r--  1 root root     5124 Sep 26  2011 pgdg-centos91-9.1-4.noarch.rpm
drwxr-x--- 18 1000 1002     4096 Aug 18 20:58 Python-2.7.3
-rw-r--r--  1 root root 14135620 Apr 10 07:28 Python-2.7.3.tgz
-rw-r--r--  1 root root      539 Aug 18 21:37 wget-log
[root@SNDA-192-168-15-161 src]# rpm  -Uvh pgdg-centos91-9.1-4.noarch.rpm
warning: pgdg-centos91-9.1-4.noarch.rpm: Header V4 DSA/SHA1 Signature, key ID 442df0f8: NOKEY
Preparing...                ########################################### [100%]
   1:pgdg-centos91          ########################################### [100%]

修改原始的yum倉庫配置,在[base]和[updates]部分的尾部追加exclude=postgresql*用以取消從預設倉庫安裝和更新PostgreSQL。
[root@SNDA-192-168-15-161 src]# cd /etc/yum.repos.d
[root@SNDA-192-168-15-161 yum.repos.d]# vi CentOS-Base.repo

安裝或者升級postgresql-libs
[root@SNDA-192-168-15-161 yum.repos.d]# yum upgrade postgresql-libs
Loaded plugins: fastestmirror, security
Loading mirror speeds from cached hostfile
* base: mirrors.grandcloud.cn
* extras: mirrors.grandcloud.cn
* updates: mirrors.grandcloud.cn
base                                                     | 3.7 kB     00:00
extras                                                   | 3.0 kB     00:00
nodejs-stable                                            | 2.9 kB     00:00
pgdg91                                                   | 2.8 kB     00:00
pgdg91/primary_db                                        | 119 kB     00:01
updates                                                  | 3.5 kB     00:00
updates/primary_db                                       | 2.3 MB     00:09
Setting up Upgrade Process
No Match for argument: postgresql-libs
No package postgresql-libs available.
No Packages marked for Update

安裝PostgreSQL Server
[root@SNDA-192-168-15-161 yum.repos.d]# yum install postgresql91-server
Loaded plugins: fastestmirror, security
Loading mirror speeds from cached hostfile
* base: mirrors.grandcloud.cn
* extras: mirrors.grandcloud.cn
* updates: mirrors.grandcloud.cn
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package postgresql91-server.x86_64 0:9.1.5-1PGDG.rhel6 will be installed
--> Processing Dependency: postgresql91 = 9.1.5-1PGDG.rhel6 for package: postgresql91-server-9.1.5-1PGDG.rhel6.x86_64
--> Processing Dependency: libpq.so.5()(64bit) for package: postgresql91-server-9.1.5-1PGDG.rhel6.x86_64
--> Running transaction check
---> Package postgresql91.x86_64 0:9.1.5-1PGDG.rhel6 will be installed
---> Package postgresql91-libs.x86_64 0:9.1.5-1PGDG.rhel6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
Package                  Arch        Version                 Repository   Size
================================================================================
Installing:
postgresql91-server      x86_64      9.1.5-1PGDG.rhel6       pgdg91      3.6 M
Installing for dependencies:
postgresql91             x86_64      9.1.5-1PGDG.rhel6       pgdg91      990 k
postgresql91-libs        x86_64      9.1.5-1PGDG.rhel6       pgdg91      188 k

Transaction Summary
================================================================================
Install       3 Package(s)

Total download size: 4.7 M
Installed size: 20 M
Is this ok [y/N]: y
Downloading Packages:
(1/3): postgresql91-9.1.5-1PGDG.rhel6.x86_64.rpm         | 990 kB     00:06
(2/3): postgresql91-libs-9.1.5-1PGDG.rhel6.x86_64.rpm    | 188 kB     00:02
(3/3): postgresql91-server-9.1.5-1PGDG.rhel6.x86_64.rpm  | 3.6 MB     00:43
--------------------------------------------------------------------------------
Total                                            90 kB/s | 4.7 MB     00:54
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Warning: RPMDB altered outside of yum.
  Installing : postgresql91-libs-9.1.5-1PGDG.rhel6.x86_64                   1/3
  Installing : postgresql91-9.1.5-1PGDG.rhel6.x86_64                        2/3
  Installing : postgresql91-server-9.1.5-1PGDG.rhel6.x86_64                 3/3
  Verifying  : postgresql91-libs-9.1.5-1PGDG.rhel6.x86_64                   1/3
  Verifying  : postgresql91-server-9.1.5-1PGDG.rhel6.x86_64                 2/3
  Verifying  : postgresql91-9.1.5-1PGDG.rhel6.x86_64                        3/3

Installed:
  postgresql91-server.x86_64 0:9.1.5-1PGDG.rhel6

Dependency Installed:
  postgresql91.x86_64 0:9.1.5-1PGDG.rhel6
  postgresql91-libs.x86_64 0:9.1.5-1PGDG.rhel6

Complete!

初始化資料庫,預設路徑為/var/lib/pgsql/9.1/data
[root@SNDA-192-168-15-161 yum.repos.d]# service postgresql-9.1 initdb
Initializing database:                                     [  OK  ]

啟動服務
[root@SNDA-192-168-15-161 yum.repos.d]# service postgresql-9.1 start
Starting postgresql-9.1 service:                           [  OK  ]

[root@SNDA-192-168-15-161 yum.repos.d]# vi /var/lib/pgsql/9.1/data/pg_hba.conf
[root@SNDA-192-168-15-161 yum.repos.d]# psql -U postgres
psql: FATAL:  Peer authentication failed for user "postgres"

重啟服務
[root@SNDA-192-168-15-161 yum.repos.d]# service postgresql-9.1 restart
Stopping postgresql-9.1 service:                           [  OK  ]
Starting postgresql-9.1 service:                           [  OK  ]

(這裡需要先修改設定檔/var/lib/pgsql/9.1/data/pg_hba.conf 將peer或別的改為trust,否則會提示錯誤Peer authentication failed for user “postgres”),修改用戶端認證設定檔,將METHOD由預設的ident改為md5
[root@SNDA-192-168-15-161 yum.repos.d]# psql -U postgres
psql (9.1.5)
Type "help" for help.

postgres=# ALTER USER postgres WITH PASSWORD 'admin'
postgres-# \q

 

Engine Yard:PostgreSQL是我們的第一選擇

PostgreSQL介面編程二:.NetDataProvider--Npgsql驅動

http://www.codeproject.com/Articles/30989/Using-PostgreSQL-in-your-C-NET-application-An-intr

http://datachomp.com/archives/getting-started-with-postgres-and-mvc3/

http://www.pgadmin.org/

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.