跳转到主要内容

pg_later

执行查询,并在稍后异步获取查询结果

pg_later · 执行查询,并在稍后异步获取查询结果

概览

ID扩展软件包版本类别许可证编程语言
1090pg_laterpg_later0.5.0TIMEPostgreSQLRust
属性可执行文件动态库需要预加载需要建扩展可迁移可信
--sLd--否是是是否否

软件包

类型仓库版本兼容的 PostgreSQL 大版本包名模式依赖
EXTPIGSTY0.5.019 18 17 16 15pg_laterpgmq
RPMPIGSTY0.5.019 18 17 16 15pg_later_$vpgmq_$v
DEBPIGSTY0.5.019 18 17 16 15postgresql-$v-pg-laterpostgresql-$v-pgmq
Linux / PGPG19PG18PG17PG16PG15
el8.x86_64N/APIGSTY 0.4.0PIGSTY 0.4.0PIGSTY 0.4.0PIGSTY 0.4.0
el8.aarch64N/APIGSTY 0.4.0PIGSTY 0.4.0PIGSTY 0.4.0PIGSTY 0.4.0
el9.x86_64PIGSTY 0.5.0PIGSTY 0.5.0PIGSTY 0.5.0PIGSTY 0.5.0PIGSTY 0.5.0
el9.aarch64PIGSTY 0.5.0PIGSTY 0.5.0PIGSTY 0.5.0PIGSTY 0.5.0PIGSTY 0.5.0
el10.x86_64PIGSTY 0.5.0PIGSTY 0.5.0PIGSTY 0.5.0PIGSTY 0.5.0PIGSTY 0.5.0
el10.aarch64PIGSTY 0.5.0PIGSTY 0.5.0PIGSTY 0.5.0PIGSTY 0.5.0PIGSTY 0.5.0
d12.x86_64PIGSTY 0.5.0PIGSTY 0.5.0PIGSTY 0.5.0PIGSTY 0.5.0PIGSTY 0.5.0
d12.aarch64PIGSTY 0.5.0PIGSTY 0.5.0PIGSTY 0.5.0PIGSTY 0.5.0PIGSTY 0.5.0
d13.x86_64PIGSTY 0.5.0PIGSTY 0.5.0PIGSTY 0.5.0PIGSTY 0.5.0PIGSTY 0.5.0
d13.aarch64PIGSTY 0.5.0PIGSTY 0.5.0PIGSTY 0.5.0PIGSTY 0.5.0PIGSTY 0.5.0
u22.x86_64PIGSTY 0.5.0PIGSTY 0.5.0PIGSTY 0.5.0PIGSTY 0.5.0PIGSTY 0.5.0
u22.aarch64PIGSTY 0.5.0PIGSTY 0.5.0PIGSTY 0.5.0PIGSTY 0.5.0PIGSTY 0.5.0
u24.x86_64PIGSTY 0.5.0PIGSTY 0.5.0PIGSTY 0.5.0PIGSTY 0.5.0PIGSTY 0.5.0
u24.aarch64PIGSTY 0.5.0PIGSTY 0.5.0PIGSTY 0.5.0PIGSTY 0.5.0PIGSTY 0.5.0
u26.x86_64PIGSTY 0.5.0PIGSTY 0.5.0PIGSTY 0.5.0PIGSTY 0.5.0PIGSTY 0.5.0
u26.aarch64PIGSTY 0.5.0PIGSTY 0.5.0PIGSTY 0.5.0PIGSTY 0.5.0PIGSTY 0.5.0
软件包版本平台仓库大小下载
pg_later_180.4.0el8.x86_64pigsty3.2 MiBpg_later_18-0.4.0-4PIGSTY.el8.x86_64.rpm
pg_later_180.4.0el8.aarch64pigsty2.9 MiBpg_later_18-0.4.0-4PIGSTY.el8.aarch64.rpm
pg_later_180.5.0el9.x86_64pigsty2.3 MiBpg_later_18-0.5.0-1PGSTY.el9.x86_64.rpm
pg_later_180.5.0el9.aarch64pigsty2.2 MiBpg_later_18-0.5.0-1PGSTY.el9.aarch64.rpm
pg_later_180.5.0el10.x86_64pigsty2.3 MiBpg_later_18-0.5.0-1PGSTY.el10.x86_64.rpm
pg_later_180.5.0el10.aarch64pigsty2.2 MiBpg_later_18-0.5.0-1PGSTY.el10.aarch64.rpm
postgresql-18-pg-later0.5.0d12.x86_64pigsty1.9 MiBpostgresql-18-pg-later_0.5.0-1PGSTY~bookworm_amd64.deb
postgresql-18-pg-later0.5.0d12.aarch64pigsty1.7 MiBpostgresql-18-pg-later_0.5.0-1PGSTY~bookworm_arm64.deb
postgresql-18-pg-later0.5.0d13.x86_64pigsty1.9 MiBpostgresql-18-pg-later_0.5.0-1PGSTY~trixie_amd64.deb
postgresql-18-pg-later0.5.0d13.aarch64pigsty1.7 MiBpostgresql-18-pg-later_0.5.0-1PGSTY~trixie_arm64.deb
postgresql-18-pg-later0.5.0u22.x86_64pigsty2.1 MiBpostgresql-18-pg-later_0.5.0-1PGSTY~jammy_amd64.deb
postgresql-18-pg-later0.5.0u22.aarch64pigsty2.0 MiBpostgresql-18-pg-later_0.5.0-1PGSTY~jammy_arm64.deb
postgresql-18-pg-later0.5.0u24.x86_64pigsty2.1 MiBpostgresql-18-pg-later_0.5.0-1PGSTY~noble_amd64.deb
postgresql-18-pg-later0.5.0u24.aarch64pigsty2.0 MiBpostgresql-18-pg-later_0.5.0-1PGSTY~noble_arm64.deb
postgresql-18-pg-later0.5.0u26.x86_64pigsty2.1 MiBpostgresql-18-pg-later_0.5.0-1PGSTY~resolute_amd64.deb
postgresql-18-pg-later0.5.0u26.aarch64pigsty2.0 MiBpostgresql-18-pg-later_0.5.0-1PGSTY~resolute_arm64.deb
软件包版本平台仓库大小下载
pg_later_170.4.0el8.x86_64pigsty3.2 MiBpg_later_17-0.4.0-4PIGSTY.el8.x86_64.rpm
pg_later_170.4.0el8.aarch64pigsty2.9 MiBpg_later_17-0.4.0-4PIGSTY.el8.aarch64.rpm
pg_later_170.5.0el9.x86_64pigsty2.3 MiBpg_later_17-0.5.0-1PGSTY.el9.x86_64.rpm
pg_later_170.5.0el9.aarch64pigsty2.2 MiBpg_later_17-0.5.0-1PGSTY.el9.aarch64.rpm
pg_later_170.5.0el10.x86_64pigsty2.3 MiBpg_later_17-0.5.0-1PGSTY.el10.x86_64.rpm
pg_later_170.5.0el10.aarch64pigsty2.2 MiBpg_later_17-0.5.0-1PGSTY.el10.aarch64.rpm
postgresql-17-pg-later0.5.0d12.x86_64pigsty1.9 MiBpostgresql-17-pg-later_0.5.0-1PGSTY~bookworm_amd64.deb
postgresql-17-pg-later0.5.0d12.aarch64pigsty1.7 MiBpostgresql-17-pg-later_0.5.0-1PGSTY~bookworm_arm64.deb
postgresql-17-pg-later0.5.0d13.x86_64pigsty1.9 MiBpostgresql-17-pg-later_0.5.0-1PGSTY~trixie_amd64.deb
postgresql-17-pg-later0.5.0d13.aarch64pigsty1.7 MiBpostgresql-17-pg-later_0.5.0-1PGSTY~trixie_arm64.deb
postgresql-17-pg-later0.5.0u22.x86_64pigsty2.1 MiBpostgresql-17-pg-later_0.5.0-1PGSTY~jammy_amd64.deb
postgresql-17-pg-later0.5.0u22.aarch64pigsty2.0 MiBpostgresql-17-pg-later_0.5.0-1PGSTY~jammy_arm64.deb
postgresql-17-pg-later0.5.0u24.x86_64pigsty2.1 MiBpostgresql-17-pg-later_0.5.0-1PGSTY~noble_amd64.deb
postgresql-17-pg-later0.5.0u24.aarch64pigsty2.0 MiBpostgresql-17-pg-later_0.5.0-1PGSTY~noble_arm64.deb
postgresql-17-pg-later0.5.0u26.x86_64pigsty2.1 MiBpostgresql-17-pg-later_0.5.0-1PGSTY~resolute_amd64.deb
postgresql-17-pg-later0.5.0u26.aarch64pigsty2.0 MiBpostgresql-17-pg-later_0.5.0-1PGSTY~resolute_arm64.deb
软件包版本平台仓库大小下载
pg_later_160.4.0el8.x86_64pigsty3.2 MiBpg_later_16-0.4.0-4PIGSTY.el8.x86_64.rpm
pg_later_160.4.0el8.aarch64pigsty2.9 MiBpg_later_16-0.4.0-4PIGSTY.el8.aarch64.rpm
pg_later_160.5.0el9.x86_64pigsty2.3 MiBpg_later_16-0.5.0-1PGSTY.el9.x86_64.rpm
pg_later_160.5.0el9.aarch64pigsty2.2 MiBpg_later_16-0.5.0-1PGSTY.el9.aarch64.rpm
pg_later_160.5.0el10.x86_64pigsty2.3 MiBpg_later_16-0.5.0-1PGSTY.el10.x86_64.rpm
pg_later_160.5.0el10.aarch64pigsty2.2 MiBpg_later_16-0.5.0-1PGSTY.el10.aarch64.rpm
postgresql-16-pg-later0.5.0d12.x86_64pigsty1.9 MiBpostgresql-16-pg-later_0.5.0-1PGSTY~bookworm_amd64.deb
postgresql-16-pg-later0.5.0d12.aarch64pigsty1.7 MiBpostgresql-16-pg-later_0.5.0-1PGSTY~bookworm_arm64.deb
postgresql-16-pg-later0.5.0d13.x86_64pigsty1.9 MiBpostgresql-16-pg-later_0.5.0-1PGSTY~trixie_amd64.deb
postgresql-16-pg-later0.5.0d13.aarch64pigsty1.7 MiBpostgresql-16-pg-later_0.5.0-1PGSTY~trixie_arm64.deb
postgresql-16-pg-later0.5.0u22.x86_64pigsty2.1 MiBpostgresql-16-pg-later_0.5.0-1PGSTY~jammy_amd64.deb
postgresql-16-pg-later0.5.0u22.aarch64pigsty2.0 MiBpostgresql-16-pg-later_0.5.0-1PGSTY~jammy_arm64.deb
postgresql-16-pg-later0.5.0u24.x86_64pigsty2.1 MiBpostgresql-16-pg-later_0.5.0-1PGSTY~noble_amd64.deb
postgresql-16-pg-later0.5.0u24.aarch64pigsty2.0 MiBpostgresql-16-pg-later_0.5.0-1PGSTY~noble_arm64.deb
postgresql-16-pg-later0.5.0u26.x86_64pigsty2.1 MiBpostgresql-16-pg-later_0.5.0-1PGSTY~resolute_amd64.deb
postgresql-16-pg-later0.5.0u26.aarch64pigsty2.0 MiBpostgresql-16-pg-later_0.5.0-1PGSTY~resolute_arm64.deb
软件包版本平台仓库大小下载
pg_later_150.4.0el8.x86_64pigsty3.2 MiBpg_later_15-0.4.0-4PIGSTY.el8.x86_64.rpm
pg_later_150.4.0el8.aarch64pigsty2.9 MiBpg_later_15-0.4.0-4PIGSTY.el8.aarch64.rpm
pg_later_150.5.0el9.x86_64pigsty2.3 MiBpg_later_15-0.5.0-1PGSTY.el9.x86_64.rpm
pg_later_150.5.0el9.aarch64pigsty2.2 MiBpg_later_15-0.5.0-1PGSTY.el9.aarch64.rpm
pg_later_150.5.0el10.x86_64pigsty2.3 MiBpg_later_15-0.5.0-1PGSTY.el10.x86_64.rpm
pg_later_150.5.0el10.aarch64pigsty2.2 MiBpg_later_15-0.5.0-1PGSTY.el10.aarch64.rpm
postgresql-15-pg-later0.5.0d12.x86_64pigsty1.9 MiBpostgresql-15-pg-later_0.5.0-1PGSTY~bookworm_amd64.deb
postgresql-15-pg-later0.5.0d12.aarch64pigsty1.7 MiBpostgresql-15-pg-later_0.5.0-1PGSTY~bookworm_arm64.deb
postgresql-15-pg-later0.5.0d13.x86_64pigsty1.9 MiBpostgresql-15-pg-later_0.5.0-1PGSTY~trixie_amd64.deb
postgresql-15-pg-later0.5.0d13.aarch64pigsty1.7 MiBpostgresql-15-pg-later_0.5.0-1PGSTY~trixie_arm64.deb
postgresql-15-pg-later0.5.0u22.x86_64pigsty2.1 MiBpostgresql-15-pg-later_0.5.0-1PGSTY~jammy_amd64.deb
postgresql-15-pg-later0.5.0u22.aarch64pigsty2.0 MiBpostgresql-15-pg-later_0.5.0-1PGSTY~jammy_arm64.deb
postgresql-15-pg-later0.5.0u24.x86_64pigsty2.1 MiBpostgresql-15-pg-later_0.5.0-1PGSTY~noble_amd64.deb
postgresql-15-pg-later0.5.0u24.aarch64pigsty2.0 MiBpostgresql-15-pg-later_0.5.0-1PGSTY~noble_arm64.deb
postgresql-15-pg-later0.5.0u26.x86_64pigsty2.1 MiBpostgresql-15-pg-later_0.5.0-1PGSTY~resolute_amd64.deb
postgresql-15-pg-later0.5.0u26.aarch64pigsty2.0 MiBpostgresql-15-pg-later_0.5.0-1PGSTY~resolute_arm64.deb

源码

pig build pkg pg_later;		# build rpm/deb

安装

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

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

使用 pig 安装扩展。

pig install pg_later;		# install by package name

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

将扩展加入 shared_preload_libraries,详见配置说明。

shared_preload_libraries = 'pg_later';

在数据库中创建扩展。

CREATE EXTENSION pg_later CASCADE; -- requires pgmq

用法

来源:

pg_later 0.5.0 通过 pgmq 队列异步执行 SQL,并返回任务 ID,供稍后获取结果。0.5.0 源码提供 PostgreSQL 15–19 的构建特性,较早版本还支持过更旧的主版本。

配置

该库要求加入 shared_preload_libraries 并重启 PostgreSQL。已有预加载列表时追加 pg_later。必须明确配置后台进程的数据库连接:依次选择 pglater.host、PGLATER_SOCKET_URL、DATABASE_URL。套接字配置使用 URL 查询参数指定主机、端口、用户与数据库。

shared_preload_libraries = 'pg_later'
pglater.host = 'postgresql:///?host=/tmp&port=5432&user=pglater_worker&dbname=app'

应单独创建后台角色并配置认证,仅授予队列及待执行语句所需的权限。任务使用该连接的身份执行,而非提交会话的角色。创建扩展需要超级用户,且必须能够安装 pgmq。请在后台连接指定的数据库中初始化队列。

快速开始

初始化扩展后端:

CREATE EXTENSION pg_later CASCADE;
SELECT pglater.init();

立即执行一条 SQL 查询:

SELECT pglater.exec(
  'SELECT * FROM pg_available_extensions ORDER BY name LIMIT 2'
) AS job_id;
 job_id
--------
     1

稍后通过任务 ID 获取结果:

SELECT pglater.fetch_results(1);
{
  "query": "select * from pg_available_extensions order by name limit 2",
  "job_id": 1,
  "result": [
    {
      "name": "adminpack",
      "comment": "administrative functions for PostgreSQL",
      "default_version": "2.1",
      "installed_version": null
    },
    {
      "name": "amcheck",
      "comment": "functions for verifying relation integrity",
      "default_version": "1.3",
      "installed_version": null
    }
  ],
  "status": "success"
}

API 与运行边界

  • pglater.exec(query, delay, validate) 返回队列消息 ID。延迟默认为零秒,验证默认开启;验证只检查语法解析,不检查授权或语句安全性。
  • pglater.fetch_results(job_id) 在结果存在时返回 JSON,尚无结果时返回 NULL;应检查结果状态以区分成功与失败的任务。
  • pglater.init 创建任务与结果队列。后台进程会归档已处理任务,包括报告查询失败的任务;这不等于自动重试 SQL。
  • 任务 SQL 会写入日志,结果行会整体转换为 JSON。应限制队列访问,避免在提交语句中放入密钥。该后台 API 不保留调用者的事务或会话状态。

表格阅读器