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.
Homebrew users can just run “brew install postgis” and tends to be a favorite for more advanced users since there are brew scripts for most of the popular PostgreSQL extensions, not always present in other Mac distributions.
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.
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 (as of 3.0 contains just geometry/geography) CREATE EXTENSION postgis; -- enable raster support (for 3+) CREATE EXTENSION postgis_raster; -- 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 "3.1.0"; -- Upgrade Topology ALTER EXTENSION postgis_topology UPDATE TO "3.1.0"; -- Upgrade US Tiger Geocoder ALTER EXTENSION postgis_tiger_geocoder UPDATE TO "3.1.0";
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 );