ubuntu安装postgresql、postgis、pgrouting

ps:我是在windows中的 wsl 中创建了 ubuntu,所以不涉及任何防火墙、端口相关的内容

1. 安装postgresql

shell 复制代码
sudo apt update
sudo apt install postgresql postgresql-contrib

安装完成后系统会自动创建一个 postgres 用户,先切换到 postgres 用户

shell 复制代码
# 切换用户
sudo -i -u postgres

设置密码

sql 复制代码
# 查看配置文件地址
show config_file;
show hba_file;


postgresql.conf 修改

pg_hba.conf 修改

重启:

shell 复制代码
systemctl restart postgresql

2. 安装插件 [postgis、pgrouting]

这个里面有相关说明
https://github.com/dhamaniasad/awesome-postgres

我的 postgresql 版本是 16

1. 添加PostgreSQL Apt仓库(如果尚未添加)

复制代码
```shell
# 安装所需工具
sudo apt install ca-certificates gnupg curl

# 添加PGDG密钥
curl https://www.postgresql.org/media/keys/ACCC4CF8.asc | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/apt.postgresql.org.gpg >/dev/null

# 添加仓库
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'

# 更新包列表
sudo apt update
```

2. 安装PostGIS for PostgreSQL 16(其它版本直接把下面的 16 改成你的版本即可)

shell 复制代码
# 查看可用的PostGIS版本 ,如果是其它版本就把 16  改成你的本
apt search postgresql-16-postgis

# 安装PostGIS命令行工具
sudo apt install postgis

# postgis插件
sudo apt install postgresql-16-postgis-3

# pgrouting 插件
sudo apt install postgresql-16-pgrouting

如果有提示升级啥的直接选 no

3. 测试

shell 复制代码
# 切换用户 进入 postgresql 命令行
sudo -u postgres psql

CREATE DATABASE gis_test;

# 连接到新数据库
\c gis_test

# 启用PostGIS扩展
CREATE EXTENSION postgis;

# 验证安装
SELECT PostGIS_Version();

# 应该看到类似这样的输出:
# POSTGIS="3.4.0" [EXTENSION] PGSQL="160" GEOS="3.11.1" PROJ="9.1.1" ...
相关推荐
赵渝强老师7 小时前
【赵渝强老师】PostgreSQL中表的碎片
数据库·postgresql
chlk1231 天前
Linux文件权限完全图解:读懂 ls -l 和 chmod 755 背后的秘密
linux·操作系统
舒一笑1 天前
Ubuntu系统安装CodeX出现问题
linux·后端
改一下配置文件2 天前
Ubuntu24.04安装NVIDIA驱动完整指南(含Secure Boot解决方案)
linux
深紫色的三北六号2 天前
Linux 服务器磁盘扩容与目录迁移:rsync + bind mount 实现服务无感迁移(无需修改配置)
linux·扩容·服务迁移
SudosuBash2 天前
[CS:APP 3e] 关于对 第 12 章 读/写者的一点思考和题解 (作业 12.19,12.20,12.21)
linux·并发·操作系统(os)
哈基咪怎么可能是AI3 天前
为什么我就想要「线性历史 + Signed Commits」GitHub 却把我当猴耍 🤬🎙️
linux·github
十日十行3 天前
Linux和window共享文件夹
linux
木心月转码ing4 天前
WSL+Cpp开发环境配置
linux
崔小汤呀5 天前
最全的docker安装笔记,包含CentOS和Ubuntu
linux·后端