Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
P

pg_parquet

> 数据库
Open source

Copy to/from Parquet in S3, Azure Blob Storage, Google Cloud Storage, http(s) stores, local files or standard inout stream from within PostgreSQL

684 stars0 likes2 views
WebsiteGitHub

About

Copy to/from Parquet in S3, Azure Blob Storage, Google Cloud Storage, http(s) stores, local files or standard inout stream from within PostgreSQL

pg_parquet

Copy from/to Parquet files in PostgreSQL! pg_parquet is a PostgreSQL extension that allows you to read and write Parquet files, which are located in S3, Azure Blob Storage, Google Cloud Storage, http(s) endpoints or file system, from PostgreSQL via COPY TO/FROM commands. It depends on Apache Arrow project to read and write Parquet files and pgrx project to extend PostgreSQL's COPY command.

sql
-- Copy a query result into Parquet in S3
COPY (SELECT * FROM table) TO 's3://mybucket/data.parquet' WITH (format 'parquet');

-- Load data from Parquet in S3
COPY table FROM 's3://mybucket/data.parquet' WITH (format 'parquet');

Quick Reference

  • Installation From Source
  • Usage
    • Copy FROM/TO Parquet files TO/FROM Postgres tables
    • COPY FROM/TO Parquet stdin/stdout TO/FROM Postgres tables)
    • COPY FROM/TO Parquet program stream TO/FROM Postgres tables)
    • Inspect Parquet schema
    • Inspect Parquet metadata
    • Inspect Parquet column statistics
    • List and read Parquet files from uri pattern
  • Object Store Support
  • Copy Options
  • Configuration
  • Supported Types
    • Nested Types
  • Postgres Support Matrix

Installation From Source

After installing Postgres, you need to set up rustup, cargo-pgrx to build the extension.

…

Usage

There are mainly 3 things that you can do with pg_parquet:

  1. You can export Postgres tables/queries to Parquet files, stdin/stdout or a program's stream,
  2. You can ingest data from Parquet files to Postgres tables,
  3. You can inspect the schema and metadata of Parquet files.

COPY from/to Parquet files to/from Postgres tables

You can use PostgreSQL's COPY command to read and write from/to Parquet files. Below is an example of how to write a PostgreSQL table, with complex types, into a Parquet file and then to read the Parquet file content back into the same table.

…

COPY from/to Parquet stdin/stdout to/from Postgres tables

You can use COPY command to read and write Parquet stream from/to standard input and output. Below is an example usage (you have to specify format = parquet):

bash
psql -d pg_parquet -p 28817 -h localhost -c "create table product_example_reconstructed (like product_example);"
 CREATE TABLE

psql -d pg_parquet -p 28817 -h localhost -c "copy product_example to stdout (format parquet);" | psql -d pg_parquet -p 28817 -h localhost -c "copy product_example_reconstructed from stdin (format parquet);"
 COPY 2

COPY from/to Parquet program stream to/from Postgres tables

You can use COPY command to read and write Parquet stream from/to a program's input and output. Below is an example usage (you have to specify format = parquet):

bash
psql -d pg_parquet -p 28817 -h localhost -c "copy product_example_reconstructed to program 'cat > /tmp/test.parquet' (format parquet);"
 COPY 2

psql -d pg_parquet -p 28817 -h localhost -c "copy product_example_reconstructed from program 'cat /tmp/test.parquet' (format parquet);"
 COPY 2

Inspect Parquet schema

You can call SELECT * FROM parquet.schema() to discover the schema of the Parquet file at given uri.

…

Inspect Parquet metadata

You can call SELECT * FROM parquet.metadata() to discover the detailed metadata of the Parquet file, such as column statistics, at given uri.

…
…

You can call SELECT * FROM parquet.file_metadata() to discover file level metadata of the Parquet file, such as format version, at given uri.

sql
SELECT * FROM parquet.file_metadata('/tmp/product_example.parquet')
             uri              | created_by | num_rows | num_row_groups | format_version 
------------------------------+------------+----------+----------------+----------------
 /tmp/product_example.parquet | pg_parquet |        1 |              1 | 1
(1 row)

You can call SELECT * FROM parquet.kv_metadata() to query custom key-value metadata of the Parquet file at given uri.

sql
SELECT uri, encode(key, 'escape') as key, encode(value, 'escape') as value FROM parquet.kv_metadata('/tmp/product_example.parquet');
             uri              |     key      |    value
------------------------------+--------------+---------------------
 /tmp/product_example.parquet | ARROW:schema | /////5gIAAAQAAAA ...
(1 row)

Inspect Parquet column statistics

You can call SELECT * FROM parquet.column_stats() to discover the column statistics of the Parquet file, such as min and max value for the column, at given uri.

…

List and read Parquet files from uri pattern

You can call SELECT * FROM parquet.list() to see all uris that matches with the uri pattern. Uri pattern can resolve ** for directories and * for words in the uri.

sql
COPY (SELECT i FROM generate_series(1, 1000000) i) TO '/tmp/some/test.parquet' with (file_size_bytes '1MB');
COPY 1000000

SELECT * FROM parquet.list('/tmp/some/**/*.parquet');
                  uri                  |  size
---------------------------------------+---------
 /tmp/some/test.parquet/data_4.parquet |  100162
 /tmp/some/test.parquet/data_3.parquet | 1486916
 /tmp/some/test.parquet/data_2.parquet | 1486916
 /tmp/some/test.parquet/data_0.parquet | 1486920
 /tmp/some/test.parquet/data_1.parquet | 1486916
(5 rows)

Uri pattern is also supported by COPY FROM for all supported object stores except http(s) endpoints.

sql
COPY (SELECT i FROM generate_series(1, 1000000) i) TO 's3://testbucket/some/test.parquet' with (file_size_bytes '1MB');
COPY 1000000

CREATE TABLE test(a int);
CREATE TABLE

COPY test FROM 's3://testbucket/some/**/*.parquet';
COPY 1000000

Object Store Support

pg_parquet supports reading and writing Parquet files from/to S3, Azure Blob Storage, http(s) and Google Cloud Storage object stores.

[!NOTE] To be able to write into a object store location, you need to grant parquet_object_store_write role to your current postgres user. Similarly, to read from an object store location, you need to grant parquet_object_store_read role to your current postgres user.

S3 Storage

The simplest way to configure object storage is by creating the standard ~/.aws/credentials and ~/.aws/config files:

bash
$ cat ~/.aws/credentials
[default]
aws_access_key_id = AKIAIOSFODNN7EXAMPLE
aws_secret_access_key = wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY

$ cat ~/.aws/config 
[default]
region = eu-central-1

Alternatively, you can use the following environment variables when starting postgres to configure the S3 client:

  • AWS_ACCESS_KEY_ID: the access key ID of the AWS account
  • AWS_SECRET_ACCESS_KEY: the secret access key of the AWS account
  • AWS_SESSION_TOKEN: the session token for the AWS account
  • AWS_REGION: the default region of the AWS account
  • AWS_ENDPOINT_URL: the endpoint
  • AWS_SHARED_CREDENTIALS_FILE: an alternative location for the credentials file (only via environment variables)
  • AWS_CONFIG_FILE: an alternative location for the config file (only via environment variables)
  • AWS_PROFILE: the name of the profile from the credentials and config file (default profile name is default) (only via environment variables)
  • AWS_ALLOW_HTTP: allows http endpoints (only via environment variables)

Config source priority order is shown below:

  1. Environment variables,
  2. Config file.

Supported S3 uri formats are shown below:

  • s3:// \ / \
  • https:// .s3.amazonaws.com / \
  • https:// s3.amazonaws.com / \ / \

Supported authorization methods' priority order is shown below:

  1. Temporary session tokens by assuming roles,
  2. Long term credentials.

Azure Blob Storage

The simplest way to configure object storage is by creating the standard ~/.azure/config file:

bash
$ cat ~/.azure/config
[storage]
account = devstoreaccount1
key = Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==

Alternatively, you can use the following environment variables when starting postgres to configure the Azure Blob Storage client:

  • AZURE_STORAGE_ACCOUNT: the storage account name of the Azure Blob
  • AZURE_STORAGE_KEY: the storage key of the Azure Blob
  • AZURE_STORAGE_CONNECTION_STRING: the connection string for the Azure Blob (overrides any other config)
  • AZURE_STORAGE_SAS_TOKEN: the storage SAS token for the Azure Blob
  • AZURE_TENANT_ID: the tenant id for client secret or workload identity auth (only via environment variables)
  • AZURE_CLIENT_ID: the client id for client secret or workload identity auth (only via environment variables)
  • AZURE_FEDERATED_TOKEN_FILE: the file system path to the federated token file to use for workload identity auth (only via environment variables)
  • AZURE_CLIENT_SECRET: the client secret for client secret auth (only via environment variables)
  • AZURE_STORAGE_ENDPOINT: the endpoint (only via environment variables)
  • AZURE_CONFIG_FILE: an alternative location for the config file (only via environment variables)
  • AZURE_ALLOW_HTTP: allows http endpoints (only via environment variables)

Config source priority order is shown below:

  1. Connection string (read from environment variable or config file),
  2. Environment variables,
  3. Config file.

Supported Azure Blob Storage uri formats are shown below:

  • az:// \ / \
  • azure:// \ / \
  • https:// .blob.core.windows.net / \

Supported authorization methods' priority order is shown below:

  1. Bearer token via client secret,
  2. Sas token,
  3. Storage key.

Http(s) Storage

Only https uris are supported by default. You can set ALLOW_HTTP environment variable to allow http uris.

Google Cloud Storage

The simplest way to configure object storage is by creating a json config file like [~/.config/gcloud/application_default_credentials.json] (can be generated by gcloud auth application-default login):

bash
$ cat ~/.config/gcloud/application_default_credentials.json
{
  "gcs_base_url": "http://localhost:4443",     
  "disable_oauth": true,
  "client_email": "",
  "private_key_id": "",
  "private_key": ""
}

Alternatively, you can use the following environment variables when starting postgres to configure the Google Cloud Storage client:

  • GOOGLE_SERVICE_ACCOUNT_KEY: json serialized service account key (only via environment variables)
  • GOOGLE_SERVICE_ACCOUNT_PATH: an alternative location for the config file (only via environment variables)

Supported Google Cloud Storage uri formats are shown below:

  • gs:// \ / \

Copy Options

pg_parquet supports the following options in the COPY TO command:

  • format parquet: you need to specify this option to read or write Parquet files which does not end with .parquet[.] extension,
  • file_size_bytes : the total file size per Parquet file. When set, the parquet files, with target size, are created under parent directory (named the same as file name). By default, when not specified, a single file is generated without creating a parent folder. You can specify total bytes without unit like file_size_bytes 2000000 or with unit (KB, MB, or GB) like file_size_bytes '1MB',
  • field_ids : fields ids that are assigned to the fields in Parquet file schema. By default, no field ids are assigned. Pass auto to let pg_parquet generat

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Rustazure-storagecolumnardata-ingestiondata-migration

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category数据库
PricingOpen source

> Related tools

P
PostgreSQL
功能强大的开源关系型数据库
R
Redis
内存数据结构存储,常用作缓存与队列
M
MySQL
广泛使用的开源关系型数据库