Ricerca nel sito web

Come installare PostGIS PostgreSQL database extender su CentOS 8


Su questa pagina

  1. Prerequisiti
  2. Per iniziare
  3. Installa PostGIS
  4. Crea un'estensione
  5. Conclusione

PostGIS è un database extender gratuito e open source per il sistema di gestione dei database PostgreSQL. Ti aiuta ad aggiungere alcune funzioni extra come area, unione, intersezione, distanza, tipi di dati e consentire l'esecuzione di query sulla posizione in SQL. Con PostGIS, puoi memorizzare i poligoni e i tipi di punti dei dati nel database PostgreSQL.

In questo tutorial, ti mostreremo come installare PostGIS con PostgreSQL su CentOS 8.

Prerequisiti

  • Un server che esegue CentOS 8.
  • Una password di root è configurata sul tuo server.

Iniziare

Prima di iniziare, dovrai installare PostGIS e il repository EPEL sul tuo sistema. Puoi installarli entrambi eseguendo il seguente comando:

dnf -y install https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm
dnf -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm

Successivamente, abilita il repository Powertool e disabilita il repository PostgreSQL predefinito con il seguente comando:

dnf config-manager --set-enabled PowerTools
dnf -qy module disable postgresql

Una volta terminato, puoi procedere al passaggio successivo.

Installa PostGIS

Ora puoi installare PostGIS eseguendo il seguente comando:

dnf install postgis25_12

Una volta completata l'installazione, è possibile verificare il pacchetto PostGIS con il seguente comando:

rpm -qi postgis25_12

Dovresti ottenere il seguente output:

Name        : postgis25_12
Version     : 2.5.5
Release     : 2.rhel8
Architecture: x86_64
Install Date: Monday 01 February 2021 11:59:37 PM EST
Group       : Unspecified
Size        : 29832534
License     : GPLv2+
Signature   : DSA/SHA1, Tuesday 10 November 2020 01:36:47 PM EST, Key ID 1f16d2e1442df0f8
Source RPM  : postgis25_12-2.5.5-2.rhel8.src.rpm
Build Date  : Tuesday 10 November 2020 01:30:09 PM EST
Build Host  : koji-rhel8-x86-64-pgbuild
Relocations : (not relocatable)
Vendor      : PostgreSQL Global Development Group
URL         : http://www.postgis.net/
Summary     : Geographic Information Systems Extensions to PostgreSQL
Description :
PostGIS adds support for geographic objects to the PostgreSQL object-relational
database. In effect, PostGIS "spatially enables" the PostgreSQL server,
allowing it to be used as a backend spatial database for geographic information
systems (GIS), much like ESRI's SDE or Oracle's Spatial extension. PostGIS
follows the OpenGIS "Simple Features Specification for SQL" and has been
certified as compliant with the "Types and Functions" profile.

Successivamente, inizializza il database PostgreSQL con il seguente comando:

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

Successivamente, avvia il servizio PostgreSQL e abilitalo per l'avvio al riavvio del sistema con il seguente comando:

systemctl start postgresql-12.service
systemctl enable postgresql-12.service

Crea un'estensione

A questo punto, PostgreSQL e PostGIS sono stati installati. Ora dovrai creare un'estensione per PostGIS.

Innanzitutto, accedi all'utente Postgres con il seguente comando:

su - postgres

Successivamente, crea un utente e un database postgres con il seguente comando:

createuser test_usr
createdb test_postgis -O test_usr

Successivamente, connettiti al database con il seguente comando:

psql -d test_postgis

Dovresti vedere il seguente output:

psql (12.5)
Type "help" for help.

Quindi, crea un'estensione PostGIS con il seguente comando:

CREATE EXTENSION postgis;

Successivamente, puoi verificare la versione di PostGIS utilizzando il seguente comando:

select PostGIS_Full_Version();

Dovresti vedere la versione di PostGIS nel seguente output:

                                                                                          postgis_full_version                                 
                                                          
-----------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------
 POSTGIS="2.5.5" [EXTENSION] PGSQL="120" GEOS="3.8.1-CAPI-1.13.3" PROJ="Rel. 7.2.1, January 1st, 2021" GDAL="GDAL 3.2.1, released 2020/12/29" L
IBXML="2.9.7" LIBJSON="0.13.1" LIBPROTOBUF="1.3.0" RASTER
(1 row)

Successivamente, esci dalla shell Postgres con il seguente comando;

exit
exit

Conclusione

Nella guida sopra, hai imparato come installare PostGIS con PostgreSQL su CentOS 8. Ora puoi utilizzare PostGIS per aggiungere geometria al tuo database.