Skip to content
This documentation is for the end of life version of Percona Distribution for PostgreSQL 11.
Learn more about PostgreSQL 11 end of life implications. See the current documentation.
logo
Percona Product Documentation
Deployment
Initializing search
    percona/postgresql-docs
    percona/postgresql-docs
    • Home
      • Release notes index
      • Percona Distribution for PostgreSQL 11.22 Update (2024-01-22)
      • Percona Distribution for PostgreSQL 11.22 (2023-12-13)
      • Percona Distribution for PostgreSQL 11.21 (2023-08-31)
      • Percona Distribution for PostgreSQL 11.20 (2023-06-30)
      • Percona Distribution for PostgreSQL 11.19 Update (2023-05-22)
      • Percona Distribution for PostgreSQL 11.19 (2023-03-31)
      • Percona Distribution for PostgreSQL 11.18 (2022-12-08)
      • Percona Distribution for PostgreSQL 11.17 (2022-09-08)
      • Percona Distribution for PostgreSQL 11.16 (2022-06-07)
      • Percona Distribution for PostgreSQL 11.15 Second Update (2022-05-05)
      • Percona Distribution for PostgreSQL 11.15 Update (2022-04-14)
      • Percona Distribution for PostgreSQL 11.15 (2022-04-08)
      • Percona Distribution for PostgreSQL 11.14 (2021-12-20)
      • Percona Distribution for PostgreSQL 11.13 Update (2021-12-07)
      • Percona Distribution for PostgreSQL 11.13 (2021-09-09)
      • Percona Distribution for PostgreSQL 11.12 Third Update (2021-07-15)
      • Percona Distribution for PostgreSQL 11.12 Second Update (2021-07-01)
      • Percona Distribution for PostgreSQL 11.12 Update (2021-06-10)
      • Percona Distribution for PostgreSQL 11.12 (2021-05-24)
      • Percona Distribution for PostgreSQL 11.11 Third Update (2021-06-10)
      • Percona Distribution for PostgreSQL 11.11 Second Update (2021-05-10)
      • Percona Distribution for PostgreSQL 11.11 Update (2021-04-12)
      • Percona Distribution for PostgreSQL 11.11 (2021-03-08)
      • Percona Distribution for PostgreSQL 11.10 Update (2021-06-10)
      • Percona Distribution for PostgreSQL 11.10 (2020-12-15)
      • Percona Distribution for PostgreSQL 11.9 (2020-09-08)
      • Percona Distribution for PostgreSQL 11.8 (2020-06-11)
      • Percona Distribution for PostgreSQL 11.7 (2020-04-09)
      • Percona Distribution for PostgreSQL 11.6 (2020-01-23)
      • Percona Distribution for PostgreSQL 11 (2019-09-17)
      • Percona Distribution for PostgreSQL 11 (Beta) (2019-05-15)
        • Overview
        • Via apt
        • Via yum
        • Enable Percona Distribution for PostgreSQL extensions
        • Repositories overview
      • Run in Docker
      • Migrate from PostgreSQL to Percona Distribution for PostgreSQL
      • Minor Upgrade of Percona Distribution for PostgreSQL
      • pg_stat_monitor
      • High availability
        • Deploying on Debian or Ubuntu
        • Deploying on RHEL or CentOS
        • Testing the Patroni PostgreSQL Cluster
        • pgBackRest setup
      • Backup and disaster recovery
        • Deploying backup and disaster recovery solution in Percona Distribution for PostgreSQL
        • Overview
        • Deployment
          • Considerations
          • Install PostGIS
          • Enable PostGIS extension
          • Upload spatial data to PostgreSQL
        • Query spatial data
        • Upgrade spatial database
      • LDAP authentication
    • Telemetry
    • Uninstall
    • Licensing
    • Trademark policy

    • Considerations
    • Install PostGIS
    • Enable PostGIS extension
    • Upload spatial data to PostgreSQL

    Deploy spatial data with PostgreSQL¶

    The following document provides guidelines how to install PostGIS and how to run the basic queries.

    Considerations¶

    1. We assume that you have the basic knowledge of spatial data, GIS (Geographical Information System) and of shapefiles.
    2. For uploading the spatial data and querying the database, we use the same data set as is used in PostGIS tutorial

    Install PostGIS¶

    1. Enable Percona repository

      As other components of Percona Distribution for PostgreSQL, PostGIS is available from Percona repositories. Use the percona-release repository management tool to enable the repository.

      $ sudo percona-release setup ppg11
      
    2. Install PostGIS packages

      $ sudo apt install percona-postgis
      
    3. The command in the previous step installs the set of PostGIS extensions. To check what extensions are available, run the following query from the psql terminal:

      SELECT name, default_version,installed_version
      FROM pg_available_extensions WHERE name LIKE 'postgis%' or name LIKE address%';
      

      Note

      To enable the postgis_sfcgal-3 extension on Ubuntu 18.04, you need to manually install the required dependency:

      $ sudo apt-get install libsfcgal1
      

    For Red Hat Enterprise Linux 8 and derivatives, replace the operating system version in the following commands accordingly.

    1. Check the Platform specific notes and enable required repositories and modules for the dependencies relevant to your operating system.
    2. Enable Percona repository

      As other components of Percona Distribution for PostgreSQL, PostGIS is available from Percona repositories. Use the percona-release repository management tool to enable the repository.

      $ sudo percona-release setup ppg11
      
    3. Install the extension

      $ sudo yum install percona-postgis33_11 percona-postgis33_11-client
      

    This installs the set of PostGIS extensions. To check what extensions are available, run the following query from the psql terminal:

    SELECT name, default_version,installed_version
    FROM pg_available_extensions WHERE name LIKE 'postgis%' or name LIKE 'address%';
    

    Enable PostGIS extension¶

    1. Create a database and a schema for this database to store your data. A schema is a container that logically segments objects (tables, functions, views, and so on) for better management. Run the following commands from the psql terminal:

      CREATE DATABASE nyc;
      \c nyc;
      CREATE SCHEMA gis;
      
    2. To make PostGIS functions and operations work, you need to enable the postgis extension. Make sure you are connected to the database you created earlier and run the following command:

      \c nyc;
      CREATE EXTENSION postgis;
      
    3. Check that the extension is enabled:

      SELECT postgis_full_version();
      

      The output should be similar to the following:

      postgis_full_version
      -----------------------------------------------------------------------------------------------------------------------------------------------------------------
       POSTGIS="3.3.3" [EXTENSION] PGSQL="140" GEOS="3.10.2-CAPI-1.16.0" PROJ="8.2.1" LIBXML="2.9.13" LIBJSON="0.15" LIBPROTOBUF="1.3.3" WAGYU="0.5.0 (Internal)"
      

    Upload spatial data to PostgreSQL¶

    PostGIS provides the shp2pgsql command line utility that converts the binary data from shapefiles into the series of SQL commands and loads them into the database.

    1. For testing purposes, download the sample data set:

      $ curl -LO https://s3.amazonaws.com/s3.cleverelephant.ca/postgis-workshop-2020.zip
      
    2. Unzip the archive. From the folder where the .shp files are located, execute the following command and replace the dbname value with the name of your database:

      shp2pgsql \
        -D \
        -I \
        -s 26918 \
        nyc_streets.shp \
        nyc_streets \
        | psql -U postgres dbname=nyc
      

      The command does the following:

      • -D flag instructs the command to generate the dump format
      • -I flag instructs to create the spatial index on the table upon the data load
      • -s indicates the spatial reference identifier of the data. The data we load is in the Projected coordinate system for North America and has the value 26918.
      • nyc_streets.shp is the source shapefile
      • nyc_streets is the table name to create in the database
      • dbname=nyc is the database name
    3. Check the uploaded data

      \d nyc_streets;
                                               Table "public.nyc_streets"
       Column |              Type               | Collation | Nullable |                 Default
      --------+---------------------------------+-----------+----------+------------------------------------------
       gid    | integer                         |           | not null | nextval('nyc_streets_gid_seq'::regclass)
       id     | double precision                |           |          |
       name   | character varying(200)          |           |          |
       oneway | character varying(10)           |           |          |
       type   | character varying(50)           |           |          |
       geom   | geometry(MultiLineString,26918) |           |          |
      Indexes:
          "nyc_streets_pkey" PRIMARY KEY, btree (gid)
          "nyc_streets_geom_idx" gist (geom)
      
    4. Repeat the command to upload other shapefiles in the data set: nyc_census_blocks, nyc_neighborhoods, nyc_subway_stations

    Contact Us

    For free technical help, visit the Percona Community Forum.

    To report bugs or submit feature requests, open a JIRA ticket.

    For paid support and managed or consulting services , contact Percona Sales.

    December 13, 2023 June 30, 2023
    Percona LLC and/or its affiliates, © 2024 — Cookie Preferences
    Made with Material for MkDocs