# dnf list installed | grep postgresql
VRTSnbpostgresqlagent.x86_64 9.1.0.0-1620848511 @System
postgresql.x86_64 10.17-2.module+el8.5.0+11838+8dca950a @rhel8-appstream
postgresql-server.x86_64 10.17-2.module+el8.5.0+11838+8dca950a @rhel8-appstream
postgresql10.x86_64 10.22-1PGDG.rhel8 @rhel8-pgdg10
postgresql10-contrib.x86_64 10.22-1PGDG.rhel8 @rhel8-pgdg10
postgresql10-libs.x86_64 10.22-1PGDG.rhel8 @rhel8-pgdg10
postgresql10-server.x86_64 10.22-1PGDG.rhel8 @rhel8-pgdg10
# dnf list installed | grep postgis
postgis31_10.x86_64 3.1.7-1.rhel8 @rhel8-pgdg10
postgis31_10-client.x86_64 3.1.7-1.rhel8 @rhel8-pgdg10
postgis31_10-devel.x86_64 3.1.7-1.rhel8 @@commandline
postgis31_10-utils.x86_64 3.1.7-1.rhel8 @@commandline
(My colleague manually downloaded those latter two packages from... somewhere)
When we try to CREATE EXTENSION postgis; we get the following error
ERROR: could not access file "$libdir/postgis-3": No such file or directory
Our PostgreSQL installation location in /usr/pgsql-10/ and inside /usr/pgsql-10/lib are the .so files for the extension (e.g. postgis-3.so). Inside /usr/pgsql-10/share/extension are postgis*.control files which contain:
# postgis extension
comment = 'PostGIS geometry and geography spatial types and functions'
default_version = '3.1.7'
module_pathname = '$libdir/postgis-3'
relocatable = false
When I tried adding a libdir=/usr/pgsql-10/lib line to the file the error was ERROR: unrecognized parameter "libdir" in file "/usr/share/pgsql/extension/postgis.control" but when we replaced the path in module_pathname to include /usr/pgsql-10/lib we just got the same error as before ERROR: could not access file "$libdir/postgis-3": No such file or directory. Also tried installing other non-PostGIS extensions and got similar could not access "$libdir/extension" errors.
This server is managed by our IT who helped install some of the postgis packages so I'm not sure if there's somehow a package universe mismatch here.
Some further context after reading this answer, the PostgreSQL data directory is mounted at a different location for space reasons (/pgdata), so maybe something got missed in that configuration change?