All Products
Search
Document Center

Hologres:Automatic loading of foreign tables (Auto Load)

Last Updated:Feb 04, 2026

This topic describes how to use the Auto Load feature for foreign tables. This feature automatically loads data from MaxCompute and Object Storage Service (OSS) on demand or in full.

Scenarios

Hologres is highly compatible with the cloud-native big data computing service MaxCompute, Alibaba Cloud Data Lake Formation (DLF), and Alibaba Cloud Object Storage Service (OSS). You can use foreign tables to accelerate queries on data stored in MaxCompute or OSS without migrating the data. To accelerate queries for many tables, you can use the automatic loading feature. This feature automatically synchronizes metadata from MaxCompute and DLF and creates Hologres foreign tables, which reduces the manual effort of creating them.

  • On-demand loading of foreign tables: This mode is ideal for scenarios where a small number of data source tables require accelerated queries. When you enable this feature, Hologres automatically creates a corresponding foreign table when you query a table in MaxCompute or OSS, which accelerates the query.

    Note
    • If a schema and table with the same name already exist in Hologres, the automatic loading feature is not triggered when you query a MaxCompute or OSS table. Instead, the existing internal table in Hologres is queried.

    • Because automatic loading creates a foreign table, the account used for the query must have permissions to create and delete schemas and tables in the database. However, if the foreign table has already been created, only query permission is required for subsequent operations.

    • This feature triggers automatic loading only at query time. It does not load data periodically.

  • Full loading of foreign tables: This mode is ideal for scenarios with many tables or multiple data sources that require accelerated queries. When this feature is enabled, the system automatically creates foreign tables that match the data source when you run a query. This process creates a complete mapping of all tables from the data source. After the initial full load, you can configure periodic checks to ensure that newly added tables are also automatically created as foreign tables when queried. This approach optimizes the management of many foreign tables and is ideal for improving the performance of Business Intelligence (BI) queries.

Automatic loading

Features

  • Hologres V1.1.43 and later support automatic loading of MaxCompute foreign tables. This feature initially supported only MaxCompute two-layer model data sources.

  • In Hologres V1.3.28 and later, the default value of the hg_experimental_load_all_foreign_table_interval_time parameter was changed from 5 min to 30 min. This change reduces the system resource consumption caused by periodic checks during the full loading of foreign tables.

  • Hologres V2.2.1 and later support the following features. If your instance is V2.1 or earlier, you can contact Hologres technical support to upgrade your instance.

    • A new parameter, hg_experimental_load_foreign_table_mode = ['query' | 'period'], is added to control the automatic loading mode for foreign tables.

    • Automatic loading of foreign tables supports data from MaxCompute three-layer model projects. For more information about the MaxCompute three-layer model, see Schema operations.

    • Automatic loading of foreign tables supports schema evolution for MaxCompute foreign tables, such as adding columns, deleting columns, and modifying column names and order.

      For existing Hologres foreign tables, if the schema of the external data source changes, you can use the following Grand Unified Configuration (GUC) parameter to enable schema evolution checks. When this parameter is enabled, the metadata of the MaxCompute foreign table is automatically updated at query time. Enable this GUC at the session level as needed. Do not enable it at the database level, because doing so can generate many schema evolution check jobs and increase the system load.

      set hg_experimental_enable_auto_load_check_schema_evolution = on;
      Note

      Automatic loading of foreign tables does not currently support schema evolution for OSS foreign tables.

    • Automatic loading of foreign tables supports loading through DLF metadata to accelerate queries on data stored in OSS. For more information, see Accelerate queries on data in an OSS-based data lake using DLF.

Limits

  • When you use automatic loading for foreign tables, the mapping parameters for MaxCompute and OSS data sources cannot start with hg_ or holo_. These are reserved keywords in Hologres.

  • A single query can automatically load a maximum of six tables. If a query involves more than six tables, the automatic loading process fails. You must run the query again to load the remaining foreign tables.

  • If a MaxCompute table contains data types that are not supported by Hologres foreign tables, the foreign table cannot be created automatically. You must use the CREATE FOREIGN TABLE statement to manually create the foreign table by selecting only the supported fields.

  • If you use Auto Load to automatically load OSS data, you must run the CREATE USER MAPPING command. This command specifies the AccessKey ID and AccessKey secret for the account used to access DLF and OSS, such as your Alibaba Cloud account.

  • If you load tables from multiple external data sources into the same Hologres schema, a newly created foreign table overwrites an existing foreign table that has the same name. To avoid this, associate different data sources with different Hologres schemas.

  • When you use Auto Load for foreign tables, if you specify a schema that does not exist in Hologres, the system can create the schema automatically. However, the user must have `db_admin` permissions.

  • For scenarios that involve the full automatic loading of foreign tables:

    • Do not set the automatic loading interval to less than 5 minutes.

    • Do not enable full automatic loading for an external data source that contains more than 1,000 tables.

Procedure

Enable automatic loading

  • Syntax

    -- Enable automatic loading
    ALTER DATABASE <database name> SET hg_experimental_enable_auto_load_foreign_table = on;
  • Parameter description

    database name: The name of the Hologres database.

(Optional) Set the automatic loading mode

In Hologres V2.2.1 and later, you can set the automatic loading mode based on your business needs. The automatic loading mode must be enabled at the database level. If you do not set a mode, the on-demand loading mode is used by default. You do not need to perform this step for Hologres versions earlier than V2.2.1.

  • Syntax

    ALTER DATABASE <database name> SET hg_experimental_load_foreign_table_mode = ['query' | 'period']
  • The parameter values are described as follows:

    • query (default): On-demand loading of foreign tables.

      -- Set the loading mode to on-demand loading
      ALTER DATABASE <database name> SET hg_experimental_load_foreign_table_mode = 'query';
    • period: Full loading of foreign tables.

      -- Set the loading mode to full loading
      ALTER DATABASE <database name> SET hg_experimental_load_foreign_table_mode = 'period';

Configure mappings

  • Syntax

    • Configure MaxCompute mappings

      • For Hologres V2.2.1 and later

        -- For a MaxCompute three-layer model project
        ALTER DATABASE <database> SET hg_experimental_auto_load_foreign_schema_mapping = '<hologres_schema>:<odps_foreign_server>.<mc_project>.<mc_schema>, [...]';
        -- For a MaxCompute two-layer model project
        ALTER DATABASE <database> SET hg_experimental_auto_load_foreign_schema_mapping = '<hologres_schema>:<odps_foreign_server>.<mc_project>, [...]';
      • For Hologres versions earlier than V2.2.1

        ALTER DATABASE <database> SET hg_experimental_default_odps_project_list='<odps_project_name_1>,<odps_project_name_2>...';
    • Configure DLF mappings

      -- DLF Default Catalog
      ALTER DATABASE <database> SET hg_experimental_auto_load_foreign_schema_mapping = '<hologres_schema>:<dlf_foreign_server>.<dlf_database> [...]';
      -- Custom Catalog
      ALTER DATABASE <database> SET hg_experimental_auto_load_foreign_schema_mapping = '<hologres_schema>:<dlf_foreign_server>.<dlf_catalog>.<dlf_database>, [...]';
  • Parameters

    Parameter name

    Description

    database

    The name of the Hologres database.

    hologres_schema

    The name of the Hologres schema.

    mc_project

    The name of the MaxCompute project to automatically load. Log on to the MaxCompute console and go to the Workspace > Project Management page to obtain the MaxCompute project name.

    odps_foreign_server

    The server used to access the MaxCompute project. This is fixed to odps_server.

    odps_project_name

    The name of the MaxCompute project. You can specify multiple projects. Separate multiple project names with commas (,).

    The default value is empty, which means that the metadata of tables in any MaxCompute project is not loaded periodically.

    Note

    This parameter is required only for Hologres versions earlier than V2.2.1.

    mc_schema

    The name of the MaxCompute schema.

    Note

    This parameter is required only for projects where the three-layer model is enabled. For more information about schemas, see Schema operations.

    dlf_foreign_server

    The foreign server created based on DLF_FDW. You can run the following command to get the foreign server name. For more information, see Accelerate queries on data in an OSS-based data lake using DLF.

    SELECT * FROM pg_foreign_server;

    dlf_catalog

    The name of the data catalog where the DLF database to be automatically loaded resides. Log on to the Data Lake Formation console, choose Metadata > Metadata Management, and then obtain the data catalog name from the Data Catalog tab.

    dlf_database

    The name of the DLF database to be automatically loaded. Log on to the Data Lake Formation console, choose Metadata > Metadata Management, and then obtain the database name from the Database tab.

Query data

You can directly query the data in the corresponding MaxCompute or DLF tables.

-- Query data in a MaxCompute project
SELECT * FROM <hologres_schema>.<mc_table>;
-- Query DLF data
SELECT * FROM <hologres_schema>.<dlf_table>;

More operations

Disable automatic loading

  • Syntax

    ---- Disable automatic loading
    ALTER DATABASE <database name> SET hg_experimental_enable_auto_load_foreign_table = off;
    Note

    After you disable automatic loading, the system stops synchronizing metadata from external data sources and creating new foreign tables. You can view only the foreign tables and data that are already loaded in Hologres. To add more foreign tables, you must manually run the IMPORT command. For more information, see IMPORT FOREIGN SCHEMA.

  • Parameter description

    database name: The name of the Hologres database.

View data sources with automatic loading enabled

-- Before V2.2, view the configured MaxCompute data sources
SHOW hg_experimental_default_odps_project_list;

-- In V2.2 and later, view the configured MaxCompute and DLF data sources
SHOW hg_experimental_auto_load_foreign_schema_mapping;

Set the inspection period

After you configure a data source for full loading, you can use the following time parameter to set up periodic checks. If new tables are added to the data source, the system automatically loads them as Hologres foreign tables when a query is run after the specified check period. The default interval is 30 minutes. This means that if a new table is added, it is automatically loaded as a foreign table when it is queried 30 minutes later.

  • Syntax

    -- Set the inspection period for the specified Hologres database to 600 s
    ALTER DATABASE <database name> SET hg_experimental_load_all_foreign_table_interval_time = 600;
  • Parameter description

    database name: The name of the Hologres database.

Note

Set the check period to 600 s (10 minutes) or longer.

Delete a loaded foreign table

If you no longer need to accelerate queries on a foreign table, you can run the DROP statement to delete it. For more information, see DROP FOREIGN TABLE.

Usage examples

Example 1: On-demand loading of foreign tables

Note

This example uses a MaxCompute data source to demonstrate automatic loading for both two-layer and three-layer model projects. The details are as follows:

  • Two-layer model: The project name is mc_project, and the table name is mc_table.

  • Three-layer model: The project name is mc_3_layer_project, the schema name is mc_schema, and the table name is mc_table.

  • Two-layer model

    1. Enable automatic loading.

      ALTER DATABASE holo_demo SET hg_experimental_enable_auto_load_foreign_table = on;
    2. Configure the mapping.

      --- For V2.2.1 and later
      ALTER DATABASE holo_demo SET hg_experimental_auto_load_foreign_schema_mapping = 'hologres_schema:odps_server.mc_project';
      --- For versions earlier than V2.2.1
      ALTER DATABASE holo_demo SET hg_experimental_default_odps_project_list='mc_project';
    3. Query the foreign table.

      SELECT * FROM hologres_schema.mc_table;
  • Three-layer model

    1. Enable automatic loading.

      ALTER DATABASE holo_demo SET hg_experimental_enable_auto_load_foreign_table = on;
    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';
    3. Query the foreign table.

      SELECT * FROM holo_schema_3layer.mc_table;

Example 2: Full automatic loading of foreign tables

This example uses a DLF data source. You can automatically load DLF foreign tables by binding to the DLF Default Catalog or a custom catalog.

  • DLF Default Catalog

    Set up automatic loading for the dlf_db database in the DLF Default Catalog. After the setup is complete, all tables in this database are automatically created as Hologres foreign tables. The system also periodically loads new tables from this database based on the check period configured by hg_experimental_load_all_foreign_table_interval_time.

    1. Create the foreign service dlf_server and configure its Endpoint information. For more information, see Accelerate queries on data in an OSS-based data lake using DLF.

      -- Create a 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'
      );
    2. Create a user mapping.

      Auto Load requires you to run the CREATE USER MAPPING command to specify the AccessKey ID and AccessKey secret for accessing DLF and OSS. For more information, see Accelerate queries on data in an OSS-based data lake using DLF.

      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'
      );
    3. Enable automatic loading.

      ALTER DATABASE holo_demo SET hg_experimental_enable_auto_load_foreign_table = on;
    4. Set the mapping and 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 = 10;
    5. Query the foreign table data.

      SELECT * FROM holo_schema.dlf_table;
  • DLF custom catalog

    1. Create a foreign server and configure its Endpoint information. For more information, see Accelerate queries on data in an OSS-based data lake using DLF.

      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'
      );
    2. Create a user mapping.

      Auto Load requires you to run the CREATE USER MAPPING command to specify the AccessKey ID and AccessKey secret for accessing DLF and OSS. For more information, see Accelerate queries on data in an OSS-based data lake using DLF.

      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'
      );
    3. Enable automatic loading.

      ALTER DATABASE holo_demo SET hg_experimental_enable_auto_load_foreign_table = on;
    4. Configure the mapping, loading mode, and check period.

      -- Configure the mapping
      SET hg_experimental_auto_load_foreign_schema_mapping = 'holo_schema:DLF_server.dlf_catalog.dlf_db';
      -- Set the loading mode to full loading of foreign tables
      SET hg_experimental_load_foreign_table_mode = 'period'; 
      -- Set the inspection period to 600 s
      SET hg_experimental_load_all_foreign_table_interval_time = 600;
    5. Query the foreign table data.

      SELECT * FROM holo_schema.dlf_table;