Skip to content
In this postPostgreSQL

PostGIS is here: geospatial queries on Layerbase Cloud PostgreSQL

4 min readPostgreSQLLayerbaseDatabases

PostgreSQL 18 databases on Layerbase Cloud can now run PostGIS, the extension that turns Postgres into a geospatial database: points, lines and polygons as column types, spatial indexes, and hundreds of ST_ functions for distance, area, containment and coordinate transforms. "Cafes within 2 km of this user", "which delivery zone is this address in", and "tiles for this map viewport" become plain SQL queries against the database you already have.

It is opt-in for each database, it is on every plan including Free, and turning it on does not restart anything. Here is how to enable it, a worked example you can paste, and exactly what ships.

Turn it on

There are two ways, and they do the same thing.

From the dashboard. Open the database, click the Extensions tab, and click Enable next to PostGIS. The switch only appears on a database whose PostgreSQL build carries PostGIS, so you never see an option that would fail.

With SQL. Connect with your usual client and run:

sql
CREATE EXTENSION IF NOT EXISTS postgis;

Either way, nothing restarts and nothing is preloaded. A database that never enables PostGIS pays nothing for it: no extra memory, no background worker, no change to its startup.

To check what you got:

sql
SELECT postgis_lib_version(), postgis_geos_version(), postgis_proj_version();

On PostgreSQL 18 that reports PostGIS 3.6.4 with GEOS 3.14.1 and PROJ 9.8.1.

A worked example: cafes near me

Say the database is called places and you want the cafes within walking distance of a user in downtown Austin. Create a table with a geography column (distances in meters on the real globe, no projection math required), add a few rows, and index it:

sql
CREATE EXTENSION IF NOT EXISTS postgis;

CREATE TABLE cafes (
  id serial PRIMARY KEY,
  name text NOT NULL,
  location geography(Point, 4326) NOT NULL
);

INSERT INTO cafes (name, location) VALUES
  ('Bennu Coffee',       ST_Point(-97.7179, 30.2862, 4326)),
  ('Houndstooth Coffee', ST_Point(-97.7421, 30.2692, 4326)),
  ('Merit Coffee',       ST_Point(-97.7389, 30.2613, 4326)),
  ('Epoch Coffee',       ST_Point(-97.7272, 30.3184, 4326));

CREATE INDEX cafes_location_idx ON cafes USING gist (location);

ST_Point takes longitude first, then latitude. That order trips up almost everyone once.

Now ask for everything within 2,000 meters of the user, nearest first:

sql
SELECT name,
       round(ST_Distance(location, ST_Point(-97.7431, 30.2672, 4326)::geography)) AS meters
FROM cafes
WHERE ST_DWithin(location, ST_Point(-97.7431, 30.2672, 4326)::geography, 2000)
ORDER BY meters;
text
        name        | meters
--------------------+--------
 Houndstooth Coffee |    242
 Merit Coffee       |    769

ST_DWithin is the part that matters for speed: it uses the GiST index, so the query stays fast with a million cafes instead of four. ST_Distance alone would compute the distance to every row.

Two more things you will reach for. GeoJSON for a web map:

sql
SELECT ST_AsGeoJSON(location::geometry) FROM cafes WHERE name = 'Merit Coffee';
text
{"type":"Point","coordinates":[-97.7389,30.2613]}

And Web Mercator coordinates, the projection most tile maps use:

sql
SELECT ST_AsText(ST_Transform(location::geometry, 3857))
FROM cafes WHERE name = 'Merit Coffee';
text
POINT(-10880244.578694686 3537181.9354353915)

We ran every query above on a Layerbase Cloud database before publishing this, and the output is copied from it.

What ships, and what does not

Layerbase runs core PostGIS:

  • geometry and geography types, GiST and SP-GiST indexes, and the full set of ST_ functions for measurement, relationships, processing and output.
  • Coordinate transforms with ST_Transform (PROJ 9.8.1), including the common pairs such as WGS 84 to Web Mercator or to UTM zones.
  • Vector tiles with ST_AsMVT, plus GeoJSON, WKT, WKB and KML input and output.

These parts of the PostGIS project are not included:

  • postgis_raster (and GDAL), postgis_topology, postgis_tiger_geocoder, address_standardizer and postgis_sfcgal.
  • Datum shifts that need PROJ grid files. PROJ runs without network access and without the grid downloads, so transforms that depend on a shift grid fall back to less precise methods or fail. Ordinary transforms between common coordinate systems are unaffected.

If you import a database that uses one of the excluded components, the migration report names it, so you know before you cut over rather than after.

PostgreSQL 19 beta

Databases on the current PostgreSQL 19 beta (beta 3) get PostGIS too, at version 3.7.0rc2. That is a release candidate, because no released PostGIS supports PostgreSQL 19 yet, running on a beta server. It is fine for trying things out; keep production data on PostgreSQL 18. When PostgreSQL 19 reaches general availability, it ships with the final PostGIS 3.7 release, and beta databases move by dump and restore, which creates the extension fresh at the final version.

Turning it off

Click Disable in the Extensions tab, or run DROP EXTENSION postgis;. Layerbase never cascades the drop: while a table still has a geometry or geography column, the drop is refused and the tab shows which objects are in the way. Drop or change those first, then disable.

Backups, sleep and restores

PostGIS data is ordinary table data to the rest of the platform. Backups include it, restores bring back the rows and the spatial indexes, and a database that sleeps when idle wakes with PostGIS intact. We tested each of those paths on real databases, and checked every Layerbase server for the same PostGIS build, before turning it on.

Try it

Open a PostgreSQL 18 database in the dashboard, go to Extensions, and enable PostGIS, or run CREATE EXTENSION postgis; from any client. The full reference, including what is excluded and how to enable it with SQL, is at /docs/extensions.

FAQ

Which Layerbase databases support PostGIS?

PostgreSQL 18 databases on the current release (18.6) on Layerbase Cloud, on every plan including Free, and databases on the current PostgreSQL 19 beta get the PostGIS 3.7 release candidate. The Extensions tab shows the PostGIS switch only where the build carries it; if your database is on an older version, the tab says so, and support can move it.

Does enabling PostGIS restart my database or cost anything?

No. PostGIS needs no preload, so enabling it runs one CREATE EXTENSION and nothing restarts. It is included in every plan; storage used by spatial data counts like any other data.

Is pgvector available too?

Not yet. PostGIS is available today; pgvector is not.