GDAL with Full Database Support (PostgreSQL, Oracle, MSSQL, MySQL) on Rocky 9
GDAL with Full Database Support (PostgreSQL, Oracle, MSSQL, MySQL)
Geospatial professionals often rely on GDAL (Geospatial Data Abstraction Library) for seamless data conversion, spatial ETL processes, and interoperability across various formats and spatial databases. But when your workflows demand access to enterprise-grade databases like Oracle Spatial, SQL Server, PostgreSQL/PostGIS, and MySQL/MariaDB you’ll need a custom-built GDAL. This post walks you through the entire process of building GDAL from source on Rocky 9, with full support for:
- Oracle (OCI)
- PostgreSQL (PostGIS)
- SQL Server (ODBC/MSSQLSpatial)
- MySQL (MariaDB)
- SQLite / GeoTIFF / JPEG / PNG / PROJ and more

Install System Dependencies
Make sure your system has all the essential build tools and libraries:
dnf install -y \
git gcc-c++ make cmake wget unzip swig tar \
python3 python3-devel python3-numpy \
zlib-devel libdeflate-devel libzstd-devel openssl-devel curl-devel expat-devel \
libjpeg-devel libpng-devel libtiff-devel libgeotiff-devel \
proj-devel \
postgresql-devel \
sqlite-devel \
unixODBC-devel \
mariadb-connector-c-devel \
libxml2-devel xerces-c-devel \
libaio libaio-devel \
cryptopp-devel
Explanation
-----------
# Build tools
git gcc-c++ make cmake wget unzip swig tar \
python3 python3-devel python3-numpy \
# Basic libraries
zlib-devel libdeflate-devel libzstd-devel openssl-devel curl-devel expat-devel \
# Image and raster format support
libjpeg-devel libpng-devel libtiff-devel libgeotiff-devel \
# Geographic projection
proj-devel \
# Database drivers
postgresql-devel \
sqlite-devel \
unixODBC-devel \
mariadb-connector-c-devel \
# XML processing and configuration
libxml2-devel xerces-c-devel \
# Oracle Instant Client dependencies (Oracle .rpm files must be installed separately)
libaio libaio-devel \
# Optional cryptography support
cryptopp-devel
Install Oracle Instant Client
GDAL requires Oracle’s proprietary client libraries to enable OCI (Oracle Spatial) support.
dnf -y install https://download.oracle.com/otn_software/linux/instantclient/oracle-instantclient-basic-linuxx64.rpm
dnf -y install https://download.oracle.com/otn_software/linux/instantclient/oracle-instantclient-devel-linuxx64.rpm
For version-specific setups, adjust 23 accordingly in paths later.
Install Microsoft SQL Server ODBC Driver
To enable MSSQLSpatial and ODBC drivers:
curl https://packages.microsoft.com/config/rhel/9/prod.repo -o /etc/yum.repos.d/mssql-release.repo
ACCEPT_EULA=Y dnf install -y msodbcsql17
Set Oracle Environment Variables
echo 'export LD_LIBRARY_PATH=/usr/lib/oracle/23/client64/lib:$LD_LIBRARY_PATH' > /etc/profile.d/oracle.sh
chmod +x /etc/profile.d/oracle.sh
source /etc/profile.d/oracle.sh
ldconfig
export LD_LIBRARY_PATH=/usr/local/src/gdal-3.11.3/build:$LD_LIBRARY_PATH
Build GDAL from Source with Full Driver Support
Download GDAL
cd /usr/local/src
wget https://download.osgeo.org/gdal/3.11.3/gdal-3.11.3.tar.gz
tar xzf gdal-3.11.3.tar.gz
cd gdal-3.11.3
mkdir build && cd build
Configure with CMake
cmake .. \
-DCMAKE_BUILD_TYPE=Release \
-DBUILD_SHARED_LIBS=ON \
-DCMAKE_INSTALL_PREFIX=/usr/local/gdal-oracle \
-DGDAL_USE_POSTGRESQL=ON \
-DPOSTGRESQL_INCLUDE_DIR=/usr/include/pgsql \
-DPOSTGRESQL_LIBRARY=/usr/lib64/libpq.so \
-DGDAL_USE_MSSQLSPATIAL=ON \
-DODBC_INCLUDE_DIR=/usr/include \
-DODBC_LIBRARY=/usr/lib64/libodbc.so \
-DOGR_ENABLE_DRIVER_OCI=ON \
-DOGR_BUILD_OCI=ON \
-DOracle_INCLUDE_DIR=/usr/include/oracle/23/client64 \
-DOracle_LIBRARY=/usr/lib/oracle/23/client64/lib/libclntsh.so \
-DGDAL_ENABLE_DRIVER_MYSQL=ON \
-DMYSQL_INCLUDE_DIR=/usr/include/mysql \
-DMYSQL_LIBRARY=/usr/lib64/libmariadb.so \
-DGDAL_USE_SQLITE3=ON \
-DGDAL_USE_GEOTIFF=ON \
-DGDAL_USE_CURL=ON \
-DGDAL_USE_PNG=ON \
-DGDAL_USE_JPEG=ON \
-DGDAL_USE_EXPAT=ON \
-DGDAL_USE_LIBZ=ON \
-DGDAL_USE_PROJ=ON
Confirm Support
Make sure your CMake output includes:
Oracle support: yes
OCI driver enabled
PostgreSQL support: yes
MSSQL (ODBC) support: yes
MySQL support: yes
If Oracle support: no, double-check the paths to oci.h and libclntsh.so.
Compile and Install
make -j$(nproc)
make install
ldconfig
Set Runtime PATH
echo 'export PATH=/usr/local/gdal-oracle/bin:$PATH' >> ~/.bashrc
echo 'export LD_LIBRARY_PATH=/usr/local/gdal-oracle/lib:$LD_LIBRARY_PATH' >> ~/.bashrc
source ~/.bashrc
Verify Installed Drivers
ogrinfo --formats | grep -E "OCI|PostgreSQL|ODBC|MySQL|SQLite|GeoTIFF|MSSQL"
You should see output like:
SQLite -vector- (rw+uv): SQLite / Spatialite
ODBC -vector- (ro): Open Database Connectivity
MSSQLSpatial -vector- (rw+u): Microsoft SQL Server Spatial
PostgreSQL -vector- (rw+u): PostgreSQL/PostGIS
MySQL -vector- (rw+u): MySQL
OCI -vector- (rw+u): Oracle Spatial
Example: Convert Oracle Spatial to PostGIS
Export from Oracle
ogr2ogr -f GeoJSON STREETS.json \
OCI:TEST/test@**.**.**.**:1907/Servisname \
-sql "SELECT * FROM TEST.STREETS WHERE rownum < 10000"
Import into PostgreSQL
ogr2ogr -f "PostgreSQL" PG:"host=**.**.**.** port=1907 dbname=gis_db user=etl_user password=test123" \
STREETS.json \
-nln streets \
-lco FID=objectid \
-lco GEOMETRY_NAME=geom \
-a_srs "EPSG:5254"
Bonus: Convert Esri ST_Geometry to PostGIS
Some Oracle Spatial tables store geometries in Esri’s ST_Geometry format. You can convert them using:
ogr2ogr -f GeoJSON ANADOLU.json \
OCI:TEST/test@exa3-scan.ibb.gov.tr:1472/PUBCBS \
-sql "SELECT OBJECTID, ..., sdo_util.from_wktgeometry(sde.st_astext(shape)) AS SHAPE_SDO FROM TEST.ANADOLU"
Then import as usual into PostGIS:
ogr2ogr -f "PostgreSQL" PG:"host=**.***.**.** port=1907 dbname=gis_db user=etl_user password=test123" \
ANADOLU.json \
-nln anadolu \
-lco FID=objectid \
-lco GEOMETRY_NAME=geom \
-a_srs "EPSG:5254"
Building GDAL from source might sound like a headache, but it unlocks full potential across Oracle Spatial, PostGIS, MSSQL, MySQL, and more — giving you full control and compatibility.
← PostgreSQL Blog