Rocky,Linux,9安装PostgreSQL和PostGIS教程

Rocky Linux 9正式版发布已有一段时间了,它属于稳定的Linux发行版,有的美国服务器商家已陆续提供该系统支持。PostgreSQL是款功能强大的开源关系型数据库,本文将介绍下如何在Rocky Linux 9上安装PostgreSQL和PostGIS。

首先,使用SSH工具登录到Rocky Linux服务器,然后运行下面命令来安装EPEL和PostgreSQL数据库。

dnf -y install epel-release

dnf -y install https://download.postgresql.org/pub/repos/yum/reporpms/EL-9-x86_64/pgdg-redhat-repo-latest.noarch.rpm

启用Code Ready Builder(CRB)。

dnf -y config-manager –set-enabled crb

禁用PostgreSQL模块。

dnf -qy module disable postgresql

开始安装PostgreSQL和PostGIS。例如,运行下面命令安装PostgreSQL 14服务器。

dnf -y install postgis32_14

初始化群集。

/usr/pgsql-14/bin/postgresql-14-setup initdb

启动PostgreSQL服务。

systemctl enable –now postgresql-14

切换到postgres用户。

su – postgres

创建数据库:

createdb my_gis_db

创建PostGIS扩展模块:

Rocky,Linux,9安装PostgreSQL和PostGIS教程

psql my_gis_db -c “CREATE EXTENSION postgis”

检查状态:

psql my_gis_db -c “SELECT postgis_full_version()”
postgis_full_version
———————————————————————————————————————————————————————————–
POSTGIS=”3.2.2 628da50″ [EXTENSION] PGSQL=”140″ GEOS=”3.10.3-CAPI-1.16.1″ SFCGAL=”1.4.1″ PROJ=”8.2.1″ LIBXML=”2.9.13″ LIBJSON=”0.14″ LIBPROTOBUF=”1.3.3″ WAGYU=”0.5.0 (Internal)”
(1 row)

最后,我们可以根据实际需要安装以下扩展。

  • – postgis_sfcgal
  • – postgis_raster
  • – postgis_tiger_geocoder
  • – postgis_topology

例如:

$ psql my_gis_db -c “CREATE EXTENSION postgis_topology”
CREATE EXTENSION
$ psql my_gis_db -c “CREATE EXTENSION postgis_raster”
CREATE EXTENSION
$ psql my_gis_db -c “SELECT postgis_full_version()”
postgis_full_version
——————————————————————————————————————————————————————————————————————————————
POSTGIS=”3.2.2 628da50″ [EXTENSION] PGSQL=”140″ GEOS=”3.10.3-CAPI-1.16.1″ SFCGAL=”1.4.1″ PROJ=”8.2.1″ GDAL=”GDAL 3.4.3, released 2022/04/22″ LIBXML=”2.9.13″ LIBJSON=”0.14″ LIBPROTOBUF=”1.3.3″ WAGYU=”0.5.0 (Internal)” TOPOLOGY RASTER
(1 row)

(本文由黑猫博客原创,转载请注明出处“黑猫博客”和原文地址!)

© 版权声明
THE END
点赞7 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容