1. 服务器安装
1.1 源码安装
平台:Ubuntu 16.04 LTS
- 1 下载源码,以9.6.2为例, https://github.com/postgres/postgres/archive/REL9_6_2.zip
- 2 安装库依赖并安装
$ sudo apt install libreadline6-dev bison flex
$ ./configure
$ make && sudo make install
如果少了依赖包,重新安装后需要执行./configure && make clean && make && sudo make install
- 3 默认安装位置
/usr/local/pgsql/
1.2 软件仓库安装
$ 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 安装后动作
不能用root权限运行PostgreSQL,添加添加postgres用户,并完成启动。
$ 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
启动完成, 测试连接
$ psql -h localhost -U postgres -w