About PostGIS
PostGIS is a spatial database extension for PostgreSQL that allows GIS (Geographic
Information Systems) objects to be stored in the database. The Greenplum Database PostGIS
extension includes support for GiST-based R-Tree spatial indexes and functions for analysis
and processing of GIS objects.
The Greenplum Database PostGIS extension supports the optional PostGIS
raster data type and most PostGIS Raster functions. With the PostGIS
Raster objects, PostGIS geometry data type offers a single set of overlay
SQL functions (such as ST_Intersects) operating seamlessly on vector and
raster geospatial data. PostGIS Raster uses the GDAL (Geospatial Data Abstraction Library)
translator library for raster geospatial data formats that presents a single
raster abstract data model to a calling application.
For information about Greenplum Database PostGIS extension support, see .
For information about PostGIS, see https://postgis.net/
For information about GDAL, see https://gdal.org/.
Greenplum PostGIS Extension
The Greenplum Database PostGIS extension package is available from
VMware Tanzu Network. You can install the package using the
Greenplum Package Manager (gppkg). For details, see gppkg
in the Greenplum Database Utility Guide.
Greenplum Database supports the PostGIS extension with these component versions.
- PostGIS 2.5.4
- Proj 4.8.0
- Geos 3.4.2
- GDAL 1.11.1
- Json 0.12
- Expat 2.1.0
For the information about supported extension packages and software
versions, see the Greenplum Database Release Notes.
There have been significant changes in PostGIS 2.5.4 compared with the previously supported
version of 2.1.5. For a list of new and enhanced functions in PostGIS 2.5, see the PostGIS
documentation PostGIS Functions new or enhanced in 2.5.
For a comprehensive list of PostGIS changes in PostGIS 2.5.4 and earlier, see PostGIS 2.5
Appendix A Release 2.5.4.
Greenplum Database PostGIS Limitations
The Greenplum Database PostGIS extension does not support the following features:
- Topology
- A small number of user defined functions and aggregates
- PostGIS long transaction support
For information about Greenplum Database PostGIS support, see .
Enabling and Removing PostGIS Support
The Greenplum Database PostGIS extension contains the postgis_manager.sh
script that installs or removes both the PostGIS and PostGIS Raster features in a database.
After the PostGIS extension package is installed, the script is in
$GPHOME/share/postgresql/contrib/postgis-2.5/. The
postgis_manager.sh script runs SQL scripts that install or remove PostGIS
and PostGIS Raster from a database.
For information about the PostGIS and PostGIS Raster SQL scripts, and required PostGIS
Raster environment variables, see .
Enabling PostGIS Support
Run the postgis_manager.sh script specifying the database, an optional
schema, and the install option to install PostGIS and PostGIS Raster. If
you do not specify a schema, the script installs PostGIS in the default
schema.postgis_manager.sh <dbname> [<schema_name>] install
This example installs PostGIS and PostGIS Raster objects in the database
mydatabase in the default
schema.postgis_manager.sh mydatabase install
The script runs all the PostGIS SQL scripts that enable PostGIS in a database:
install/postgis.sql, install/rtpostgis.sql
install/spatial_ref_sys.sql,
install/postgis_comments.sql, and
install/raster_comments.sql.
The postGIS package installation adds these lines to the
greenplum_path.sh file for PostGIS Raster support.
export GDAL_DATA=$GPHOME/share/gdal
export POSTGIS_ENABLE_OUTDB_RASTERS=0
export POSTGIS_GDAL_ENABLED_DRIVERS=DISABLE_ALL
Enabling GDAL Raster Drivers
PostGIS uses GDAL raster drivers when processing raster data with commands such as
ST_AsJPEG(). As the default, PostGIS disables all raster drivers. You
enable raster drivers by setting the value of the
POSTGIS_GDAL_ENABLED_DRIVERS environment variable in the
greenplum_path.sh file on all Greenplum Database hosts.
Alternatively, you can do it at the session level by setting
postgis.gdal_enabled_drivers. For a Greenplum Database session, this
example SET command enables three GDAL raster
drivers.SET postgis.gdal_enabled_drivers TO 'GTiff PNG JPEG';
This SET command sets the enabled drivers to the default for a session.
SET postgis.gdal_enabled_drivers = default;
To see the list of supported GDAL raster drivers for a Greenplum Database system, run the
raster2pgsql utility with the -G option on the
Greenplum Database master.
raster2pgsql -G
The command lists the driver long format name. The GDAL Raster table at
https://gdal.org/drivers/raster/index.html lists the long format names and the
corresponding codes that you specify as the value of the environment variable. For
example, the code for the long name Portable Network Graphics is PNG.
This example export line enables four GDAL raster drivers.
export POSTGIS_GDAL_ENABLED_DRIVERS="GTiff PNG JPEG GIF"
The gpstop -r command restarts the Greenplum Database system to use the
updated settings in the greenplum_path.sh file.
After you have updated the greenplum_path.sh file on all hosts, and have
restarted the Greenplum Database system, you can display the enabled raster drivers with
the ST_GDALDrivers() function. This SELECT command lists
the enabled raster drivers.
SELECT short_name, long_name FROM ST_GDALDrivers();
Enabling Out-of-Database Rasters
After installing PostGIS, the default setting
POSTGIS_ENABLE_OUTDB_RASTERS=0 in the
greenplum_path.sh file disables support for to out-of-database rasters.
To enable this feature, you can set the value to true (a non-zero value) on all hosts and
restart the Greenplum Database system.
You can also enable or disable this feature for a Greenplum Database session. For
example, this SET command enables the feature for the current
session.
SET postgis.enable_outdb_rasters = true;
When the feature is enabled, the server configuration parameter
postgis.gdal_enabled_drivers determines the accessible raster
formats.
Removing PostGIS Support
Run the postgis_manager.sh script specifying the database, a schema name
(if necessary), and with the uninstall option to remove PostGIS and
PostGIS Raster. You specify the schema if you specified a schema when you installed
PostGIS.postgis_manager.sh <dbname> [<schema_name>] uninstall
This example removes PostGIS and PostGIS Raster support from the database
mydatabase that was installed in the default
schema.postgis_manager.sh mydatabase uninstall
The script runs both the PostGIS SQL scripts that remove PostGIS and PostGIS Raster from
a database: uninstall_rtpostgis.sql and
uninstall_postgis.sql.
The postgis_manager.sh script does not remove these PostGIS Raster
environment variables the greenplum_path.sh file:
GDAL_DATA, POSTGIS_ENABLE_OUTDB_RASTERS,
POSTGIS_GDAL_ENABLED_DRIVERS. The environment variables are removed
when you uninstall the PostGIS extension package with the gppkg utility.
PostGIS Extension Support and Limitations
This section describes Greenplum PostGIS extension feature support and limitations.
The Greenplum Database PostGIS extension does not support the following features:
- Topology
- Some Raster Functions
Supported PostGIS Data Types
Greenplum Database PostGIS extension supports these PostGIS data types:
- box2d
- box3d
- geometry
- geography
For a list of PostGIS data types, operators, and functions, see the PostGIS reference documentation.
Supported PostGIS Raster Data Types
Greenplum Database PostGIS supports these PostGIS Raster data types.
- geomval
- addbandarg
- rastbandarg
- raster
- reclassarg
- summarystats
- unionarg
For information about PostGIS Raster data Management, queries, and applications, see
https://postgis.net/docs/manual-2.5/using_raster_dataman.html.
For a list of PostGIS Raster data types, operators, and functions, see the PostGIS Raster reference documentation.
Supported PostGIS Index
Greenplum Database PostGIS extension supports the GiST (Generalized Search Tree)
index.
PostGIS Extension Limitations
This section lists the Greenplum Database PostGIS extension limitations for user-defined
functions (UDFs), data types, and aggregates.
- Data types and functions related to PostGIS topology functionality, such as
TopoGeometry, are not supported by Greenplum Database.
- These PostGIS aggregates are not supported by Greenplum Database:
On a Greenplum Database with multiple segments, the aggregate might return
different answers if it is called several times repeatedly.
-
Greenplum Database does not support PostGIS long transactions.
PostGIS relies on triggers and the PostGIS table
public.authorization_table for long transaction support. When
PostGIS attempts to acquire locks for long transactions, Greenplum Database reports
errors citing that the function cannot access the relation,
authorization_table.
- Greenplum Database does not support type modifiers for user defined types.
The work
around is to use the AddGeometryColumn function for PostGIS geometry.
For example, a table with PostGIS geometry cannot be created with the following SQL
command:CREATE TABLE geometries(id INTEGER, geom geometry(LINESTRING));Use
the AddGeometryColumn function to add PostGIS geometry to a table.
For example, these following SQL statements create a table and add PostGIS geometry to
the
table:CREATE TABLE geometries(id INTEGER);
SELECT AddGeometryColumn('public', 'geometries', 'geom', 0, 'LINESTRING', 2);
- The _postgis_index_extent function is not supported on Greenplum
Database 6 due to its dependence on spatial index operations.
- The <-> operator (geometry <->
geometry) returns the centroid/centroid distance for
Greenplum Database 6.
PostGIS Support Scripts
After installing the PostGIS extension package, you enable PostGIS support for each
database that requires its use. To enable or remove PostGIS support in your database, you
can run SQL scripts that are supplied with the PostGIS package in
$GPHOME/share/postgresql/contrib/postgis-2.5/.
Instead of running the scripts individually, you can use the
postgis_manager.sh script to run SQL scripts that enable or remove
PostGIS support. See .
You can run the PostGIS SQL scripts individually to enable or remove PostGIS support. For
example, these commands run the SQL scripts postgis.sql,
rtpostgis.sql, and spatial_ref_sys.sql in the database
mydatabase.
psql -d mydatabase -f
$GPHOME/share/postgresql/contrib/postgis-2.5/install/postgis.sql
psql -d mydatabase -f
$GPHOME/share/postgresql/contrib/postgis-2.5/install/rtpostgis.sql
psql -d mydatabase -f
$GPHOME/share/postgresql/contrib/postgis-2.5/install/spatial_ref_sys.sql
After running the scripts, the database is enabled with both PostGIS and PostGIS
Raster.
Scripts that Enable PostGIS and PostGIS Raster Support
These scripts enable PostGIS, and the optional PostGIS Raster in a database.
- install/postgis.sql - Load the PostGIS objects and function
definitions.
- install/rtpostgis.sql - Load the PostGIS raster
object and function definitions.
If you are installing PostGIS Raster, PostGIS objects must be installed before PostGIS
Raster. PostGIS Raster depends on PostGIS objects. Greenplum Database returns an error if
rtpostgis.sql is run before postgis.sql.
These SQL scripts add data and comments to a PostGIS enabled database.
- install/spatial_ref_sys.sql - Populate the
spatial_ref_sys table with a complete set of EPSG coordinate system
definition identifiers. With the definition identifiers you can perform
ST_Transform() operations on geometries.
If you have overridden standard entries and want to use those
overrides, do not load the spatial_ref_sys.sql file when creating
the new database.
- install/postgis_comments.sql - Add comments to the PostGIS
functions.
- install/raster_comments.sql - Add comments to the PostGIS Raster
functions.
You can view comments with the pslq meta-command \dd
function_name or from any tool that can show Greenplum
Database function comments.
PostGIS Raster Environment Variables
The postGIS package installation adds these lines to the
greenplum_path.sh file for PostGIS Raster support.
export GDAL_DATA=$GPHOME/share/gdal
export POSTGIS_ENABLE_OUTDB_RASTERS=0
export POSTGIS_GDAL_ENABLED_DRIVERS=DISABLE_ALL
GDAL_DATA specifies the location of GDAL utilities and support files
used by the GDAL library. For example, the directory contains EPSG support files such as
gcs.csv and pcs.csv (so called dictionaries, mostly
in CSV format). The GDAL library requires the support files to properly evaluate EPSG
codes.
POSTGIS_GDAL_ENABLED_DRIVERS sets the enabled GDAL drivers in the
PostGIS environment.
POSTGIS_ENABLE_OUTDB_RASTERS is a boolean configuration option to
enable access to out of database raster bands.
Scripts that Remove PostGIS and PostGIS Raster Support
To remove PostGIS support from a database, run SQL scripts that are supplied with the
PostGIS extension package in
$GPHOME/share/postgresql/contrib/postgis-2.5/
If you installed PostGIS Raster, you must uninstall PostGIS Raster before you
uninstall the PostGIS objects. PostGIS Raster depends on PostGIS objects. Greenplum
Database returns an error if PostGIS objects are removed before PostGIS Raster.
These scripts remove PostGIS and PostGIS Raster objects from a database.
- uninstall/uninstall_rtpostgis.sql - Removes the PostGIS Raster
object and function definitions.
- uninstall/uninstall_postgis.sql - Removes the PostGIS objects and
function definitions.
After PostGIS support has been removed from all databases in the Greenplum Database
system, you can remove the PostGIS extension package. For example this
gppkg command removes the PostGIS extension package.
gppkg -r postgis-2.5.4+pivotal.1
Restart Greenplum Database after removing the package.
gpstop -r
Ensure that these lines for PostGIS Raster support are removed from the
greenplum_path.sh file.
export GDAL_DATA=$GPHOME/share/gdal
export POSTGIS_ENABLE_OUTDB_RASTERS=0
export POSTGIS_GDAL_ENABLED_DRIVERS=DISABLE_ALL