documentdb

微软DocumentDB的API层

概览

扩展包名版本分类许可证语言
documentdb0.114SIMMITC
ID扩展名BinLibLoadCreateTrustReloc模式
9000documentdb-
9010documentdb_core-
9020documentdb_distributed-
9030documentdb_extended_rum-
相关扩展documentdb_core pg_cron postgis tsm_system_rows vector mongo_fdw wal2mongo pg_jsonschema jsquery
下游依赖documentdb_distributed documentdb_extended_rum

版本

类型仓库版本PG 大版本包名依赖
EXTPIGSTY0.1141817161514documentdbdocumentdb_core, pg_cron, postgis, tsm_system_rows, vector
RPMPIGSTY0.1141817161514documentdb_$vpostgresql$v-contrib, pg_cron_$v, pgvector_$v, rum_$v, postgis36_$v
DEBPIGSTY0.1141817161514postgresql-$v-documentdbpostgresql-$v-cron, postgresql-$v-pgvector, postgresql-$v-rum, postgresql-$v-postgis-3
OS / PGPG18PG17PG16PG15PG14
el8.x86_64N/A
el8.aarch64N/A
el9.x86_64N/A
el9.aarch64N/A
el10.x86_64N/A
el10.aarch64N/A
d12.x86_64N/A
d12.aarch64
PIGSTY 0.114
PIGSTY 0.114
PIGSTY 0.114
PIGSTY 0.114
N/A
d13.x86_64N/A
d13.aarch64N/A
u22.x86_64
PIGSTY 0.114
PIGSTY 0.114
PIGSTY 0.114
PIGSTY 0.114
N/A
u22.aarch64
PIGSTY 0.114
PIGSTY 0.114
PIGSTY 0.114
PIGSTY 0.114
N/A
u24.x86_64
PIGSTY 0.114
PIGSTY 0.114
PIGSTY 0.114
PIGSTY 0.114
N/A
u24.aarch64
PIGSTY 0.114
PIGSTY 0.114
PIGSTY 0.114
PIGSTY 0.114
N/A
u26.x86_64N/A
u26.aarch64N/A

构建

您可以使用 pig build 命令构建 documentdb 扩展的 RPM / DEB 包:

pig build pkg documentdb         # 构建 RPM / DEB 包

安装

您可以直接安装 documentdb 扩展包的预置二进制包,首先确保 PGDGPIGSTY 仓库已经添加并启用:

pig repo add pgsql -u          # 添加仓库并更新缓存

使用 pig 或者是 apt/yum/dnf 安装扩展:

pig install documentdb;          # 当前活跃 PG 版本安装
pig ext install -y documentdb -v 18  # PG 18
pig ext install -y documentdb -v 17  # PG 17
pig ext install -y documentdb -v 16  # PG 16
pig ext install -y documentdb -v 15  # PG 15
dnf install -y documentdb_18       # PG 18
dnf install -y documentdb_17       # PG 17
dnf install -y documentdb_16       # PG 16
dnf install -y documentdb_15       # PG 15
apt install -y postgresql-18-documentdb   # PG 18
apt install -y postgresql-17-documentdb   # PG 17
apt install -y postgresql-16-documentdb   # PG 16
apt install -y postgresql-15-documentdb   # PG 15

预加载配置

shared_preload_libraries = 'pg_documentdb, pg_documentdb_core, pg_cron';

创建扩展

CREATE EXTENSION documentdb CASCADE;  -- 依赖: documentdb_core, pg_cron, postgis, tsm_system_rows, vector

用法

来源:

documentdb 是 PostgreSQL 的公共 API 扩展,用于 DocumentDB,这是一个基于 PostgreSQL 开源的 MongoDB 兼容文档数据库。它存储 BSON 文档并实现 CRUD、聚合、全文搜索、地理空间和向量工作流。MongoDB 驱动程序需要单独的 DocumentDB 网关;仅安装此扩展不会暴露 Wire-Protocol 监听器,而是 PostgreSQL API。

配置与安装

官方部署助手使用 pg_cron 预加载核心库和 API 库。更改此设置后,请重启 PostgreSQL:

shared_preload_libraries = 'pg_cron, pg_documentdb_core, pg_documentdb'

安装公共扩展及其声明的依赖项:

CREATE EXTENSION documentdb CASCADE;

CASCADE 可以在文件存在时安装 documentdb_corepg_crontsm_system_rowsvectorpostgis。安装仅限超级用户且不可重定位。

原生 SQL 工作流

SQL 接口使用数据库名、集合名和 BSON 命令文档:

SELECT documentdb_api.create_collection('appdb', 'people');

SELECT documentdb_api.insert_one(
  'appdb',
  'people',
  '{"_id": 1, "name": "Ada", "team": "storage"}',
  NULL
);

SELECT document
FROM documentdb_api_catalog.bson_aggregation_find(
  'appdb',
  '{"find":"people","filter":{"team":"storage"}}'
);

为了应用程序兼容性,请运行网关并在其配置的 TLS 端点上使用受支持的 MongoDB 驱动程序。网关将 Wire-Protocol 命令转换为此 PostgreSQL API。

重要对象

  • documentdb_api 包含集合管理及命令函数,如 create_collectioninsert_one
  • documentdb_api_catalog.bson_aggregation_find 执行 MongoDB 风格的查找规范并返回 BSON 文档。
  • documentdb_core.bson 是由 documentdb_core 提供的存储和交换类型。
  • DocumentDB 角色和内部模式将公共读写操作与管理及实现对象分开。
  • documentdb.enableNonBlockingUniqueIndexBuild 控制 v0.114 路径下的后台唯一有序索引构建,并在该版本中默认启用。

版本与运行注意事项

v0.114-0 标签的变更日志默认启用了模式验证,修复了验证器传播和缓存问题,并启用了非阻塞唯一有序索引构建。它还记录了网关配置、连通性检查、TLS 和凭证处理改进。该变更日志中的两个 RUM 优化仍受功能开关控制且默认禁用;请勿将它们描述为已启用行为。

MongoDB 兼容性并不等同于所有 MongoDB 服务器版本。应测试应用实际使用的操作符、索引行为、事务、模式验证、身份验证和驱动行为。请确保 documentdbdocumentdb_core、网关及可选的分布式/索引组件来自同一发行系列。