標籤:
一、環境
VM虛擬機器
NAME="Ubuntu"VERSION="12.04.4 LTS, Precise Pangolin"
二、過程
1.安裝make,現在不裝也行。
# apt-get install make
# make --versionGNU Make 3.81Copyright (C) 2006 Free Software Foundation, Inc.This is free software; see the source for copying conditions.There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR APARTICULAR PURPOSE.This program built for i686-pc-linux-gnu
2.擷取源碼
但是現在已經有現成的二進位安裝包了,而且根據不同的系統給出了安裝方法。http://www.postgresql.org/download/
原始碼在File Browser上,或者直接從版本控制倉庫擷取,就是從git上擷取。用源碼安裝的操作文檔在這。http://www.postgresql.org/docs/current/static/installation.html
開啟看一下ubuntu選項的頁面說了些啥,http://www.postgresql.org/download/linux/ubuntu/。一堆英文大概意思就是說Ubuntu已經預設包含了PostgreSQL,現在可以用apt-get來安裝,如果你Ubuntu上的pgsql版本不是你想要的,可以用PostgreSQL Apt 倉庫來整合補丁,然後下面是基本操作步驟,更多Apt相關的資訊資料見wiki,https://wiki.postgresql.org/wiki/Apt 。
wiki中說是PGDG這個小組在支援維護APT repository,他們致力於building PostgreSQL server packages as well as extensions and modules packages on several Debian/Ubuntu releases for all PostgreSQL versions supported。就是給不同的發行版發布PostgreSQL及其相關的包。下面是一段快速入門的安裝步驟,就按著wiki來好了。
3.安裝
添加源,更新源
# sudo sh -c ‘echo "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list‘# apt-get update
PS:這個變數可以擷取版本代號
# echo $(lsb_release -cs)precise# cat /etc/apt/sources.list.d/pgdg.list
deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main
更新好源之後,可以搜尋到各個版本的postgresql,大概看了下,8.2的也有,最新的是9.5
# apt-cache search postgresql-|grep ‘object-relational‘|lesspostgresql-9.1 - object-relational SQL database, version 9.1 serverpostgresql-8.4 - object-relational SQL database, version 8.4 serverpostgresql-8.2 - object-relational SQL database, version 8.2 serverpostgresql-8.3 - object-relational SQL database, version 8.3 serverpostgresql-9.0 - object-relational SQL database, version 9.0 serverpostgresql-9.2 - object-relational SQL database, version 9.2 serverpostgresql-9.3 - object-relational SQL database, version 9.3 serverpostgresql-9.4 - object-relational SQL database, version 9.4 serverpostgresql-9.5 - object-relational SQL database, version 9.5 server
安裝更新wget和認證
# sudo apt-get install wget ca-certificates
...省略...
正預備替換 ca-certificates 20111211 (使用 .../ca-certificates_20141019ubuntu0.12.04.1_all.deb) ...
正在解壓縮將用於更替的包檔案 ca-certificates ...
正預備替換 wget 1.13.4-2ubuntu1 (使用 .../wget_1.13.4-2ubuntu1.2_i386.deb) ...
正在解壓縮將用於更替的包檔案 wget ...
正在處理用於 man-db 的觸發器...
正在處理用於 install-info 的觸發器...
正在設定 ca-certificates (20141019ubuntu0.12.04.1) ...
Updating certificates in /etc/ssl/certs... 38 added, 17 removed; done.
Running hooks in /etc/ca-certificates/update.d....done.
正在設定 wget (1.13.4-2ubuntu1.2) ...
# wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
OK
安裝PostgreSQL,暫時先裝個9.2來練手
# sudo apt-get install postgresql-9.2正在讀取軟體包列表... 完成正在分析軟體包的相依樹狀結構 正在讀取狀態資訊... 完成 將會安裝下列額外的軟體包: libpq5 pgdg-keyring postgresql-client-9.2 postgresql-client-common postgresql-common ssl-cert建議安裝的軟體包: oidentd ident-server locales-all postgresql-doc-9.2 openssl-blacklist下列【新】軟體包將被安裝: libpq5 pgdg-keyring postgresql-9.2 postgresql-client-9.2 postgresql-client-common postgresql-common ssl-cert升級了 0 個軟體包,新安裝了 7 個軟體包,要卸載 0 個軟體包,有 140 個軟體包未被升級。需要下載 4,663 kB 的軟體包。解壓縮後會消耗掉 22.6 MB 的額外空間。.........省略下載,解壓縮過程...正在設定 libpq5 (9.4.4-1.pgdg12.4+1) ...正在設定 pgdg-keyring (2014.1) ...Removing apt.postgresql.org key from trusted.gpg: OKImporting apt.postgresql.org key: OK正在設定 postgresql-client-common (169.pgdg12.4+1) ...正在設定 postgresql-client-9.2 (9.2.13-1.pgdg12.4+1) ...update-alternatives: 使用 /usr/share/postgresql/9.2/man/man1/psql.1.gz 來提供 /usr/share/man/man1/psql.1.gz (psql.1.gz),於 自動模式 中。正在設定 ssl-cert (1.0.28ubuntu0.1) ...正在設定 postgresql-common (169.pgdg12.4+1) ...Adding user postgres to group ssl-certCreating config file /etc/postgresql-common/createcluster.conf with new versionCreating config file /etc/logrotate.d/postgresql-common with new versionBuilding PostgreSQL dictionaries from installed myspell/hunspell packages... en_usRemoving obsolete dictionary files: * No PostgreSQL clusters exist; see "man pg_createcluster"正在設定 postgresql-9.2 (9.2.13-1.pgdg12.4+1) ...Creating new cluster 9.2/main ... config /etc/postgresql/9.2/main data /var/lib/postgresql/9.2/main locale zh_CN.UTF-8 port 5432update-alternatives: 使用 /usr/share/postgresql/9.2/man/man1/postmaster.1.gz 來提供 /usr/share/man/man1/postmaster.1.gz (postmaster.1.gz),於 自動模式 中。 * Starting PostgreSQL 9.2 database server [ OK ] 正在處理用於 libc-bin 的觸發器...ldconfig deferred processing now taking place
4.配置遠端存取
PostgreSQL剛安裝好後的狀態應該是,Ubuntu上的postgres使用者密碼未知,資料庫上的postgres密碼未設
若用root或允許sudo,可以直接強制以postgres使用者登入,不需要知道postgres的密碼
root # su postgres postgres $ psqlpsql (9.2.13)輸入 "help" 來擷取協助資訊.postgres=#
(非root,允許sudo的使用者,這裡設了免密) $ sudo -u postgres psqlpsql (9.2.13)輸入 "help" 來擷取協助資訊.postgres=#
登入後就給SQL的postgres設個密碼
postgres#\password postgres
退出去找一個目錄,要修改兩個檔案,postgresql.conf 和 pg_hba.conf
# find / -name postgresql.conf/etc/postgresql/9.2/main/postgresql.conf# cd /etc/postgresql/9.2/main/# lenvironment pg_ctl.conf pg_hba.conf pg_ident.conf postgresql.conf start.conf
postgresql.conf 監聽所有IP,預設連接埠,開啟日誌收集,每天一個新日誌,還有很多不懂的參數可以調。
listen_addresses = ‘*‘ # what IP address(es) to listen on; # comma-separated list of addresses; # defaults to ‘localhost‘; use ‘*‘ for all # (change requires restart)port = 5432 # (change requires restart)logging_collector = on # Enable capturing of stderr and csvlog # into log files. Required to be on for # csvlogs. # (change requires restart)log_directory = ‘pg_log‘ # directory where log files are written, # can be absolute or relative to PGDATAlog_filename = ‘postgresql-%Y-%m-%d_%H%M%S.log‘ # log file name pattern, # can include strftime() escapeslog_truncate_on_rotation = off # If on, an existing log file with the # same name as the new log file will be # truncated rather than appended to. # But such truncation only occurs on # time-driven rotation, not on restarts # or size-driven rotation. Default is # off, meaning append to existing files # in all cases.log_rotation_age = 1d # Automatic rotation of logfiles will # happen after that time. 0 disables.log_rotation_size = 0 # Automatic rotation of logfiles will # happen after that much log output. # 0 disables.
pg_hba.conf 加入自己的地址,全部是0.0.0.0/0
# IPv4 local connections:host all all 127.0.0.1/32 md5host all all 192.168.152.1/24 md5
重啟postgresql服務,再用pgAdminIII設定一下地址,連接埠,使用者名稱稱,密碼,就可以成功串連了
PostgreSQL-安裝9.2