byteamagic

从 PostgreSQL bytea 值检测 MIME 类型与文件格式

概览

扩展包名版本分类许可证语言
pg_byteamagic0.2.4UTILBSD 2-ClauseC
ID扩展名BinLibLoadCreateTrustReloc模式
4275byteamagic-

Extension name is byteamagic; package name is pg_byteamagic.

版本

类型仓库版本PG 大版本包名依赖
EXTPIGSTY0.2.41817161514pg_byteamagic-
RPMPIGSTY0.2.41817161514pg_byteamagic_$v-
DEBPIGSTY0.2.41817161514postgresql-$v-pg-byteamagic-
OS / PGPG18PG17PG16PG15PG14
el8.x86_64
el8.aarch64
el9.x86_64
el9.aarch64
el10.x86_64
el10.aarch64
d12.x86_64
PIGSTY 0.2.4
PIGSTY 0.2.4
PIGSTY 0.2.4
PIGSTY 0.2.4
PIGSTY 0.2.4
d12.aarch64
PIGSTY 0.2.4
PIGSTY 0.2.4
PIGSTY 0.2.4
PIGSTY 0.2.4
PIGSTY 0.2.4
d13.x86_64
PIGSTY 0.2.4
PIGSTY 0.2.4
PIGSTY 0.2.4
PIGSTY 0.2.4
PIGSTY 0.2.4
d13.aarch64
PIGSTY 0.2.4
PIGSTY 0.2.4
PIGSTY 0.2.4
PIGSTY 0.2.4
PIGSTY 0.2.4
u22.x86_64
PIGSTY 0.2.4
PIGSTY 0.2.4
PIGSTY 0.2.4
PIGSTY 0.2.4
PIGSTY 0.2.4
u22.aarch64
PIGSTY 0.2.4
PIGSTY 0.2.4
PIGSTY 0.2.4
PIGSTY 0.2.4
PIGSTY 0.2.4
u24.x86_64
PIGSTY 0.2.4
PIGSTY 0.2.4
PIGSTY 0.2.4
PIGSTY 0.2.4
PIGSTY 0.2.4
u24.aarch64
PIGSTY 0.2.4
PIGSTY 0.2.4
PIGSTY 0.2.4
PIGSTY 0.2.4
PIGSTY 0.2.4

构建

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

pig build pkg pg_byteamagic         # 构建 RPM / DEB 包

安装

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

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

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

pig install pg_byteamagic;          # 当前活跃 PG 版本安装
pig ext install -y pg_byteamagic -v 18  # PG 18
pig ext install -y pg_byteamagic -v 17  # PG 17
pig ext install -y pg_byteamagic -v 16  # PG 16
pig ext install -y pg_byteamagic -v 15  # PG 15
pig ext install -y pg_byteamagic -v 14  # PG 14
dnf install -y pg_byteamagic_18       # PG 18
dnf install -y pg_byteamagic_17       # PG 17
dnf install -y pg_byteamagic_16       # PG 16
dnf install -y pg_byteamagic_15       # PG 15
dnf install -y pg_byteamagic_14       # PG 14
apt install -y postgresql-18-pg-byteamagic   # PG 18
apt install -y postgresql-17-pg-byteamagic   # PG 17
apt install -y postgresql-16-pg-byteamagic   # PG 16
apt install -y postgresql-15-pg-byteamagic   # PG 15
apt install -y postgresql-14-pg-byteamagic   # PG 14

创建扩展

CREATE EXTENSION byteamagic;

用法

来源: GitHub 仓库, byteamagic 文档 扩展名: byteamagic CSV 中的包条目是 pg_byteamagic;上游扩展名是 byteamagic

byteamagic 使用 libmagic 分析 PostgreSQL 中的 bytea 值,用于识别 MIME 类型和文件类型文本。

CREATE EXTENSION byteamagic;
SELECT byteamagic_mime(data);
SELECT byteamagic_text(data);

函数

  • byteamagic_mime(bytea) 返回 MIME 类型文本,行为与 file --mime-type 一致。
  • byteamagic_text(bytea) 返回人类可读的文件类型描述,行为与 file 一致。

说明

  • 该扩展需要 PostgreSQL 开发头文件和 libmagic 开发包。
  • 适用于将文件或 blob 以 bytea 形式存储,并需要在数据库内进行类型识别的场景。

最后修改 2026-04-14: update extension catalog (fa7cf58)