Ubuntu18.04.3安装postgresql和postgis

postgresql部署

  1. 安装postgresql组件
root@test-server03:~# apt-get install postgresql-10 -y
  1. 修改posgresql数据目录
root@test-server03:~# systemctl stop postgresql
root@test-server03:~# cd /etc/postgresql/10/main/
root@test-server03:/etc/postgresql/10/main# vim postgresql.conf
#修改下面参数为自己的数据盘目录
data_directory = '/opt/postgresql/data'
  1. 创建数据目录并授权
root@test-server03:/etc/postgresql/10/main# mkdir /opt/postgresql/data -p
root@test-server03:/etc/postgresql/10/main# chown -R postgres.postgres /opt/postgresql*
  1. 初始化数据库
#找到initdb的位置
root@test-server03:~# find / -name initdb
/usr/lib/postgresql/10/bin/initdb
#初始化
root@test-server03:~# sudo -u postgres /usr/lib/postgresql/10/bin/initdb -D /opt/postgresql/data
#重新启动postgresql
root@test-server03:~# systemctl restart postgresql
  1. 修改postgres用户密码
root@test-server03:~# passwd postgres
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
#登录psql查看数据目录是否修改,并且设置密码
root@test-server03:~# su postgres
postgres@test-server03:/root$ psql
psql (10.23 (Ubuntu 10.23-0ubuntu0.18.04.2))
Type "help" for help.
postgres=# SHOW data_directory;
    data_directory
----------------------
 /opt/postgresql/data
postgres=# ALTER USER postgres PASSWORD 'newpassd';
ALTER ROLE
  1. 修改配置
root@test-server03:~# vim /etc/postgresql/10/main/pg_hba.conf

在这里插入图片描述
标红的注释掉,标黄的修改一处,新增一处

root@test-server03:~# vim /etc/postgresql/10/main/postgresql.conf
listen_addresses = '*'
  1. 重启psql
root@test-server03:~# systemctl restart postgresql
root@test-server03:~# psql  -U postgres
Password for user postgres:
psql (10.23 (Ubuntu 10.23-0ubuntu0.18.04.2))
Type "help" for help.
postgres=#

postgis安装

  1. 安装postgis
root@test-server03:~# apt-get install postgis -y
  1. 配置postgis
root@test-server03:~# psql -U postgres -W
Password for user postgres:
psql (10.23 (Ubuntu 10.23-0ubuntu0.18.04.2))
Type "help" for help.
postgres=#  create extension postgis;
CREATE EXTENSION
postgres=# \dx
                                     List of installed extensions
  Name   | Version |   Schema   |                             Description
---------+---------+------------+---------------------------------------------------------------------
 plpgsql | 1.0     | pg_catalog | PL/pgSQL procedural language
 postgis | 2.4.3   | public     | PostGIS geometry, geography, and raster spatial types and functions
(2 rows)

postgis插件成功安装

猜你喜欢

转载自blog.csdn.net/weixin_45697805/article/details/141929007