Maps with PostgreSQL and PostGIS
PostGIS can generate Mapbox vector tiles directly, so a browser map needs only PostgreSQL/PostGIS, a thin tile server (pg_tileserv) and a Leaflet frontend, with no heavy tiling middleware. The stack runs on Kubernetes: Zalando's Postgres Operator provisions an HA cluster with the PostGIS extension, roles and schemas from a short manifest, and pg_tileserv is deployed with a ConfigMap-mounted TOML config behind an OAuth proxy. Beyond serving tables, SQL function layers built on ST_TileEnvelope, ST_HexagonGrid and ST_AsMVT can produce dynamic hexagon heatmaps (here joined against Geostat population data) whose resolution adapts to the zoom level.
Related posts
- Generate Vector Tiles with PostGIS
Supabase mediumAdeptPostGIS can generate Mapbox Vector Tiles on demand from Postgres rows, so a MapLibre GL client can render large point datasets while transferring only the data for the current viewport and zoom level. The pipeline downloads Overture Maps places as GeoJSON, converts them to SQL with GDAL ogr2ogr, and imports them into Supabase with psql. A plpgsql `mvt(z,x,y)` function then uses ST_TileEnvelope, ST_AsMVTGeom and ST_AsMVT to return base64-encoded tiles. A custom MapLibre `addProtocol` handler calls that function through supabase-js RPC. Payloads stay small because names and ids are included only above zoom 13, and detailed metadata is fetched on click instead of being encoded in the tiles.
- Geo Queries with PostGIS in Ionic Angular
Supabase mediumAdeptPostGIS on Supabase handles geo data for an Ionic Angular app with a Capacitor Google Map. A stores table holds geography(POINT) locations behind a GIST spatial index. Two SQL functions do the geo queries: nearby_stores orders stores by the <-> distance operator and returns st_distance in meters, and stores_in_view filters with && against an ST_MakeBox2D bounding box. The app calls them via Supabase RPC, inserts locations as WKT POINT(long lat) strings, uploads store images to Supabase Storage, and covers the native location permissions and API keys needed for iOS and Android.
- Postgres Realtime location sharing with MapLibre
Supabase mediumAdeptLive location sharing is built by having a Telegram bot running in a Supabase Edge Function (grammY on Deno) capture edited-location updates and write them to Postgres through a PL/pgSQL RPC. The RPC looks up the user's active session and stores the coordinates as a PostGIS point. A React/Next.js client subscribes to Supabase Realtime postgres_changes INSERT events, filtered by event_id, and renders markers with react-map-gl and MapLibre GL JS over a Protomaps basemap served from Supabase Storage.
- Hosting Postgres with GeoLite2: a practical guide to IP geolocation, data loading, and updates
Railway mediumAdeptLoading MaxMind's GeoLite2 CSVs into Postgres pays off over the MMDB binary format when you need SQL joins, batch geolocation of many IPs, queries over the ranges themselves, or one copy shared across services; for simple single-IP lookups MMDB is easier. Three deployment options are covered: a docker-entrypoint-initdb.d script that downloads and COPYs the data, a custom image with the data baked in, and a scheduled loader service for updates. Lookups use the cidr `>>=` operator backed by a GiST inet_ops index, which keeps queries under 10ms. Recommended practice is weekly refreshes to match MaxMind's Tuesday releases, loading into new tables and swapping them via renames in a transaction, with roughly 500-600 MB of storage for all three databases and a ~200 MB City index that should fit in shared_buffers.
- postgres.new: In-browser Postgres with an AI interface
Supabase mediumAdeptdatabase.build (formerly postgres.new) runs unlimited Postgres databases entirely in the browser via PGlite, a WASM build of Postgres, paired with GPT-4o that has full autonomy over the disposable database. The LLM imports CSVs, generates Chart.js charts, builds ER diagrams from real DDL, and does in-browser semantic search using pgvector and Transformers.js. SQL errors are fed back to the model so it can self-correct, and embeddings are stored in a meta table and referenced by ID to avoid sending large vectors to the model. PGlite relies on Postgres's single-user mode plus wire protocol support, a /dev/blob virtual device for COPY, and IndexedDB/OPFS persistence. A new TypeScript library, pg-gateway, handles the startup/auth handshake so standard Postgres clients can connect to PGlite deployments.