Many blog posts deal with installing or upgrading PostGIS. Today we'll talk about upgrading related libraries such as GEOS or GDAL. Since PostGIS’ functionality stack relies heavily on these libraries, downloading current library versions is unavoidable; you want to use the latest stunning spatial features. Unfortunately, not all repositories serve PostGIS with the latest libraries. In our example, we'll upgrade GEOS with Ubuntu.
Table of Contents
A customer runs a PostgreSQL 14.5 database with PostGIS 3.2.3 installed under Ubuntu 20.04.4 LTS.
She wants to test ST_ReducePrecision
(https://postgis.net/docs/ST_ReducePrecision.html), a spatial function introduced in PostGIS 3.1.0. Unfortunately, this function requires at least GEOS 3.9.0.
Her system seems to be equipped with GEOS 3.8.0.
1 2 |
postgis_demo=# SELECT ST_AsText(ST_ReducePrecision('POINT(1.412 19.323)', 0.1)); ERROR: Precision reduction requires GEOS-3.9 or higher |
She needs to upgrade GEOS. Here are the 3 steps to do that:
As a reminder – to quickly assess which libraries have been installed in the system and particular database, execute the following commands from your psql console or preferred database client.
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)' |
Unfortunately, Ubuntu does not serve GEOS versions later than 3.8.0 through default repositories for 20.04. This implies building GEOS from source, or switching to another distribution channel-respective repository. For clarification – it’s not sufficient to update GEOS alone, PostGIS must also be rebuilt against the required GEOS.
First, install the necessary build requirements.
1 |
$> sudo apt-get install cmake clang libgeos-dev |
Continue by assessing the current geos-configuration with geos-config
to confirm the basis.
1 2 |
$> geos-config –version 3.8.0 |
Second, download and extract the latest source tar from the GEOS website - and finally, build and install GEOS.
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 |
Again, cross-check the geos-configuration with geos-config. It looks pretty good so far ????.
1 2 |
$> geos-config –version 3.11.0 |
Build requirements must first be installed to the system. The server in this example already runs PostgreSQL and therefore provides some of the needed dependencies. At this point I recommend taking a look at Chapter 2.2.2 of the PostGIS online documentation and subsequently assess your system to identify needed libraries and tools.
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++ |
Next, download and extract the PostGIS source tar and configure the build.
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 |
This results in a configuration message summarizing the upcoming build action, which I recommend you briefly look through. The upcoming listing only contains a subset of the information provided.
You might have noticed that I didn’t install build requirements for SFCGAL. The extensions section indicates this fact and disables SFCGAL support.
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 |
1 2 |
$> make PostGIS was built successfully. Ready to install. |
Finally, we install the binaries.
1 |
$> sudo make install |
Did the upgrade succeed? Let’s quickly check this via psql.
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) |
Unfortunately, calling postgis_full_version
does not tell the whole truth and does not guarantee that GEOS 3.11.0 is indeed utilized by PostGIS. I suggest re-running the test-query from the beginning to see the real difference.
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) |
TADA – it works as expected. Everybody should be happy. But wait – we didn’t even upgrade PostGIS on the database level. Isn’t that strange? No, because we didn’t change the PostGIS version. We stayed within PostGIS 3.2.3.
For folks who want to upgrade PostGIS and GEOS one after the other, just utilize postgis_extensions_upgrade()
on the database level after you build and install PostGIS. Learn more about upgrading PostGIS here.
In case you need support or have any questions, get in touch with the friendly folks at CYBERTEC. We would love to hear from you.
You need to load content from reCAPTCHA to submit the form. Please note that doing so will share data with third-party providers.
More InformationYou are currently viewing a placeholder content from Facebook. To access the actual content, click the button below. Please note that doing so will share data with third-party providers.
More InformationYou are currently viewing a placeholder content from X. To access the actual content, click the button below. Please note that doing so will share data with third-party providers.
More Information
Leave a Reply