
Deploy PostGIS
Spatial PostgreSQL: PostGIS 3.7 on Postgres 18 with a volume and TLS
Just deployed
/var/lib/postgresql
Deploy and Host PostGIS on Railway
PostGIS is the open-source spatial extension for PostgreSQL. It adds geometry, geography and raster types, spatial indexes and hundreds of functions such as ST_Distance, ST_Intersects and ST_Transform, so you can store and query maps, routes, boundaries and locations with plain SQL. This template runs PostGIS 3.7 on PostgreSQL 18.
About Hosting PostGIS
Hosting PostGIS means running a PostgreSQL server with the PostGIS libraries (GEOS, PROJ, GDAL) installed, keeping its data directory on persistent storage, and creating the extensions in each database that needs them. This template builds the official postgis/postgis:18-3.7 image, pinned by digest, from a public GitHub repo. It keeps the data on a Railway volume, generates the superuser password at deploy time, and creates postgis, postgis_topology and postgis_raster on first boot in the default database and in template_postgis. Other services connect over the private network; a TCP proxy gives a public URL for desktop tools. TLS uses a self-signed certificate.
Common Use Cases
- Store and query locations, routes and boundaries for web and mobile apps (nearest store, delivery zones, geofences)
- Back a map or GIS stack such as QGIS, GeoServer, pg_tileserv, Martin or Django GeoDjango
- Load and analyse shapefiles, GeoJSON and rasters with ogr2ogr, raster2pgsql and spatial SQL
Dependencies for PostGIS Hosting
- A Railway volume for the PostgreSQL data directory (included)
- A PostgreSQL client or GIS tool to connect (psql, QGIS, DBeaver, an ORM)
Deployment Dependencies
- PostGIS documentation
- Official Docker image (postgis/docker-postgis)
- PostGIS releases
- Template repo (aalfath/postgis-railway-template)
Implementation Details
Connect another Railway service with a reference variable:
DATABASE_URL=${{PostGIS.DATABASE_URL}}
From your machine, copy DATABASE_PUBLIC_URL from the service's Variables tab:
psql "$DATABASE_PUBLIC_URL"
SELECT postgis_full_version();
CREATE TABLE places (id bigserial PRIMARY KEY, name text, geom geometry(Point, 4326));
CREATE INDEX ON places USING gist (geom);
CREATE DATABASE gis TEMPLATE template_postgis; -- a new database with PostGIS ready
The data lives at /var/lib/postgresql on the volume. Memory defaults (shared_buffers=512MB, maintenance_work_mem=256MB, work_mem=16MB) are set once with ALTER SYSTEM and can be changed later. Updates arrive as Railway "update available" notices when the repo's main branch changes; after a PostGIS minor update run SELECT postgis_extensions_upgrade(); in each spatial database. PostgreSQL major upgrades are never applied automatically. PostGIS 3.7 no longer ships the US Tiger geocoder.
Why Deploy PostGIS on Railway?
Railway is a singular platform to deploy your infrastructure stack. Railway will host your infrastructure so you don't have to deal with configuration, while allowing you to vertically and horizontally scale it.
By deploying PostGIS on Railway, you are one step closer to supporting a complete full-stack application with minimal burden. Host your servers, databases, AI agents, and more on Railway.
Template Content
