centos7使用yum安装postgis数据库和使用docker安装postgis数据库
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
https://www.postgresql.org/download/linux/redhat/
1 添加PostgreSQL Yum源
 
sudo yum install epel-release
sudo yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
 
2 安装PostgreSQL和PostGIS
sudo yum install postgresql12-server postgresql12-contrib postgis30_12
 
3 初始化PostgreSQL数据库
sudo /usr/pgsql-12/bin/postgresql-12-setup initdb
 
4 启动PostgreSQL服务
sudo systemctl start postgresql-12
sudo systemctl enable postgresql-12
 
5 创建PostgreSQL数据库
sudo su - postgres
createdb mydatabase
 
6 将PostGIS扩展添加到数据库中
psql -d mydatabase -c "CREATE EXTENSION postgis;"
psql -d mydatabase -c "CREATE EXTENSION postgis_topology;"

  

 

开启远程访问

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
修改配置文件
 
配置文件目录 /var/lib/pgsql/12/data/ 如果是安装的postgres 12  则 目录是 12
 
1.修改配置文件postgresql.conf
 
listen_addresses = ‘localhost‘取消注释,更改为:listen_addresses = ‘*‘
 
2.pg_hba.conf
 
在该配置文件的host all all 127.0.0.1/32 trust行下添加以下配置,或者直接将这一行修改为以下配置
 
host    all    all    0.0.0.0/0    trust
 
用工具连接上数据库后,修改数据库的密码
 
ALTER USER postgres WITH PASSWORD 'postgres';
 
然后再将上面的trust改成md5重启数据
 
最后重启postgres
 
关闭postgres服务的命令 sudo systemctl stop postgresql-12
启动postgres服务的命令 sudo systemctl start postgresql-12
 
postgres的安装目录/usr/pgsql-12 里面有lib和bin目录

 

创建空间数据表

 

使用命令方式

1
2
3
4
5
CREATE TABLE my_test_table (
  id SERIAL PRIMARY KEY,
  geom GEOMETRY(Point, 4326),
  name VARCHAR(128)
);

  

1
2
3
INSERT into table_point(name, geom) VALUES ('测试',ST_GeomFromText('POINT(112.22 30.12)', 4326))
 
SELECT name,st_astext(geom) FROM table_point

  

使用docker安装postgis数据库

docker pull postgis/postgis:12-3.3

docker run --name my-postgis  -p 11432:5432 -d -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=postgres -e POSTGRES_DB=mydatabase postgis/postgis:12-3.3

POSTGRES_USER=postgres设置账号为postgres

POSTGRES_PASSWORD=postgres 设置密码为postgres

POSTGRES_DB=mydatabase 创建一个数据库 数据库的名称为mydatabase,这个mydatabase数据库具备了保存空间数据的能力

 

posted on   james-roger  阅读(71)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· DeepSeek 开源周回顾「GitHub 热点速览」
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
点击右上角即可分享
微信分享提示