扩展管理:ext

如何使用 pig ext 子命令管理 PostgreSQL 扩展插件?

pig ext 命令是一个用于管理 PostgreSQL 扩展的综合工具。 它允许用户搜索、安装、删除、更新和管理 PostgreSQL 扩展插件,甚至包括内核包。


概述

pig ext - 管理 PostgreSQL 扩展

  pig repo add -ru             # 添加所有仓库并更新缓存(简单粗暴但有效)
  pig ext add pg17             # 安装可选的 postgresql 17 包
  pig ext list duck            # 在目录中搜索扩展
  pig ext scan -v 17          # 扫描 pg 17 已安装的扩展
  pig ext add pg_duckdb       # 安装指定的 postgresql 扩展

用法:
  pig ext [命令]

别名:
  ext, e, ex, pgext, extension

示例:

  pig ext list    [query]      # 列出并搜索扩展
  pig ext info    [ext...]     # 获取特定扩展的信息
  pig ext status  [-v]         # 显示已安装的扩展和 pg 状态
  pig ext add     [ext...]     # 为当前 pg 版本安装扩展
  pig ext rm      [ext...]     # 为当前 pg 版本移除扩展
  pig ext update  [ext...]     # 将扩展更新到最新版本
  pig ext import  [ext...]     # 下载扩展到本地仓库
  pig ext link    [ext...]     # 将 postgres 安装链接到路径
  pig ext upgrade              # 升级到最新的扩展目录


可用命令:
  add         安装 postgres 扩展
  import      导入扩展包到本地仓库
  info        获取扩展信息
  link        将 postgres 链接到活动 PATH
  list        列出并搜索可用扩展
  rm          移除 postgres 扩展
  scan        扫描活动 pg 的已安装扩展
  status      显示活动 pg 上已安装的扩展
  update      更新当前 pg 版本的已安装扩展
  upgrade     将扩展目录升级到最新版本

标志:
  -h, --help          显示帮助信息
  -p, --path string   通过 pg_config 路径指定 postgres
  -v, --version int   通过主版本号指定 postgres

全局标志:
      --debug              启用调试模式
  -i, --inventory string   配置清单路径
      --log-level string   日志级别:debug, info, warn, error, fatal, panic(默认 "info"      --log-path string    日志文件路径,默认为终端

使用 "pig ext [命令] --help" 获取有关命令的更多信息。

示例

要安装 postgres 扩展,你首先需要设置 repo

pig repo add pgdg pigsty -u    # 温和的方式添加 pgdg 和 pigsty 仓库
pig repo set -u                # 暴力方式移除并添加所有必需的仓库

然后你就可以搜索并安装 PostgreSQL 扩展:

pig ext install pg_duckdb
pig ext install pg_partman
pig ext install pg_cron
pig ext install pg_repack
pig ext install pg_stat_statements
pig ext install pg_stat_kcache

查看 扩展列表 获取可用扩展及其名称。

  1. 当未指定 PostgreSQL 版本时,工具会尝试从 PATH 中的 pg_config 检测活动的 PostgreSQL 安装
  2. PostgreSQL 可以通过主版本号(-v)或 pg_config 路径(-p)指定。 如果给定 -v,pig 将使用给定版本的 PGDG 内核包的默认路径。
    • 在 EL 发行版上,PG$v 的路径是 /usr/pgsql-$v/bin/pg_config
    • 在 DEB 发行版上,PG$v 的路径是 /usr/lib/postgresql/$v/bin/pg_config 等 如果给定 -p,pig 将使用 pg_config 路径查找 PostgreSQL 安装。
  3. 扩展管理器根据底层操作系统支持不同的包格式:
    • RHEL/CentOS/Rocky Linux/AlmaLinux 使用 RPM 包
    • Debian/Ubuntu 使用 DEB 包
  4. 某些扩展可能有依赖项,这些依赖项会在安装过程中自动解析。
  5. 谨慎使用 -y 标志,因为它会自动确认所有提示。

Pigsty 假设你已经安装了官方的 PGDG 内核包,如果没有,你可以这样安装:

pig ext install pg17          # 安装 PostgreSQL 17 内核(除了 devel 包)

ext list

列出并搜索扩展目录中的可用扩展。

列出并搜索可用扩展

用法:
  pig ext list [query] [flags]

别名:
  list, l, ls, find

示例:

  pig ext list                # 列出所有扩展
  pig ext list postgis        # 通过名称/描述搜索扩展
  pig ext ls olap             # 列出 olap 类别的扩展
  pig ext ls gis -v 16        # 列出 pg 16 的 gis 类别扩展

默认扩展目录定义在 cli/ext/assets/pigsty.csv

你可以使用 pig ext upgrade 更新到最新的扩展目录,它会将最新的扩展目录数据下载到 ~/.pig/pigsty.csv


ext info

显示特定扩展的详细信息。

pig ext info [ext...]

示例:

pig ext info postgis        # 显示关于 PostGIS 的详细信息
pig ext info timescaledb    # 显示关于 TimescaleDB 的信息
$ pig ext info postgis        # 显示关于 PostGIS 的详细信息

╭────────────────────────────────────────────────────────────────────────────╮
│ postgis                                                                    │
├────────────────────────────────────────────────────────────────────────────┤
│ PostGIS 几何和地理空间类型及函数                                           │
├────────────────────────────────────────────────────────────────────────────┤
│ 扩展名   : postgis                                                         │
│ 别名     : postgis                                                         │
│ 类别     : GIS                                                            │
│ 版本     : 3.5.2                                                          │
│ 许可证   : GPL-2.0                                                        │
│ 网站     : https://git.osgeo.org/gitea/postgis/postgis                    │
│ 详情     : https://pigsty.io/gis/postgis                                  │
├────────────────────────────────────────────────────────────────────────────┤
│ 扩展属性                                                                   │
├────────────────────────────────────────────────────────────────────────────┤
│ PostgreSQL 版本 │  可用于: 17, 16, 15, 14, 13                             │
│ CREATE  :  是   │  CREATE EXTENSION postgis;                               │
│ DYLOAD  :  否   │  无需加载共享库                                          │
│ TRUST   :  否   │  需要数据库超级用户安装                                  │
│ Reloc   :  否   │  模式: []                                               │
│ Depend  :  否   │                                                          │
├────────────────────────────────────────────────────────────────────────────┤
│ 被以下扩展依赖                                                             │
├────────────────────────────────────────────────────────────────────────────┤
│ - postgis_topology                                                         │
│ - postgis_raster                                                           │
│ - postgis_sfcgal                                                           │
│ - postgis_tiger_geocoder                                                   │
│ - pgrouting                                                                │
│ - pointcloud_postgis                                                       │
│ - h3_postgis                                                               │
│ - mobilitydb                                                               │
│ - documentdb                                                               │
├────────────────────────────────────────────────────────────────────────────┤
│ RPM 包                                                                     │
├────────────────────────────────────────────────────────────────────────────┤
│ 仓库          │  PGDG                                                     │
│ 包名          │  postgis35_$v*                                            │
│ 版本          │  3.5.2                                                    │
│ 可用性        │  17, 16, 15, 14, 13                                       │
├────────────────────────────────────────────────────────────────────────────┤
│ DEB 包                                                                     │
├────────────────────────────────────────────────────────────────────────────┤
│ 仓库          │  PGDG                                                     │
│ 包名          │  postgresql-$v-postgis-3 postgresql-$v-postgis-3-scripts  │
│ 版本          │  3.5.2                                                    │
│ 可用性        │  17, 16, 15, 14, 13                                       │
╰────────────────────────────────────────────────────────────────────────────╯

status - 显示已安装的扩展

显示活动 PostgreSQL 实例上已安装扩展的状态。

pig ext status [-c]

选项:

  • -c, --contrib: 包括 contrib 扩展

示例:

pig ext status              # 显示已安装的扩展
pig ext status -c           # 显示已安装的扩展,包括 contrib 扩展
pig ext status -v 16        # 显示 PostgreSQL 16 已安装的扩展

ext scan

扫描活动 PostgreSQL 实例以查找已安装的扩展。

pig ext scan [-v version]

它将扫描 postgres 扩展文件夹以查找所有实际安装的扩展。

$ pig ext status

Installed:
* PostgreSQL 17.4 (Debian 17.4-1.pgdg120+2)  85  Extensions

Active:
PG Version      :  PostgreSQL 17.4 (Debian 17.4-1.pgdg120+2)
Config Path     :  /usr/lib/postgresql/17/bin/pg_config
Binary Path     :  /usr/lib/postgresql/17/bin
Library Path    :  /usr/lib/postgresql/17/lib
Extension Path  :  /usr/share/postgresql/17/extension
Extension Stat  :  18 Installed (PIGSTY 8, PGDG 10) + 67 CONTRIB = 85 Total

Name                          Version  Cate   Flags   License       Repo    Package                                                  Description
----                          -------  ----   ------  -------       ------  ------------                                             ---------------------
timescaledb                   2.18.2   TIME   -dsl--  Timescale     PIGSTY  postgresql-17-timescaledb-tsl                            Enables scalable inserts and complex queries for time-series dat
postgis                       3.5.2    GIS    -ds---  GPL-2.0       PGDG    postgresql-17-postgis-3 postgresql-$v-postgis-3-scripts  PostGIS geometry and geography spatial types and functions
postgis_topology              3.5.2    GIS    -ds---  GPL-2.0       PGDG    postgresql-17-postgis-3 postgresql-$v-postgis-3-scripts  PostGIS topology spatial types and functions
postgis_raster                3.5.2    GIS    -ds---  GPL-2.0       PGDG    postgresql-17-postgis-3 postgresql-$v-postgis-3-scripts  PostGIS raster types and functions
postgis_sfcgal                3.5.2    GIS    -ds--r  GPL-2.0       PGDG    postgresql-17-postgis-3 postgresql-$v-postgis-3-scripts  PostGIS SFCGAL functions
postgis_tiger_geocoder        3.5.2    GIS    -ds-t-  GPL-2.0       PGDG    postgresql-17-postgis-3 postgresql-$v-postgis-3-scripts  PostGIS tiger geocoder and reverse geocoder
address_standardizer          3.5.2    GIS    -ds--r  GPL-2.0       PGDG    postgresql-17-postgis-3 postgresql-$v-postgis-3-scripts  Used to parse an address into constituent elements. Generally us
address_standardizer_data_us  3.5.2    GIS    -ds--r  GPL-2.0       PGDG    postgresql-17-postgis-3 postgresql-$v-postgis-3-scripts  Address Standardizer US dataset example
vector                        0.8.0    RAG    -ds--r  PostgreSQL    PGDG    postgresql-17-pgvector                                   vector data type and ivfflat and hnsw access methods
pg_search                     0.15.2   FTS    -ds-t-  AGPL-3.0      PIGSTY  postgresql-17-pg-search                                  pg_search: Full text search for PostgreSQL using BM25
pgroonga                      4.0.0    FTS    -ds-tr  PostgreSQL    PIGSTY  postgresql-17-pgroonga                                   Use Groonga as index, fast full text search platform for all lan
pgroonga_database             4.0.0    FTS    -ds-tr  PostgreSQL    PIGSTY  postgresql-17-pgroonga                                   PGroonga database management module
citus                         13.0.1   OLAP   -dsl--  AGPL-3.0      PIGSTY  postgresql-17-citus                                      Distributed PostgreSQL as an extension
citus_columnar                11.3-1   OLAP   -ds---  AGPL-3.0      PIGSTY  postgresql-17-citus                                      Citus columnar storage engine
pg_mooncake                   0.1.2    OLAP   ------  MIT           PIGSTY  postgresql-17-pg-mooncake                                Columnstore Table in Postgres
plv8                          3.2.3    LANG   -ds---  PostgreSQL    PIGSTY  postgresql-17-plv8                                       PL/JavaScript (v8) trusted procedural language
pg_repack                     1.5.2    ADMIN  bds---  BSD 3-Clause  PGDG    postgresql-17-repack                                     Reorganize tables in PostgreSQL databases with minimal locks
wal2json                      2.5.3    ETL    --s--x  BSD 3-Clause  PGDG    postgresql-17-wal2json                                   Changing data capture in JSON format

(18 Rows) (Flags: b = HasBin, d = HasDDL, s = HasSolib, l = NeedLoad, t = Trusted, r = Relocatable, x = Unknown)

ext add

安装一个或多个 PostgreSQL 扩展。

安装 postgres 扩展

用法:
  pig ext add [flags]

别名:
  add, a, install, ins

示例:

Description:
  pig ext install pg_duckdb                  # 安装一个扩展
  pig ext install postgis timescaledb        # 安装多个扩展
  pig ext add     pgvector pgvectorscale     # 其他别名:add, ins, i, a
  pig ext ins     pg_search -y               # 自动确认安装
  pig ext install pgsql                      # 安装最新版本的 postgresql kernel
  pig ext a pg17                             # 安装 postgresql 17 kernel packages
  pig ext ins pg16                           # 安装 postgresql 16 kernel packages
  pig ext install pg15-core                  # 安装 postgresql 15 core packages
  pig ext install pg14-main -y               # 安装 pg 14 + essential extensions (vector, repack, wal2json)
  pig ext install pg13-devel --yes           # 安装 pg 13 devel packages (auto-confirm)
  pig ext install pgsql-common               # 安装 common utils such as patroni pgbouncer pgbackrest,...


Flags:
  -h, --help   help for add
  -y, --yes   自动确认安装

ext rm

移除一个或多个 PostgreSQL 扩展。

pig ext rm [ext...] [-y]

选项:

  • -y, --yes: 自动确认移除

示例:

pig ext rm pg_duckdb                   # 移除特定扩展
pig ext rm postgis timescaledb         # 移除多个扩展
pig ext rm pgvector -y                 # 自动确认移除

ext update

更新已安装的扩展到最新版本。

pig ext update [ext...] [-y]

选项:

  • -y, --yes: 自动确认更新

示例:

pig ext update                         # 更新所有已安装的扩展
pig ext update postgis                 # 更新特定扩展
pig ext update postgis timescaledb     # 更新多个扩展
pig ext update -y                      # 自动确认更新

pig import

下载扩展包到本地仓库进行离线安装。

用法:
  pig ext import [ext...] [flags]

别名:
  import, get

示例:

  pig ext import postgis                # 导入 postgis 扩展包
  pig ext import timescaledb pg_cron    # 导入多个扩展
  pig ext import pg16                   # 导入 postgresql 16 包
  pig ext import pgsql-common           # 导入 common utilities
  pig ext import -d /www/pigsty postgis # 导入到特定路径


Flags:
  -h, --help          help for import
  -d, --repo string   specify repo dir (default "/www/pigsty")

选项:

  • -d, --repo: 指定仓库目录(默认:/www/pigsty)

示例:

pig ext import postgis                 # 导入 PostGIS 包
pig ext import timescaledb pg_cron     # 导入多个扩展包
pig ext import pg16                    # 导入 PostgreSQL 16 包
pig ext import pgsql-common            # 导入 common 实用程序包

将 PostgreSQL 安装链接到系统 PATH。

将 postgres 链接到活动 PATH

用法:
  pig ext link <-v pgver|-p pgpath> [flags]

别名:
  link, ln

示例:

  pig ext link 16                      # 将 pgdg postgresql 16 链接到 /usr/pgsql
  pig ext link /usr/pgsql-16           # 将特定 pg 链接到 /usr/pgsql
  pig ext link /u01/polardb_pg         # 将 polardb pg 链接到 /usr/pgsql
  pig ext link null|none|nil|nop|no    # 取消链接当前 postgres 安装


Flags:
  -h, --help   help for link

示例:

pig ext link 17                        # 将 PostgreSQL 17 链接到 /usr/pgsql
pig ext link 16                        # 将 PostgreSQL 16 链接到 /usr/pgsql
pig ext link /usr/pgsql-16             # 从特定路径将 PostgreSQL 链接至 /usr/pgsql
pig ext link null                      # 取消链接当前 PostgreSQL 安装

upgrade

将扩展目录升级到最新版本。

pig ext upgrade




最后修改 2025-03-22: update pig docs (3a10e19)