Foreign data wrappers
GanosBase Foreign Data Wrapper (FDW) is a spatial-temporal extension for PolarDB for PostgreSQL (Compatible with Oracle) that maps external geospatial files to foreign tables in your database. Once mapped, you query external data with standard SQL — no ETL pipeline required.
With GanosBase FDW, you can:
-
Query external geospatial files (shapefile, GeoJSON, KML, GML, MapInfo) directly from your database
-
Run spatial analysis, spatial queries, and buffer analysis against external data using PostgreSQL's geospatial functions
-
Write INSERT, UPDATE, and DELETE operations back to supported external sources
-
Import data into local tables with a single
CREATE TABLE AS SELECTstatement
For the full SQL reference, see FDW SQL reference.
How it works
GanosBase FDW follows the standard PostgreSQL Foreign Data Wrapper specification. The extension sits between your database and external data sources:
-
A foreign server defines the connection to an external data source (such as a file on Object Storage Service (OSS)).
-
A user mapping provides the credentials (AccessKey ID and AccessKey secret) for accessing the external source.
-
A foreign table maps the external data schema to columns in your database.
When you query a foreign table, GanosBase FDW fetches data from the external source, applies predicate pushdown and local query optimization where possible, and returns results as if the data were in a local table.
Quick start
This section shows the fastest path to querying a geospatial file. Use the Advanced configuration section if you need full control over the foreign server, user mapping, and foreign table definitions.
Prerequisites
Before you begin, make sure you have:
-
A PolarDB for PostgreSQL (Compatible with Oracle) cluster
-
A geospatial file (such as a shapefile) stored in an OSS bucket in the same region as your cluster
-
The AccessKey ID and AccessKey secret for accessing the OSS bucket
Install and register
-
Install the
ganos_fdwextension:CREATE EXTENSION ganos_fdw WITH SCHEMA public CASCADE;Install into the
publicschema to avoid permission issues. -
Register a geospatial file as a foreign table using
ST_RegForeignTables:-- Register a shapefile stored in OSS as a foreign table SELECT ST_RegForeignTables('OSS://<AccessKey_ID>:<AccessKey_secret>@<internal_endpoint>/bucket/path/poly.shp');Replace
<internal_endpoint>with the internal OSS endpoint for your region. For endpoint formats, see OSS domain names.ImportantAlways use the internal OSS endpoint. For more information, see OSS domain names.
-
Confirm the foreign table was registered:
SELECT foreign_table_name FROM information_schema.foreign_tables ORDER BY foreign_table_name ASC;
Query and import data
Query the foreign table directly with standard SQL:
SELECT fid, ST_AsText(geom), name, age, height
FROM poly
WHERE fid = 1;
Expected output:
1 | POLYGON((5 0,0 0,0 10,5 10,5 0)) | ZhangShan | 35 | 1.84
To import the data into a local table:
-- Create a local table with the same schema and data as the foreign table
CREATE TABLE poly_db AS
SELECT * FROM poly;
-- If the local table already exists, append the data
INSERT INTO poly_db
SELECT * FROM poly;
Remove the extension
DROP EXTENSION ganos_fdw CASCADE;
Advanced configuration
Use standard PostgreSQL FDW syntax for full control over the connection, credentials, and table schema. This approach is required when ST_RegForeignTables does not cover your use case — for example, when you need to configure encoding options or import a specific subset of layers.
Complete the following three steps in order.
Step 1: Create a foreign server
CREATE SERVER <server_name>
FOREIGN DATA WRAPPER ganos_fdw
OPTIONS (
datasource 'OSS://<internal_endpoint>/path/file',
format '<driver>',
open_options '<config>=<value>[ <config>=<value>]',
config_options '<config>=<value>[ <config>=<value>]'
);
| Option | Description |
|---|---|
datasource |
OSS path to the external data source. AccessKey credentials are not included here — they go in the user mapping. |
format |
Driver name for reading the source data. Run ST_FDWDrivers to list available drivers. If omitted, the system selects a default driver based on the file extension. |
open_options |
Driver-specific open options, as space-separated key=value pairs. |
config_options |
Additional driver configuration options. |
The datasource endpoint must be the internal OSS endpoint for the region where your cluster and OSS bucket reside. For endpoint formats, see OSS domain names.
Example — create a server for a shapefile with Latin-1 encoding:
CREATE SERVER myserver
FOREIGN DATA WRAPPER ganos_fdw
OPTIONS (
datasource 'OSS://<internal_endpoint>/path/poly.shp',
format 'ESRI Shapefile',
open_options 'SHAPE_ENCODING=LATIN1',
config_options ''
);
Step 2: Create a user mapping
Create a user mapping to provide your OSS credentials:
CREATE USER MAPPING
FOR <user_name>
SERVER <server_name>
OPTIONS (
user '<AccessKey_ID>',
password '<AccessKey_secret>'
);
Example:
CREATE USER MAPPING
FOR CURRENT_USER
SERVER myserver
OPTIONS (
user 'id',
password 'secret'
);
Step 3: Create a foreign table or import the schema
You have two options for defining the foreign table schema.
Option A: Import the schema automatically (recommended)
Use IMPORT FOREIGN SCHEMA to let GanosBase FDW detect layer definitions automatically:
IMPORT FOREIGN SCHEMA ganos_fdw
[ { LIMIT TO | EXCEPT } ( table_name [, ...] ) ]
FROM SERVER <server_name>
INTO <local_schema>;
The schema name inIMPORT FOREIGN SCHEMAmust beganos_fdw.
Example — import all layers from myserver into the imp schema:
CREATE SCHEMA imp;
IMPORT FOREIGN SCHEMA ganos_fdw
FROM SERVER myserver
INTO imp;
Example — import only the cities layer:
IMPORT FOREIGN SCHEMA ganos_fdw
LIMIT TO (cities)
FROM SERVER myserver
INTO imp;
Example — import all layers except countries:
IMPORT FOREIGN SCHEMA ganos_fdw
EXCEPT (countries)
FROM SERVER myserver
INTO imp;
Option B: Define the foreign table manually
If you know the exact column names and data types, define the table directly:
CREATE FOREIGN TABLE <table_name> (
column_name data_type
[, ...]
) SERVER <server_name>
OPTIONS (layer '<layer_name>');
Example:
CREATE FOREIGN TABLE example_table (
fid bigint,
name varchar,
age varchar,
value varchar
) SERVER myserver
OPTIONS (layer 'poly');
Tip: When the column names or data types are uncertain, use IMPORT FOREIGN SCHEMA (Option A) to avoid schema mismatches.
Write operations
INSERT, UPDATE, and DELETE operations are supported when the underlying driver (format) supports write access. Not all geospatial formats support writes.
Before attempting write operations, confirm that the format specified on the foreign server supports write access.
To check which drivers are available and their capabilities, run:
SELECT * FROM ST_FDWDrivers();
Limitations
| Limitation | Details |
|---|---|
| OSS connectivity | Your cluster and OSS bucket must reside in the same region and connect through the internal OSS endpoint. |
| Write support depends on the driver | INSERT, UPDATE, and DELETE are only available when the underlying driver supports write access. Not all geospatial formats support writes. |
| Predicate pushdown is limited | Only a subset of SQL predicates are pushed down to the external source. Complex predicates are evaluated locally after fetching the data. |
| Schema name is fixed | IMPORT FOREIGN SCHEMA requires ganos_fdw as the schema name argument. Any other value causes the command to fail. |