首页 Hologres User Guide Data warehouse design Foreign tables Load foreign tables automatically

Automatic loading of foreign tables (Auto Load)

更新时间: 2026-03-26 22:05:09

When you need to accelerate queries on data stored in MaxCompute or Object Storage Service (OSS) at scale, creating foreign tables manually with CREATE FOREIGN TABLE becomes impractical. Auto Load eliminates this overhead by automatically syncing metadata from MaxCompute and OSS (via Data Lake Formation) and creating Hologres foreign tables on demand or on a schedule.

Automatic loading

Choose a loading mode

On-demand loading Full loading
How it works Creates a foreign table the first time you query a MaxCompute or OSS table Creates foreign tables for all tables in a data source upfront; periodically syncs new tables
Best for Small number of tables requiring accelerated queries Many tables or multiple data sources requiring accelerated queries
Parameter value query (default) period

On-demand loading behavior:

  • If a Hologres schema and table with the same name already exist, Auto Load is not triggered. The existing internal table is queried instead.

  • The account running the query must have permission to create and delete schemas and tables in the database — but only for the first query. Subsequent queries require only query permission.

  • Tables are created at query time only, not on a schedule.

Full loading behavior:

  • All tables from the data source are created as Hologres foreign tables after setup.

  • New tables added to the data source are automatically loaded as foreign tables after the next check interval (default: 30 minutes).

  • Do not enable full loading for data sources with more than 1,000 tables.

  • Set the check interval to 600 seconds (10 minutes) or longer.

Limitations

  • Mapping parameters for MaxCompute and OSS data sources cannot start with hg_ or holo_ — these are reserved prefixes in Hologres.

  • A single query can auto-load at most 6 tables. If a query involves more than 6 tables, the auto-load process fails. Run the query again to load the remaining foreign tables.

  • If a MaxCompute table contains data types not supported by Hologres foreign tables, the foreign table cannot be created automatically. Use CREATE FOREIGN TABLE to manually create it, selecting only the supported fields.

  • To use Auto Load with OSS data through Data Lake Formation (DLF), run CREATE USER MAPPING to specify the AccessKey ID and AccessKey secret for the account accessing DLF and OSS.

  • If tables from multiple external data sources are loaded into the same Hologres schema, a newly created foreign table overwrites any existing foreign table with the same name. Associate different data sources with different Hologres schemas to avoid this.

  • Auto-creating a schema that does not exist in Hologres requires db_admin permissions.

  • Schema evolution (adding columns, deleting columns, modifying column names and order) is supported for MaxCompute foreign tables (V2.2.1+), but not for OSS foreign tables.

Version requirements

Version What's added
V1.1.43+ Auto Load for MaxCompute foreign tables (two-layer model only)
V1.3.28+ Default check interval changed from 5 minutes to 30 minutes
V2.2.1+ hg_experimental_load_foreign_table_mode parameter; MaxCompute three-layer model support; schema evolution for MaxCompute foreign tables; DLF metadata loading for OSS queries
Note

If your instance is V2.1 or earlier and you need V2.2.1+ features, contact Hologres technical support to upgrade.

Enable Auto Load for foreign tables

The setup requires four steps. Step 2 applies only to Hologres V2.2.1 and later.

  1. Enable automatic loading

  2. (V2.2.1+, optional) Set the loading mode

  3. Configure schema mappings

  4. Query data and verify the setup

Prerequisites

Before you begin, make sure you have:

Step 1: Enable automatic loading

ALTER DATABASE <database_name> SET hg_experimental_enable_auto_load_foreign_table = on;

Replace <database_name> with the name of your Hologres database.

Step 2: Set the loading mode

This step applies to Hologres V2.2.1 and later. Skip it for earlier versions — on-demand loading (query) is used by default.

The mode must be set at the database level.

-- On-demand loading (default)
ALTER DATABASE <database_name> SET hg_experimental_load_foreign_table_mode = 'query';

-- Full loading
ALTER DATABASE <database_name> SET hg_experimental_load_foreign_table_mode = 'period';

Step 3: Configure schema mappings

Map each Hologres schema to the external data source it should mirror.

MaxCompute mappings (V2.2.1+)

-- Three-layer model project
ALTER DATABASE <database_name> SET hg_experimental_auto_load_foreign_schema_mapping = '<hologres_schema>:<odps_foreign_server>.<mc_project>.<mc_schema>, [...]';

-- Two-layer model project
ALTER DATABASE <database_name> SET hg_experimental_auto_load_foreign_schema_mapping = '<hologres_schema>:<odps_foreign_server>.<mc_project>, [...]';

MaxCompute mappings (earlier than V2.2.1)

ALTER DATABASE <database_name> SET hg_experimental_default_odps_project_list='<odps_project_name_1>,<odps_project_name_2>...';

DLF mappings (V2.2.1+)

-- Default catalog
ALTER DATABASE <database_name> SET hg_experimental_auto_load_foreign_schema_mapping = '<hologres_schema>:<dlf_foreign_server>.<dlf_database> [...]';

-- Custom catalog
ALTER DATABASE <database_name> SET hg_experimental_auto_load_foreign_schema_mapping = '<hologres_schema>:<dlf_foreign_server>.<dlf_catalog>.<dlf_database>, [...]';

Parameters

Parameter Description Default
database_name Name of the Hologres database
hologres_schema Name of the Hologres schema
odps_foreign_server Fixed value: odps_server odps_server
mc_project Name of the MaxCompute project. Find it in the MaxCompute console under Workspace > Project Management
mc_schema Name of the MaxCompute schema. Required only for three-layer model projects. See Schema operations
odps_project_name (Earlier than V2.2.1 only) Name of the MaxCompute project. Separate multiple names with commas. empty (no projects loaded periodically)
dlf_foreign_server Foreign server created with DLF_FDW. Run SELECT * FROM pg_foreign_server; to get the name. See Accelerate queries on data in an OSS-based data lake using DLF
dlf_catalog Name of the DLF data catalog. Find it in the Data Lake Formation console under Metadata > Metadata Management > Data Catalog tab
dlf_database Name of the DLF database. Find it in the Data Lake Formation console under Metadata > Metadata Management > Database tab

Step 4: Query data and verify the setup

Run a query against the mapped schema. Auto Load creates the foreign table on first access (on-demand mode) or confirms that tables are already loaded (full mode).

-- Query a MaxCompute table
SELECT * FROM <hologres_schema>.<mc_table>;

-- Query a DLF table
SELECT * FROM <hologres_schema>.<dlf_table>;

To confirm which data sources are configured, run:

-- V2.2.1 and later
SHOW hg_experimental_auto_load_foreign_schema_mapping;

-- Earlier than V2.2.1
SHOW hg_experimental_default_odps_project_list;

More operations

Disable automatic loading

ALTER DATABASE <database_name> SET hg_experimental_enable_auto_load_foreign_table = off;

After disabling, Hologres stops syncing metadata from external data sources and creating new foreign tables. Existing foreign tables remain queryable. To add more foreign tables manually, use IMPORT FOREIGN SCHEMA.

Set the check interval for full loading

For full loading mode, configure how often Hologres checks for new tables in the data source. When a new table is detected, it is auto-loaded as a foreign table on the next query after the interval elapses.

-- Set the check interval to 600 seconds (10 minutes)
ALTER DATABASE <database_name> SET hg_experimental_load_all_foreign_table_interval_time = 600;

Default: 1800 seconds (30 minutes). Minimum: 600 seconds (10 minutes).

Enable schema evolution for MaxCompute foreign tables

When the schema of a MaxCompute data source changes — columns added, deleted, or renamed — enable this Grand Unified Configuration (GUC) parameter at the session level to update the foreign table metadata automatically at query time.

SET hg_experimental_enable_auto_load_check_schema_evolution = on;
Important

Enable this parameter at the session level only. Enabling it at the database level generates a large number of schema evolution check jobs and increases system load.

Note

Schema evolution is not supported for OSS foreign tables.

Delete a foreign table

To stop accelerating queries on a foreign table, drop it with the DROP statement. See DROP FOREIGN TABLE.

Examples

Example 1: On-demand loading from a MaxCompute project

This example shows on-demand loading for both two-layer and three-layer MaxCompute model projects.

Two-layer model Three-layer model
Project mc_project mc_3_layer_project
Schema mc_schema
Table mc_table mc_table

Two-layer model

-- Step 1: Enable automatic loading
ALTER DATABASE holo_demo SET hg_experimental_enable_auto_load_foreign_table = on;

-- Step 2: Configure the mapping
-- V2.2.1 and later
ALTER DATABASE holo_demo SET hg_experimental_auto_load_foreign_schema_mapping = 'hologres_schema:odps_server.mc_project';
-- Earlier than V2.2.1
ALTER DATABASE holo_demo SET hg_experimental_default_odps_project_list='mc_project';

-- Step 3: Query the table (the foreign table is created on first query)
SELECT * FROM hologres_schema.mc_table;

Three-layer model

-- Step 1: Enable automatic loading
ALTER DATABASE holo_demo SET hg_experimental_enable_auto_load_foreign_table = on;

-- Step 2: Configure the mapping
ALTER DATABASE holo_demo SET hg_experimental_auto_load_foreign_schema_mapping = 'holo_schema_3layer:odps_server.mc_3_layer_project.mc_schema';

-- Step 3: Query the table
SELECT * FROM holo_schema_3layer.mc_table;

Example 2: Full loading from a DLF data source

This example shows full loading for a DLF database — both from the default catalog and a custom catalog.

DLF default catalog

All tables in dlf_db are loaded as Hologres foreign tables. The system checks for new tables periodically based on the configured interval.

-- Step 1: Create the DLF foreign server
CREATE SERVER IF NOT EXISTS dlf_server FOREIGN DATA WRAPPER dlf_fdw OPTIONS (
    dlf_endpoint 'dlf-share.cn-beijing.aliyuncs.com',
    oss_endpoint 'oss-cn-beijing-internal.aliyuncs.com'
);

-- Step 2: Create a user mapping with credentials for DLF and OSS
CREATE USER MAPPING FOR <account_uid> SERVER <server_name> OPTIONS (
    dlf_access_id 'accessid',
    dlf_access_key 'accesskey',
    oss_access_id 'accessid',
    oss_access_key 'accesskey'
);

-- Step 3: Enable automatic loading
ALTER DATABASE holo_demo SET hg_experimental_enable_auto_load_foreign_table = on;

-- Step 4: Configure the mapping and set full loading mode
SET hg_experimental_auto_load_foreign_schema_mapping = 'holo_schema:dlf_server.dlf_db';
SET hg_experimental_load_foreign_table_mode = 'period';
SET hg_experimental_load_all_foreign_table_interval_time = 600;

-- Step 5: Query a table
SELECT * FROM holo_schema.dlf_table;

DLF custom catalog

-- Step 1: Create the DLF foreign server
CREATE SERVER IF NOT EXISTS DLF_server FOREIGN DATA WRAPPER dlf_fdw OPTIONS (
    dlf_endpoint 'dlf-share.cn-beijing.aliyuncs.com',
    oss_endpoint 'oss-cn-beijing-internal.aliyuncs.com'
);

-- Step 2: Create a user mapping
CREATE USER MAPPING FOR <account_uid> SERVER <server_name> OPTIONS (
    dlf_access_id 'accessid',
    dlf_access_key 'accesskey',
    oss_access_id 'accessid',
    oss_access_key 'accesskey'
);

-- Step 3: Enable automatic loading
ALTER DATABASE holo_demo SET hg_experimental_enable_auto_load_foreign_table = on;

-- Step 4: Configure the mapping, loading mode, and check interval
SET hg_experimental_auto_load_foreign_schema_mapping = 'holo_schema:DLF_server.dlf_catalog.dlf_db';
SET hg_experimental_load_foreign_table_mode = 'period';
SET hg_experimental_load_all_foreign_table_interval_time = 600;

-- Step 5: Query a table
SELECT * FROM holo_schema.dlf_table;

What's next

上一篇: Foreign tables 下一篇: Views
阿里云首页 实时数仓 Hologres 相关技术圈