Ubuntu18.04.3安装postgresql和postgis

postgresql部署

  1. 安装postgresql组件
bash 复制代码
root@test-server03:~# apt-get install postgresql-10 -y
  1. 修改posgresql数据目录
bash 复制代码
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. 创建数据目录并授权
bash 复制代码
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. 初始化数据库
bash 复制代码
#找到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用户密码
bash 复制代码
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. 修改配置
bash 复制代码
root@test-server03:~# vim /etc/postgresql/10/main/pg_hba.conf


标红的注释掉,标黄的修改一处,新增一处

bash 复制代码
root@test-server03:~# vim /etc/postgresql/10/main/postgresql.conf
listen_addresses = '*'
  1. 重启psql
bash 复制代码
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
bash 复制代码
root@test-server03:~# apt-get install postgis -y
  1. 配置postgis
bash 复制代码
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插件成功安装

相关推荐
Nturmoils14 小时前
订单列表慢查询,先看 WHERE、ORDER BY 和 LIMIT
数据库
渣波17 小时前
拒绝 SQL 焦虑!手把手带你用 NestJS + Prisma + DTO 写出“防弹”级后端代码
javascript·数据库·后端
倔强的石头_2 天前
KingbaseES 新版MySQL 兼容版体验:旧版迁移 + 功能实测
数据库
倔强的石头_5 天前
《Kingbase护城河》——数据库存储空间全景探测与精细化瘦身实战
数据库
冬奇Lab5 天前
每日一个开源项目(第134篇):Zvec - 阿里开源的嵌入式向量数据库,向量搜索界的 SQLite
数据库·人工智能·llm
ClouGence6 天前
Oracle CDC 架构优化:从主库直连到 DataGuard 备库同步
数据库·后端·oracle
无响应de神6 天前
三、用户与权限管理
数据库·mysql
麦聪聊数据6 天前
数据服务化时代:企业数据能力输出的核心路径
数据库
shushangyun_6 天前
2026年快消品B2B系统推荐:支持终端门店订货、促销政策自动化的工具?
java·运维·网络·数据库·人工智能·spring·自动化
DARLING Zero two♡6 天前
【MySQL数据库】数据类型与表约束
数据库·mysql