When PostGIS Needs a Newer GEOS

PostGIS leans heavily on underlying libraries like GEOS and GDAL, and the versions shipped in default OS repositories often lag behind what the latest spatial functions require. A customer recently hit this wall: PostgreSQL 14.5 with PostGIS 3.2.3 on Ubuntu 20.04.4 LTS, and a desire to test ST_ReducePrecision—a function available since PostGIS 3.1.0 but needing GEOS 3.9.0 or newer. The system had GEOS 3.8.0.

Verifying the installed versions from a psql session is the typical starting point.

PgSQL

1

2

3

4

5

6

7

8

9

postgres=# c postgis_demo

postgis_demo=# select postgis_full_version();

postgis_full_version

--------------------------------------------------------------------------

POSTGIS='3.2.3 2f97b6c' [EXTENSION] PGSQL='140' GEOS='3.8.0-CAPI-1.13.1'

PROJ='6.3.1' LIBXML='2.9.10' LIBJSON='0.13.1' LIBPROTOBUF='1.3.3' WAGYU=

'0.5.0 (Internal)'

The check confirmed the problem. Ubuntu 20.04's default repositories don't carry GEOS beyond 3.8.0, which means building GEOS from source—and also rebuilding PostGIS against it. Updating GEOS alone isn't enough; the two must be compiled in tandem.

Step 1: Build GEOS From Source

Start with the build prerequisites.

PgSQL

1

$> sudo apt-get install cmake clang libgeos-dev

Then confirm the current state of geos-config to establish a baseline before touching anything.

PgSQL

1

2

$> geos-config –version

3.8.0

Download the latest GEOS source tarball, extract it, and run the standard build-and-install sequence.

PgSQL

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

$> wget https://download.osgeo.org/geos/geos-3.11.0.tar.bz2

$> tar xvfj geos-3.11.0.tar.bz2

$> cd geos-3.11

$> mkdir build

$> cd build

# Set up the build

$> cmake

    -DCMAKE_BUILD_TYPE=Release

    -DCMAKE_INSTALL_PREFIX=/usr/local

    ..

$> make

$> ctest

$> sudo make install

Checking geos-config again shows the new version in place.

PgSQL

1

2

$> geos-config –version

3.11.0

Step 2: Rebuild PostGIS Against the New GEOS

PostGIS has its own build dependencies. The PostgreSQL server already running on the system provides several of these, so inspect Chapter 2.2.2 of the PostGIS installation docs and audit your machine for what's missing.

PgSQL

1

2

3

$> sudo apt-get install postgresql-server-dev-14 gcc libxml2 xsltproc

libprotobuf-c-dev protobuf-c-compiler libxml2-dev libproj-dev

libgdal-dev g++

After fetching and unpacking the PostGIS source, configure the build. The resulting summary lists what will be compiled or omitted—it's worth a quick read. In this case, SFCGAL support was disabled because its build requirements weren't installed, a detail the configuration output makes clear.

PgSQL

1

2

3

4

5

6

7

$> wget https://download.osgeo.org/postgis/source/postgis-3.2.3.tar.gz

$> tar xvzf postgis-3.2.3.tar.gz

$> cd postgis-3.2.3

$> ./configure

PgSQL

1

2

3

4

5

6

7

8

9

10

11

12

  PostGIS is now configured for x86_64-pc-linux-gnu

 -------------- Dependencies --------------

  GEOS config:          /usr/local/bin/geos-config

  GEOS version:         3.11.0

  GDAL config:          /usr/bin/gdal-config

  GDAL version:         3.0.4

  PostgreSQL config:    /usr/bin/pg_config

 --------------- Extensions ---------------

  PostGIS Raster:                     enabled

  PostGIS Topology:                   enabled

  SFCGAL support:                     disabled

  Address Standardizer support:       enabled

The compilation step takes a while.

PgSQL

1

2

$> make

PostGIS was built successfully. Ready to install.

Finally, install the compiled binaries.

PgSQL

1

$> sudo make install

Step 3: Verify the Upgrade in the Database

The final check runs back in psql.

PgSQL

1

2

3

4

5

6

7

8

9

10

11

12

postgres=# c postgis_demo

postgis_demo=# select postgis_full_version();

postgis_full_version

--------------------------------------------------------------------------

POSTGIS='3.2.3 2f97b6c' [EXTENSION] PGSQL='140' GEOS='3.11.0-CAPI-1.17.0'

PROJ='6.3.1' LIBXML='2.9.10' LIBJSON='0.13.1' LIBPROTOBUF='1.3.3' WAGYU=

'0.5.0 (Internal)'

(1 Zeile)

postgis_full_version reports the library versions, but it doesn't guarantee which GEOS is actually being used at runtime. Re-running the original failing query—ST_ReducePrecision on the customer's data—is the definitive test.

PgSQL

1

2

3

4

5

6

postgis_demo=# SELECT ST_AsText(ST_ReducePrecision('POINT(1.412 19.323)', 0.1));

    st_astext

-----------------

 POINT(1.4 19.3)

(1 Zeile)

It works. Note that the PostGIS version on the database itself didn't change: the version stayed at 3.2.3, which is why no database-level upgrade was necessary. If you're also bumping the PostGIS version, run postgis_extensions_upgrade() after installing the new binaries to sync the database extensions.