Databases 6 min read

How to Add PostGIS Extension to Kingbase: A Step‑by‑Step Docker Guide

This guide explains how to integrate the PostGIS spatial extension into a Kingbase database running in Docker, covering prerequisite communication with support, extracting the extension files, copying necessary binaries, restarting the container, and verifying the installation with sample queries.

Dunmao Tech Hub
Dunmao Tech Hub
Dunmao Tech Hub
How to Add PostGIS Extension to Kingbase: A Step‑by‑Step Docker Guide

Introduction

The PostGIS extension adds geographic and spatial capabilities to PostgreSQL‑compatible databases, enabling storage and analysis of points, lines, polygons, and trajectories, as well as distance calculations and spatial queries. This article shows how to integrate PostGIS into a Kingbase database, which follows the PostgreSQL model.

What Is PostGIS?

PostGIS extends PostgreSQL with spatial data types (point, line, polygon, etc.) and functions for distance computation, area queries, spatial intersections, and map overlay operations, making it the most widely used open‑source spatial database extension for GIS development.

Environment Preparation

Contact Kingbase Support

Kingbase does not provide a public download page for extensions, so you must request the appropriate PostGIS package from official support. Provide the exact Kingbase version (e.g., v008r006c009b0014 ) and CPU architecture (e.g., X86 ). If using Docker, verify the version from the image.

Installation Steps

1. Unzip the Extension

After receiving the compressed PostGIS package, extract it into a persistent directory mounted into the Docker container, such as /mnt/data/postgis. The extraction creates a folder like postgis-3.1.2.

2. Copy Extension Files

Enter the running Kingbase container: docker exec -it kingbase /bin/bash Inside the container, three key directories exist under the Kingbase installation: bin , lib , and share/extension . Copy the corresponding files from the extracted PostGIS folder into these directories:

# Copy bin files
cp ./userdata/postgis/postgis-3.1.2/bin/* ./install/kingbase/bin/

# Copy lib files
cp ./userdata/postgis/postgis-3.1.2/lib/* ./install/kingbase/lib/

# Copy extension files
cp ./userdata/postgis/postgis-3.1.2/share/extension/* ./install/kingbase/share/extension/

If any files already exist, you may overwrite them or skip as appropriate.

3. Restart the Container

Restart the Docker container (or the database service inside it) to load the new libraries: docker restart kingbase Then connect to the target database using Kingbase’s ksql client:

ksql -d your_database_name

4. Create the Extension

Run the following SQL command to enable PostGIS in the selected database: CREATE EXTENSION IF NOT EXISTS postgis; If the extension is already installed, the command reports that it exists; otherwise it creates the extension successfully.

5. Verify with a Sample Query

Example: compute the geographic distance between Tiananmen Square (Beijing) and the Bund (Shanghai):

SELECT ST_Distance(
    ST_SetSRID(ST_MakePoint(116.403874, 39.914885), 4326)::geography,
    ST_SetSRID(ST_MakePoint(121.473701, 31.230416), 4326)::geography
) AS distance_m;

The query returns a numeric distance in meters; a successful execution without errors confirms that PostGIS is active.

Conclusion

By unzipping the PostGIS package, copying its binaries, libraries, and extension files into the Kingbase installation, and restarting the container, you can enable full spatial functionality in Kingbase. This greatly simplifies GIS‑related development on platforms that already recommend Kingbase as their primary database.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

DockerdatabasePostGISKingbaseSpatial
Dunmao Tech Hub
Written by

Dunmao Tech Hub

Sharing selected technical articles synced from CSDN. Follow us on CSDN: Dunmao.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.