All Products
Search
Document Center

Hologres:Export data to OSS

Last Updated:Mar 26, 2026

Use the COPY TO command together with hg_dump_to_oss to export Hologres query results to an Object Storage Service (OSS) bucket. Both internal tables and foreign tables are supported, and cross-region export is available.

Prerequisites

Before you begin, ensure that you have:

  • A Hologres instance with Superuser privileges, or the pg_execute_server_program permission granted to your account

  • An OSS bucket in the target region

  • The AccessKey ID and AccessKey secret for your Alibaba Cloud account

  • The classic network endpoint of the target OSS bucket

If you are not a Superuser, ask a Superuser to grant the permission:

-- If the instance uses the simple permission model
CALL spm_grant('pg_execute_server_program', '<account-id-or-email-or-ram-user>');

-- If the instance uses the standard PostgreSQL authorization model
GRANT pg_execute_server_program TO <account-id-or-email-or-ram-user>;

Limitations

  • The data volume for a single export cannot exceed 5 GB.

How it works

hg_dump_to_oss runs as a server-side program that writes query results directly to OSS. The COPY TO command calls hg_dump_to_oss via the PROGRAM option, passing connection parameters and output options as arguments.

All examples in this topic use the following pattern:

COPY (<query>) TO PROGRAM 'hg_dump_to_oss <connection-args>' (<format-options>);

Export commands

Quick start

Export all rows from a table to a CSV file in OSS:

COPY (SELECT * FROM holo_test LIMIT 2)
TO PROGRAM 'hg_dump_to_oss
  --AccessKeyId     <your-access-key-id>
  --AccessKeySecret <your-access-key-secret>
  --Endpoint        oss-cn-hangzhou-internal.aliyuncs.com
  --BucketName      hologres-demo
  --DirName         holotest/
  --FileName        file_name
  --BatchSize       3000'
DELIMITER ',';

Replace the placeholders with your actual values:

PlaceholderDescriptionWhere to find it
<your-access-key-id>AccessKey IDAccessKey Management page
<your-access-key-secret>AccessKey secretAccessKey Management page
<endpoint>Classic network endpoint of the OSS bucketBucket details in the Bucket List page. Example: oss-cn-beijing-internal.aliyuncs.com
Do not add / or \ before the DirName value.

hg_dump_to_oss parameters

ParameterRequiredDescriptionDefaultExample
AccessKeyIdYesAccessKey ID of your Alibaba Cloud account
AccessKeySecretYesAccessKey secret of your account
EndpointYesClassic network endpoint of the OSS bucketoss-cn-beijing-internal.aliyuncs.com
BucketNameYesName of the OSS buckethologres-demo
DirNameYesTarget folder path in OSSholotest/
FileNameNoName of the output file in OSSfile_name
BatchSizeNoNumber of rows per write batch10005000

The COPY TO command also accepts the following format options after the PROGRAM clause:

OptionSupported formatsDescriptionDefault
FORMATtext, csv, binaryOutput formattext
DELIMITERtext, csvColumn separator. Not supported for binary.Tab (\t) for text; comma (,) for CSV
NULLtext, csvString to represent NULL values. Not supported for binary.\N for text; empty unquoted string for CSV
HEADERcsvInclude a header row with column names
QUOTEcsvCharacter to quote fieldsSame as QUOTE value
ENCODINGAllFile encodingCurrent client encoding

More examples

Export from a foreign table with a header row

COPY (SELECT * FROM foreign_holo_test LIMIT 20)
TO PROGRAM 'hg_dump_to_oss
  --AccessKeyId     <your-access-key-id>
  --AccessKeySecret <your-access-key-secret>
  --Endpoint        oss-cn-hangzhou-internal.aliyuncs.com
  --BucketName      hologres-demo
  --DirName         holotest/
  --FileName        file_name
  --BatchSize       3000'
(DELIMITER ',', HEADER true);

Export to a bucket in a different region

Hologres supports cross-region export. For example, you can export data from an instance in China (Hangzhou) to an OSS bucket in China (Beijing) by specifying the Beijing endpoint:

COPY (SELECT * FROM holo_test_1 LIMIT 20)
TO PROGRAM 'hg_dump_to_oss
  --AccessKeyId     <your-access-key-id>
  --AccessKeySecret <your-access-key-secret>
  --Endpoint        oss-cn-beijing-internal.aliyuncs.com
  --BucketName      hologres-demo
  --DirName         holotest/
  --FileName        file_name
  --BatchSize       3000'
(DELIMITER ',', HEADER true, FORMAT CSV);

After the export completes, access the output files in the specified OSS folder using the OSS console or OSS tools.

Troubleshooting

Invalid query syntax

Error:

ERROR: syntax error at or near ")" LINE 1: COPY (select 1,2,3 from ) TO PROGRAM 'hg_dump_to_oss ...

The query inside COPY (...) is invalid. Check the SQL statement for syntax errors.

Connection failed (exit code 255)

Error:

DETAIL: child process exited with exit code 255

The Hologres server cannot reach the OSS endpoint. Use the classic network endpoint for your bucket—public network endpoints are not supported. Find the correct endpoint on the Bucket List page under bucket details, or refer to Regions and endpoints.

Program not found

Error:

DETAIL: command not found

The PROGRAM value must be exactly hg_dump_to_oss. Check for typos in the command name.

Invalid credentials or configuration

Exit codeCauseResolution
101Invalid AccessKeyIdVerify your AccessKey ID on the AccessKey Management page.
102Invalid AccessKeySecretVerify your AccessKey secret on the AccessKey Management page.
103Invalid EndpointConfirm the classic network endpoint for your region on the Bucket List page or in Regions and endpoints.
104Invalid BucketNameConfirm the bucket name on the Bucket List page.
105Missing required parameterCheck the parameter table above and make sure all required parameters are provided.