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.
yum install postgis2_93. (where 93 refers to minor version of PostgreSQL you installed.
These instructions are for PostgreSQL 9.1 and higher, PostGIS 2.0 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:
-- Enable PostGIS (includes raster) CREATE EXTENSION postgis; -- Enable Topology CREATE EXTENSION postgis_topology; -- fuzzy matching needed for Tiger CREATE EXTENSION fuzzystrmatch; -- 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) ALTER EXTENSION postgis UPDATE TO "2.1.3"; -- Upgrade Topology ALTER EXTENSION postgis_topology UPDATE TO "2.1.3"; -- Upgrade US Tiger Geocoder ALTER EXTENSION postgis_tiger_geocoder UPDATE TO "2.1.3";
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 );