跳转到主要内容

aws_s3

从 S3 导入导出数据(兼容 RDS aws_s3 扩展)

aws_s3 · 从 S3 导入导出数据(兼容 RDS aws_s3 扩展)

概览

ID扩展软件包版本类别许可证编程语言
8800aws_s3aws_s30.0.1FDWApache-2.0SQL
属性可执行文件动态库需要预加载需要建扩展可迁移可信
----d-r否否否是是否

软件包

类型仓库版本兼容的 PostgreSQL 大版本包名模式依赖
EXTPIGSTY0.0.119 18 17 16 15aws_s3-
RPMPIGSTY0.0.119 18 17 16 15aws_s3_$v-
DEBPIGSTY0.0.119 18 17 16 15postgresql-$v-aws-s3-
Linux / PGPG19PG18PG17PG16PG15
el8.x86_64N/APIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1
el8.aarch64N/APIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1
el9.x86_64PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1
el9.aarch64PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1
el10.x86_64PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1
el10.aarch64PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1
d12.x86_64PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1
d12.aarch64PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1
d13.x86_64PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1
d13.aarch64PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1
u22.x86_64PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1
u22.aarch64PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1
u24.x86_64PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1
u24.aarch64PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1
u26.x86_64PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1
u26.aarch64PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1PIGSTY 0.0.1
软件包版本平台仓库大小下载
aws_s3_190.0.1el9.x86_64pigsty9.2 KiBaws_s3_19-0.0.1-1PGSTY.el9.noarch.rpm
aws_s3_190.0.1el9.aarch64pigsty9.2 KiBaws_s3_19-0.0.1-1PGSTY.el9.noarch.rpm
aws_s3_190.0.1el10.x86_64pigsty9.4 KiBaws_s3_19-0.0.1-1PGSTY.el10.noarch.rpm
aws_s3_190.0.1el10.aarch64pigsty9.4 KiBaws_s3_19-0.0.1-1PGSTY.el10.noarch.rpm
postgresql-19-aws-s30.0.1d12.x86_64pigsty10.4 KiBpostgresql-19-aws-s3_0.0.1-1PGSTY~bookworm_all.deb
postgresql-19-aws-s30.0.1d12.aarch64pigsty10.4 KiBpostgresql-19-aws-s3_0.0.1-1PGSTY~bookworm_all.deb
postgresql-19-aws-s30.0.1d13.x86_64pigsty10.4 KiBpostgresql-19-aws-s3_0.0.1-1PGSTY~trixie_all.deb
postgresql-19-aws-s30.0.1d13.aarch64pigsty10.4 KiBpostgresql-19-aws-s3_0.0.1-1PGSTY~trixie_all.deb
postgresql-19-aws-s30.0.1u22.x86_64pigsty10.3 KiBpostgresql-19-aws-s3_0.0.1-1PGSTY~jammy_all.deb
postgresql-19-aws-s30.0.1u22.aarch64pigsty10.3 KiBpostgresql-19-aws-s3_0.0.1-1PGSTY~jammy_all.deb
postgresql-19-aws-s30.0.1u24.x86_64pigsty10.3 KiBpostgresql-19-aws-s3_0.0.1-1PGSTY~noble_all.deb
postgresql-19-aws-s30.0.1u24.aarch64pigsty10.3 KiBpostgresql-19-aws-s3_0.0.1-1PGSTY~noble_all.deb
postgresql-19-aws-s30.0.1u26.x86_64pigsty10.4 KiBpostgresql-19-aws-s3_0.0.1-1PGSTY~resolute_all.deb
postgresql-19-aws-s30.0.1u26.aarch64pigsty10.4 KiBpostgresql-19-aws-s3_0.0.1-1PGSTY~resolute_all.deb
软件包版本平台仓库大小下载
aws_s3_180.0.1el8.x86_64pigsty9.3 KiBaws_s3_18-0.0.1-1PGSTY.el8.noarch.rpm
aws_s3_180.0.1el8.aarch64pigsty9.3 KiBaws_s3_18-0.0.1-1PGSTY.el8.noarch.rpm
aws_s3_180.0.1el9.x86_64pigsty9.2 KiBaws_s3_18-0.0.1-1PGSTY.el9.noarch.rpm
aws_s3_180.0.1el9.aarch64pigsty9.2 KiBaws_s3_18-0.0.1-1PGSTY.el9.noarch.rpm
aws_s3_180.0.1el10.x86_64pigsty9.4 KiBaws_s3_18-0.0.1-1PGSTY.el10.noarch.rpm
aws_s3_180.0.1el10.aarch64pigsty9.4 KiBaws_s3_18-0.0.1-1PGSTY.el10.noarch.rpm
postgresql-18-aws-s30.0.1d12.x86_64pigsty10.4 KiBpostgresql-18-aws-s3_0.0.1-1PGSTY~bookworm_all.deb
postgresql-18-aws-s30.0.1d12.aarch64pigsty10.4 KiBpostgresql-18-aws-s3_0.0.1-1PGSTY~bookworm_all.deb
postgresql-18-aws-s30.0.1d13.x86_64pigsty10.4 KiBpostgresql-18-aws-s3_0.0.1-1PGSTY~trixie_all.deb
postgresql-18-aws-s30.0.1d13.aarch64pigsty10.4 KiBpostgresql-18-aws-s3_0.0.1-1PGSTY~trixie_all.deb
postgresql-18-aws-s30.0.1u22.x86_64pigsty10.3 KiBpostgresql-18-aws-s3_0.0.1-1PGSTY~jammy_all.deb
postgresql-18-aws-s30.0.1u22.aarch64pigsty10.3 KiBpostgresql-18-aws-s3_0.0.1-1PGSTY~jammy_all.deb
postgresql-18-aws-s30.0.1u24.x86_64pigsty10.3 KiBpostgresql-18-aws-s3_0.0.1-1PGSTY~noble_all.deb
postgresql-18-aws-s30.0.1u24.aarch64pigsty10.3 KiBpostgresql-18-aws-s3_0.0.1-1PGSTY~noble_all.deb
postgresql-18-aws-s30.0.1u26.x86_64pigsty10.3 KiBpostgresql-18-aws-s3_0.0.1-1PGSTY~resolute_all.deb
postgresql-18-aws-s30.0.1u26.aarch64pigsty10.3 KiBpostgresql-18-aws-s3_0.0.1-1PGSTY~resolute_all.deb
软件包版本平台仓库大小下载
aws_s3_170.0.1el8.x86_64pigsty9.3 KiBaws_s3_17-0.0.1-1PGSTY.el8.noarch.rpm
aws_s3_170.0.1el8.aarch64pigsty9.3 KiBaws_s3_17-0.0.1-1PGSTY.el8.noarch.rpm
aws_s3_170.0.1el9.x86_64pigsty9.2 KiBaws_s3_17-0.0.1-1PGSTY.el9.noarch.rpm
aws_s3_170.0.1el9.aarch64pigsty9.2 KiBaws_s3_17-0.0.1-1PGSTY.el9.noarch.rpm
aws_s3_170.0.1el10.x86_64pigsty9.4 KiBaws_s3_17-0.0.1-1PGSTY.el10.noarch.rpm
aws_s3_170.0.1el10.aarch64pigsty9.4 KiBaws_s3_17-0.0.1-1PGSTY.el10.noarch.rpm
postgresql-17-aws-s30.0.1d12.x86_64pigsty10.4 KiBpostgresql-17-aws-s3_0.0.1-1PGSTY~bookworm_all.deb
postgresql-17-aws-s30.0.1d12.aarch64pigsty10.4 KiBpostgresql-17-aws-s3_0.0.1-1PGSTY~bookworm_all.deb
postgresql-17-aws-s30.0.1d13.x86_64pigsty10.4 KiBpostgresql-17-aws-s3_0.0.1-1PGSTY~trixie_all.deb
postgresql-17-aws-s30.0.1d13.aarch64pigsty10.4 KiBpostgresql-17-aws-s3_0.0.1-1PGSTY~trixie_all.deb
postgresql-17-aws-s30.0.1u22.x86_64pigsty10.3 KiBpostgresql-17-aws-s3_0.0.1-1PGSTY~jammy_all.deb
postgresql-17-aws-s30.0.1u22.aarch64pigsty10.3 KiBpostgresql-17-aws-s3_0.0.1-1PGSTY~jammy_all.deb
postgresql-17-aws-s30.0.1u24.x86_64pigsty10.3 KiBpostgresql-17-aws-s3_0.0.1-1PGSTY~noble_all.deb
postgresql-17-aws-s30.0.1u24.aarch64pigsty10.3 KiBpostgresql-17-aws-s3_0.0.1-1PGSTY~noble_all.deb
postgresql-17-aws-s30.0.1u26.x86_64pigsty10.4 KiBpostgresql-17-aws-s3_0.0.1-1PGSTY~resolute_all.deb
postgresql-17-aws-s30.0.1u26.aarch64pigsty10.4 KiBpostgresql-17-aws-s3_0.0.1-1PGSTY~resolute_all.deb
软件包版本平台仓库大小下载
aws_s3_160.0.1el8.x86_64pigsty9.3 KiBaws_s3_16-0.0.1-1PGSTY.el8.noarch.rpm
aws_s3_160.0.1el8.aarch64pigsty9.3 KiBaws_s3_16-0.0.1-1PGSTY.el8.noarch.rpm
aws_s3_160.0.1el9.x86_64pigsty9.2 KiBaws_s3_16-0.0.1-1PGSTY.el9.noarch.rpm
aws_s3_160.0.1el9.aarch64pigsty9.2 KiBaws_s3_16-0.0.1-1PGSTY.el9.noarch.rpm
aws_s3_160.0.1el10.x86_64pigsty9.4 KiBaws_s3_16-0.0.1-1PGSTY.el10.noarch.rpm
aws_s3_160.0.1el10.aarch64pigsty9.4 KiBaws_s3_16-0.0.1-1PGSTY.el10.noarch.rpm
postgresql-16-aws-s30.0.1d12.x86_64pigsty10.4 KiBpostgresql-16-aws-s3_0.0.1-1PGSTY~bookworm_all.deb
postgresql-16-aws-s30.0.1d12.aarch64pigsty10.4 KiBpostgresql-16-aws-s3_0.0.1-1PGSTY~bookworm_all.deb
postgresql-16-aws-s30.0.1d13.x86_64pigsty10.4 KiBpostgresql-16-aws-s3_0.0.1-1PGSTY~trixie_all.deb
postgresql-16-aws-s30.0.1d13.aarch64pigsty10.4 KiBpostgresql-16-aws-s3_0.0.1-1PGSTY~trixie_all.deb
postgresql-16-aws-s30.0.1u22.x86_64pigsty10.3 KiBpostgresql-16-aws-s3_0.0.1-1PGSTY~jammy_all.deb
postgresql-16-aws-s30.0.1u22.aarch64pigsty10.3 KiBpostgresql-16-aws-s3_0.0.1-1PGSTY~jammy_all.deb
postgresql-16-aws-s30.0.1u24.x86_64pigsty10.3 KiBpostgresql-16-aws-s3_0.0.1-1PGSTY~noble_all.deb
postgresql-16-aws-s30.0.1u24.aarch64pigsty10.3 KiBpostgresql-16-aws-s3_0.0.1-1PGSTY~noble_all.deb
postgresql-16-aws-s30.0.1u26.x86_64pigsty10.4 KiBpostgresql-16-aws-s3_0.0.1-1PGSTY~resolute_all.deb
postgresql-16-aws-s30.0.1u26.aarch64pigsty10.4 KiBpostgresql-16-aws-s3_0.0.1-1PGSTY~resolute_all.deb
软件包版本平台仓库大小下载
aws_s3_150.0.1el8.x86_64pigsty9.3 KiBaws_s3_15-0.0.1-1PGSTY.el8.noarch.rpm
aws_s3_150.0.1el8.aarch64pigsty9.3 KiBaws_s3_15-0.0.1-1PGSTY.el8.noarch.rpm
aws_s3_150.0.1el9.x86_64pigsty9.2 KiBaws_s3_15-0.0.1-1PGSTY.el9.noarch.rpm
aws_s3_150.0.1el9.aarch64pigsty9.2 KiBaws_s3_15-0.0.1-1PGSTY.el9.noarch.rpm
aws_s3_150.0.1el10.x86_64pigsty9.4 KiBaws_s3_15-0.0.1-1PGSTY.el10.noarch.rpm
aws_s3_150.0.1el10.aarch64pigsty9.4 KiBaws_s3_15-0.0.1-1PGSTY.el10.noarch.rpm
postgresql-15-aws-s30.0.1d12.x86_64pigsty10.4 KiBpostgresql-15-aws-s3_0.0.1-1PGSTY~bookworm_all.deb
postgresql-15-aws-s30.0.1d12.aarch64pigsty10.4 KiBpostgresql-15-aws-s3_0.0.1-1PGSTY~bookworm_all.deb
postgresql-15-aws-s30.0.1d13.x86_64pigsty10.4 KiBpostgresql-15-aws-s3_0.0.1-1PGSTY~trixie_all.deb
postgresql-15-aws-s30.0.1d13.aarch64pigsty10.4 KiBpostgresql-15-aws-s3_0.0.1-1PGSTY~trixie_all.deb
postgresql-15-aws-s30.0.1u22.x86_64pigsty10.3 KiBpostgresql-15-aws-s3_0.0.1-1PGSTY~jammy_all.deb
postgresql-15-aws-s30.0.1u22.aarch64pigsty10.3 KiBpostgresql-15-aws-s3_0.0.1-1PGSTY~jammy_all.deb
postgresql-15-aws-s30.0.1u24.x86_64pigsty10.3 KiBpostgresql-15-aws-s3_0.0.1-1PGSTY~noble_all.deb
postgresql-15-aws-s30.0.1u24.aarch64pigsty10.3 KiBpostgresql-15-aws-s3_0.0.1-1PGSTY~noble_all.deb
postgresql-15-aws-s30.0.1u26.x86_64pigsty10.4 KiBpostgresql-15-aws-s3_0.0.1-1PGSTY~resolute_all.deb
postgresql-15-aws-s30.0.1u26.aarch64pigsty10.4 KiBpostgresql-15-aws-s3_0.0.1-1PGSTY~resolute_all.deb

源码

pig build pkg aws_s3;		# build rpm/deb

安装

启用 PGDG 和 PIGSTY 仓库并更新缓存。

pig repo add pgsql -u   # add both repo and update cache

使用 pig 安装扩展。

pig install aws_s3;		# install by package name

pig install aws_s3 -v 19;   # install for PG 19
pig install aws_s3 -v 18;   # install for PG 18
pig install aws_s3 -v 17;   # install for PG 17
pig install aws_s3 -v 16;   # install for PG 16
pig install aws_s3 -v 15;   # install for PG 15

在数据库中创建扩展。

CREATE EXTENSION aws_s3;

用法

aws_s3: 从 S3 导入/导出数据的 PostgreSQL 扩展

设置凭证

通过 PostgreSQL 会话变量配置 AWS 凭证:

SET aws_s3.access_key_id TO 'your_access_key';
SET aws_s3.secret_key TO 'your_secret_key';
SET aws_s3.session_token TO 'optional_session_token';  -- 使用临时凭证时

本地开发使用 LocalStack:

SET aws_s3.endpoint_url TO 'http://localhost:4566';

从 S3 导入数据

CREATE EXTENSION aws_s3;

CREATE TABLE animals (
  name text,
  age int
);

SELECT aws_s3.table_import_from_s3(
  'animals',
  '',
  '(FORMAT CSV, DELIMITER '','', HEADER true)',
  'my-bucket',
  'animals.csv',
  'us-east-1'
);

SELECT * FROM animals;

参数: 表名、列列表(空字符串表示全部)、COPY 选项、S3 桶名、S3 键名、AWS 区域。

导出数据到 S3

SELECT * FROM aws_s3.query_export_to_s3(
  'SELECT * FROM animals',
  'my-bucket',
  'export/animals.csv',
  'us-east-1',
  options := 'FORMAT CSV, HEADER true'
);

参数: SQL 查询、S3 桶名、S3 键名、AWS 区域、COPY 选项。

特性

  • 带有 Content-Encoding=gzip 元数据的文件在导入时自动解压
  • 凭证可以作为函数参数直接传递或通过会话变量设置
  • 使用与 PostgreSQL 相同的 COPY 格式选项(CSV、TEXT、BINARY,以及所有相关设置如 DELIMITER、HEADER、NULL 等)

表格阅读器