1. 服務(wù)器安裝
1.1 源碼安裝
平臺(tái):Ubuntu 16.04 LTS
- 1 下載源碼撑瞧,以9.6.2為例, https://github.com/postgres/postgres/archive/REL9_6_2.zip
- 2 安裝庫(kù)依賴并安裝
$ sudo apt install libreadline6-dev bison flex
$ ./configure
$ make && sudo make install
如果少了依賴包飒泻,重新安裝后需要執(zhí)行./configure && make clean && make && sudo make install
- 3 默認(rèn)安裝位置
/usr/local/pgsql/
1.2 軟件倉(cāng)庫(kù)安裝
$ deb http://apt.postgresql.org/pub/repos/apt/ xenial-pgdg main
$ wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | \ sudo apt-key add -$ sudo apt-get update
$ sudo apt-get install postgresql-9.4
1.3 安裝后動(dòng)作
不能用root權(quán)限運(yùn)行PostgreSQL,添加添加postgres用戶,并完成啟動(dòng)案腺。
$ sudo adduser postgres
$ sudo mkdir /usr/local/pgsql/data
$ sudo chown postgres /usr/local/pgsql/data
$ su postgres
$ /usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data
$ touch /usr/local/pgsql/data/logfile
$ /usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data -l /usr/local/pgsql/data/logfile start
啟動(dòng)完成, 測(cè)試連接
$ psql -h localhost -U postgres -w