# 源码安装
tar zxvf postgresql-10.0.tar.gz
mv postgresql-10.0 /usr/local/pgsql
cd /usr/local/pgsql/
./configure --prefix=/usr/local/pgsql --without-readline
make
make install
# 添加用户,设置目录权限
adduser postgres
passwd postgres
mkdir -p /usr/local/pgsql/data
chown -R postgres:root /usr/local/pgsql
# 设置环境变量
> su - postgres
> vim ~/.bash_profile
export PATH=$PATH:/usr/local/pgsql/bin
> source ~/.bash_profile
# 允许所有连接
> vim /usr/local/pgsql/data/pg_hba.conf
host all all 0.0.0.0/0 trust
# 侦听所有连接
> vim /usr/local/pgsql/data/postgresql.conf
listen_addresses = '*'
logging_collector = on
# 添加启动服务(确认文件postgresql内的目录正确)
cp /usr/local/pgsql/contrib/start-scripts/linux /etc/init.d/postgresql
chmod u+x /etc/init.d/postgresql
# 添加开启自启动
chkconfig --add postgresql
# 启动服务
service postgresql start
# 切换用户,初始化数据并创建测试库(确认data目录下为空)
su - postgres
/usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data
createdb test
psql test
pgadmin4 安装:
#下载 pgadmin4
https://www.pgadmin.org/download/pgadmin-4-python-wheel/
# 安装 pgadmin4
> pip install pgadmin4-2.0-py2.py3-none-any.whl
# 设置服务器地址
> vim /usr/lib/python2.7/site-packages/pgadmin4/config.py
DEFAULT_SERVER = '192.168.40.10'
# 设置邮箱用户&密码,启动服务
> python /usr/lib/python2.7/site-packages/pgadmin4/pgAdmin4.py
# 浏览器访问
http://192.168.40.10:5050/
yum 安装 postgresql-11 及 postgis
# 安装(自动创建用户及组 postgres)
rpm -ivh https://download.postgresql.org/pub/repos/yum/11/redhat/rhel-7-x86_64/pgdg-centos11-11-2.noarch.rpm
yum install -y postgresql11-server postgresql11
/usr/pgsql-11/bin/postgresql-11-setup initdb
#启动服务
systemctl enable postgresql-11
systemctl start postgresql-11
systemctl status postgresql-11
# postgis 安装参考 http://www.postgis.net/install/
# 安装 postgis
yum install -y ogr_fdw11 pgrouting_11 postgis25_11 postgis25_11-client
# 启用 postgis 等
# su - postgres
CREATE EXTENSION postgis;
CREATE EXTENSION postgis_topology;
CREATE EXTENSION postgis_sfcgal;
\dx
SELECT postgis_full_version();
-----------------------------------------------
# 创建多实例及启动
-----------------------------------------------
mkdir -p /opt/postgre_data/data5433
chown -R postgres:postgres /opt/postgre_data
su postgres
/usr/pgsql-11/bin/pg_ctl init -D /opt/postgre_data/data5433
sed -ie 's/^#port = 5432/port = 5433/g' /opt/postgre_data/data5433/postgresql.conf
/usr/pgsql-11/bin/pg_ctl -D /opt/postgre_data/data5433 start
官方安装参考:
https://www.postgresql.org/docs/10/static/installation.html (EN)
http://www.postgres.cn/docs/9.3/installation.html (CN)
pgadmin4 文档:https://www.pgadmin.org/docs/pgadmin4/dev/index.html