Deploy PostGIS | Open-Source Spatial Database on Railway
Self Host PostGIS: Spatial queries, topology, raster, routing ready
PostGIS
Just deployed
/var/lib/postgresql/data

Deploy and Host PostGIS on Railway
Deploy PostGIS on Railway to get a production-ready spatial database in minutes. PostGIS extends PostgreSQL with geographic object support, enabling spatial queries, coordinate transformations, topology analysis, and geometry processing — the foundation for any location-aware application.
This Railway template pre-configures a postgis/postgis:17-3.5 Docker container with PostgreSQL 17 and PostGIS 3.5, persistent volume storage, and a TCP proxy for external client connections.
Getting Started with PostGIS on Railway
After deployment completes, your PostGIS database is immediately accessible. Connect using any PostgreSQL client — pgAdmin, DBeaver, DataGrip, or psql — using the TCP proxy connection string from your Railway dashboard. The connection URL follows the format postgresql://postgis_admin:@:/postgis_db.
PostGIS extensions are pre-installed on the default database. Verify spatial capabilities by running:
SELECT PostGIS_Full_Version();
Create your first spatial table to start storing geographic data:
CREATE TABLE locations (
id SERIAL PRIMARY KEY,
name TEXT NOT NULL,
geom GEOMETRY(Point, 4326)
);
INSERT INTO locations (name, geom)
VALUES ('Railway HQ', ST_SetSRID(ST_MakePoint(-122.4194, 37.7749), 4326));
SELECT name, ST_AsText(geom) FROM locations;
About Hosting PostGIS
PostGIS is the most widely used open-source spatial database extension, adding hundreds of spatial functions to PostgreSQL. It implements the OGC Simple Features for SQL specification and is trusted by organizations from startups to government agencies for managing geographic data.
Key features:
- Spatial indexing — GiST and SP-GiST indexes for fast geographic queries on millions of records
- Geometry & geography types — Store points, lines, polygons, and complex geometries in native data types
- Coordinate reference systems — Built-in PROJ support for transformations between 8,000+ CRS definitions
- Topology support — Model shared boundaries and connectivity between spatial features
- Raster processing — Analyze gridded data (elevation, satellite imagery) alongside vector geometries
- Routing — Combine with pgRouting for shortest-path and network analysis
- Standards-compliant — OGC SFS, SQL/MM, GeoJSON, KML, WKT/WKB output formats
Why Deploy PostGIS on Railway
A production spatial database without infrastructure management:
- One-click deploy with persistent volume storage and TCP proxy
- PostgreSQL 17 with PostGIS 3.5 — latest stable versions
- Internal private networking for service-to-service connections
- External TCP proxy for client tools and remote applications
- Automatic container restarts on failure
- No vendor lock-in — standard PostgreSQL wire protocol
Common Use Cases for Self-Hosted PostGIS
- Location-based services — Store and query points of interest, geofences, and delivery zones for mobile and web apps
- Real estate and property tech — Spatial joins between parcels, zoning boundaries, flood zones, and property listings
- Environmental monitoring — Analyze sensor data, satellite imagery, deforestation tracking, and wildlife habitat mapping
- Fleet management and logistics — Route optimization, vehicle tracking, and delivery area calculations using pgRouting
Dependencies for PostGIS on Railway
- PostGIS —
postgis/postgis:17-3.5(PostgreSQL 17.5 + PostGIS 3.5.2 + GEOS 3.9.0 + PROJ 7.2.1)
Environment Variables Reference for PostGIS
| Variable | Value | Description |
|---|---|---|
POSTGRES_USER | postgis_admin | Database superuser name |
POSTGRES_PASSWORD | [generated] | Database password |
POSTGRES_DB | postgis_db | Default database with PostGIS |
PGDATA | /var/lib/postgresql/data/pgdata | Data directory (subdirectory of volume mount) |
Deployment Dependencies
- Runtime: Docker (
postgis/postgis:17-3.5) - Docker Hub: postgis/postgis
- GitHub: postgis/docker-postgis
- Official docs: postgis.net
Hardware Requirements for Self-Hosting PostGIS
| Resource | Minimum | Recommended |
|---|---|---|
| CPU | 1 core | 2+ cores |
| RAM | 256 MB | 1 GB+ |
| Storage | 1 GB | 10 GB+ (depends on spatial data volume) |
| Runtime | Docker | Docker |
PostGIS resource requirements scale with data volume and query complexity. Spatial joins on millions of records benefit significantly from additional RAM for caching and faster storage (SSD).
Self-Hosting PostGIS with Docker
Pull and run the official PostGIS image:
docker run -d \
--name postgis \
-e POSTGRES_USER=postgis_admin \
-e POSTGRES_PASSWORD=mysecretpassword \
-e POSTGRES_DB=postgis_db \
-e PGDATA=/var/lib/postgresql/data/pgdata \
-v postgis_data:/var/lib/postgresql/data \
-p 5432:5432 \
postgis/postgis:17-3.5
Or use Docker Compose:
services:
postgis:
image: postgis/postgis:17-3.5
environment:
POSTGRES_USER: postgis_admin
POSTGRES_PASSWORD: mysecretpassword
POSTGRES_DB: postgis_db
PGDATA: /var/lib/postgresql/data/pgdata
volumes:
- postgis_data:/var/lib/postgresql/data
ports:
- "5432:5432"
volumes:
postgis_data:
Connect and verify PostGIS is available:
psql -h localhost -U postgis_admin -d postgis_db \
-c "SELECT PostGIS_Version();"
Is PostGIS Free to Self-Host?
PostGIS is fully open-source under the GNU General Public License (GPL). There are no license fees, per-query charges, or usage limits. When deployed on Railway, you only pay for the infrastructure resources consumed (compute, storage, network egress). Managed PostGIS hosting alternatives like AcuGIS start at $12/month and Elestio at $14/month — self-hosting on Railway gives you full control at comparable or lower cost.
PostGIS vs MySQL Spatial vs MongoDB Geospatial
| Feature | PostGIS | MySQL Spatial | MongoDB Geospatial |
|---|---|---|---|
| Spatial functions | 300+ | ~30 | ~20 |
| Standards compliance | OGC SFS, SQL/MM | Partial OGC | GeoJSON only |
| Raster support | Yes | No | No |
| Topology | Yes | No | No |
| 3D support | Yes (Z/M coords) | No | No |
| Routing (pgRouting) | Yes | No | No |
| Index type | GiST, SP-GiST | R-tree | 2dsphere |
| License | GPL | GPL | SSPL |
PostGIS is the clear choice for applications needing advanced spatial analysis, standards compliance, or raster/topology support. MySQL Spatial and MongoDB Geospatial are adequate for simple proximity queries but lack depth for GIS workloads.
FAQ
What is PostGIS and why self-host it? PostGIS is an open-source spatial database extension for PostgreSQL that adds support for geographic objects, spatial queries, and coordinate transformations. Self-hosting gives you full control over your spatial data, eliminates per-query API costs from services like Mapbox or Google Maps Platform, and keeps sensitive location data on your own infrastructure.
What does this Railway template deploy? This template deploys a single PostGIS container running PostgreSQL 17 with PostGIS 3.5 extensions pre-installed. It includes persistent volume storage for your database files and a TCP proxy for external client connections. No additional services are needed — PostGIS is a self-contained spatial database.
Why is a volume required for PostGIS on Railway?
The volume persists your PostgreSQL data directory across container restarts and redeployments. Without a volume, all spatial data, tables, indexes, and user accounts would be lost every time the container restarts. The volume is mounted at /var/lib/postgresql/data with PGDATA set to a subdirectory to avoid conflicts with Railway's volume initialization.
How do I connect another Railway service to PostGIS?
Use Railway's internal networking. Set your application's database URL to postgresql://postgis_admin:@postgis.railway.internal:5432/postgis_db or use Railway's reference syntax: ${{PostGIS.DATABASE_URL}}. Internal connections don't incur network egress charges.
Can I use PostGIS with QGIS, GeoServer, or other GIS tools? Yes. PostGIS uses the standard PostgreSQL wire protocol, so any tool that connects to PostgreSQL can use PostGIS. Connect QGIS, GeoServer, MapServer, or any OGC-compliant client using the TCP proxy connection string from your Railway dashboard.
How do I import shapefiles or GeoJSON into self-hosted PostGIS?
Use shp2pgsql (included in the PostGIS container) for shapefiles or ogr2ogr (from GDAL) for GeoJSON, KML, and other formats. You can run these tools via railway ssh into the container or from a local machine pointing at the TCP proxy.
Template Content
PostGIS
postgis/postgis:17-3.5