PostGIS has many packaged installations, but if you are more adventurous and want to compile your own, refer to our source download and compilation instructions:
Binary distributions of PostGIS are available for various operating systems.
BigSQL distribution includes versions for MacOSX. It generally has latest version of PostGIS and ogrfdw.
The EnterpriseDb OSX PostgreSQL combination from EnterpriseDB includes generally latest stable minor version of PostGIS.
The builds from KyngChaos are a little dated but useful for older PostGIS versions. Read the instructions carefully. Do not mix with other installations.
yum install postgis2_93. (where 93 refers to minor version of PostgreSQL you installed.
BigSQL - Supports 64-bit for Linux (RedHat, Debian), MacOSX 64-bit, and Windows 64-bit. It generally has latest version of PostGIS and ogrfdw for all OS supported. As such, it’s ideal if you have users on different OS and want a consistent set of PostGIS related features for all. Refer to BigSQL: PostGIS Install and BigSQL: How to create a Spatial Database for PostGIS specific install instructions.
EnterpriseDb PostgreSQL - Supports 32-bit/64-bit Linux, MacOSX, Windows Note that the MacOSX PostGIS package and EDB Windows PostGIS package have different maintainers, so offerings are not equivalent. Both versions generally have latest minor version of PostGIS, but versions of libraries used may be different, other PostGIS related extensions like pgRouting, postgis_sfcgal are packaged with the windows but not OSX version.
These instructions are for PostgreSQL 9.1 and higher, PostGIS 2.2 and higher that is compiled with raster support. Note: if you have postgis, without raster support, you can not use CREATE EXTENSION. Refer to PostGIS install.
PostGIS is an optional extension that must be enabled in each database you want to use it in before you can use it. Installing the software is just the first step.
DO NOT INSTALL it in the database called
Connect to your database with
psql or PgAdmin. Run the following SQL.
You need only install the features you want:
-- Enable PostGIS (includes raster) CREATE EXTENSION postgis; -- Enable Topology CREATE EXTENSION postgis_topology; -- Enable PostGIS Advanced 3D -- and other geoprocessing algorithms -- sfcgal not available with all distributions CREATE EXTENSION postgis_sfcgal; -- fuzzy matching needed for Tiger CREATE EXTENSION fuzzystrmatch; -- rule based standardizer CREATE EXTENSION address_standardizer; -- example rule data set CREATE EXTENSION address_standardizer_data_us; -- Enable US Tiger Geocoder CREATE EXTENSION postgis_tiger_geocoder;
To upgrade PostGIS, you first have to install the latest binaries and then upgrade each database you have PostGIS installed in
For example connect to database you want to upgrade and if you just installed binaries for 2.1.3 You can upgrade from 2.0 to 2.1, 2.2 et.c using this approach. To go from 1.* to 2.* you need to do a hard upgrade. Refer to PostGIS install for more extensive instructions. Note: that as of PostGIS 2.1.3 and PostGIS 2.0.6, you need to set environment variables to get full features.
-- Upgrade PostGIS (includes raster) to latest version ALTER EXTENSION postgis UPDATE; ALTER EXTENSION postgis_topology UPDATE;
or to a specific version
-- Upgrade PostGIS (includes raster) ALTER EXTENSION postgis UPDATE TO "2.4.2"; -- Upgrade Topology ALTER EXTENSION postgis_topology UPDATE TO "2.4.2"; -- Upgrade US Tiger Geocoder ALTER EXTENSION postgis_tiger_geocoder UPDATE TO "2.4.2";
See the documentation for more guidance.
-- Create table with spatial column CREATE TABLE mytable ( id SERIAL PRIMARY KEY, geom GEOMETRY(Point, 26910), name VARCHAR(128) ); -- Add a spatial index CREATE INDEX mytable_gix ON mytable USING GIST (geom); -- Add a point INSERT INTO mytable (geom) VALUES ( ST_GeomFromText('POINT(0 0)', 26910) ); -- Query for nearby points SELECT id, name FROM mytable WHERE ST_DWithin( geom, ST_GeomFromText('POINT(0 0)', 26910), 1000 );