跳转到主要内容

byteamagic

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

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

概览

ID扩展软件包版本类别许可证编程语言
4275byteamagicpg_byteamagic0.2.4UTILBSD-2-ClauseC
属性可执行文件动态库需要预加载需要建扩展可迁移可信
--s-d-r否是否是是否
Extension name is byteamagic; package name is pg_byteamagic.

软件包

类型仓库版本兼容的 PostgreSQL 大版本包名模式依赖
EXTPIGSTY0.2.419 18 17 16 15pg_byteamagic-
RPMPIGSTY0.2.419 18 17 16 15pg_byteamagic_$v-
DEBPIGSTY0.2.419 18 17 16 15postgresql-$v-pg-byteamagic-
Linux / PGPG19PG18PG17PG16PG15
el8.x86_64N/APIGSTY 0.2.4PIGSTY 0.2.4PIGSTY 0.2.4PIGSTY 0.2.4
el8.aarch64N/APIGSTY 0.2.4PIGSTY 0.2.4PIGSTY 0.2.4PIGSTY 0.2.4
el9.x86_64PIGSTY 0.2.4PIGSTY 0.2.4PIGSTY 0.2.4PIGSTY 0.2.4PIGSTY 0.2.4
el9.aarch64PIGSTY 0.2.4PIGSTY 0.2.4PIGSTY 0.2.4PIGSTY 0.2.4PIGSTY 0.2.4
el10.x86_64PIGSTY 0.2.4PIGSTY 0.2.4PIGSTY 0.2.4PIGSTY 0.2.4PIGSTY 0.2.4
el10.aarch64PIGSTY 0.2.4PIGSTY 0.2.4PIGSTY 0.2.4PIGSTY 0.2.4PIGSTY 0.2.4
d12.x86_64PIGSTY 0.2.4PIGSTY 0.2.4PIGSTY 0.2.4PIGSTY 0.2.4PIGSTY 0.2.4
d12.aarch64PIGSTY 0.2.4PIGSTY 0.2.4PIGSTY 0.2.4PIGSTY 0.2.4PIGSTY 0.2.4
d13.x86_64PIGSTY 0.2.4PIGSTY 0.2.4PIGSTY 0.2.4PIGSTY 0.2.4PIGSTY 0.2.4
d13.aarch64PIGSTY 0.2.4PIGSTY 0.2.4PIGSTY 0.2.4PIGSTY 0.2.4PIGSTY 0.2.4
u22.x86_64PIGSTY 0.2.4PIGSTY 0.2.4PIGSTY 0.2.4PIGSTY 0.2.4PIGSTY 0.2.4
u22.aarch64PIGSTY 0.2.4PIGSTY 0.2.4PIGSTY 0.2.4PIGSTY 0.2.4PIGSTY 0.2.4
u24.x86_64PIGSTY 0.2.4PIGSTY 0.2.4PIGSTY 0.2.4PIGSTY 0.2.4PIGSTY 0.2.4
u24.aarch64PIGSTY 0.2.4PIGSTY 0.2.4PIGSTY 0.2.4PIGSTY 0.2.4PIGSTY 0.2.4
u26.x86_64PIGSTY 0.2.4PIGSTY 0.2.4PIGSTY 0.2.4PIGSTY 0.2.4PIGSTY 0.2.4
u26.aarch64PIGSTY 0.2.4PIGSTY 0.2.4PIGSTY 0.2.4PIGSTY 0.2.4PIGSTY 0.2.4
软件包版本平台仓库大小下载
pg_byteamagic_190.2.4el9.x86_64pigsty19.5 KiBpg_byteamagic_19-0.2.4-1PGSTY.el9.x86_64.rpm
pg_byteamagic_190.2.4el9.aarch64pigsty19.4 KiBpg_byteamagic_19-0.2.4-1PGSTY.el9.aarch64.rpm
pg_byteamagic_190.2.4el10.x86_64pigsty19.5 KiBpg_byteamagic_19-0.2.4-1PGSTY.el10.x86_64.rpm
pg_byteamagic_190.2.4el10.aarch64pigsty19.4 KiBpg_byteamagic_19-0.2.4-1PGSTY.el10.aarch64.rpm
postgresql-19-pg-byteamagic0.2.4d12.x86_64pigsty10.6 KiBpostgresql-19-pg-byteamagic_0.2.4-1PGSTY~bookworm_amd64.deb
postgresql-19-pg-byteamagic0.2.4d12.aarch64pigsty10.8 KiBpostgresql-19-pg-byteamagic_0.2.4-1PGSTY~bookworm_arm64.deb
postgresql-19-pg-byteamagic0.2.4d13.x86_64pigsty10.7 KiBpostgresql-19-pg-byteamagic_0.2.4-1PGSTY~trixie_amd64.deb
postgresql-19-pg-byteamagic0.2.4d13.aarch64pigsty10.7 KiBpostgresql-19-pg-byteamagic_0.2.4-1PGSTY~trixie_arm64.deb
postgresql-19-pg-byteamagic0.2.4u22.x86_64pigsty10.8 KiBpostgresql-19-pg-byteamagic_0.2.4-1PGSTY~jammy_amd64.deb
postgresql-19-pg-byteamagic0.2.4u22.aarch64pigsty10.7 KiBpostgresql-19-pg-byteamagic_0.2.4-1PGSTY~jammy_arm64.deb
postgresql-19-pg-byteamagic0.2.4u24.x86_64pigsty10.8 KiBpostgresql-19-pg-byteamagic_0.2.4-1PGSTY~noble_amd64.deb
postgresql-19-pg-byteamagic0.2.4u24.aarch64pigsty10.9 KiBpostgresql-19-pg-byteamagic_0.2.4-1PGSTY~noble_arm64.deb
postgresql-19-pg-byteamagic0.2.4u26.x86_64pigsty10.9 KiBpostgresql-19-pg-byteamagic_0.2.4-1PGSTY~resolute_amd64.deb
postgresql-19-pg-byteamagic0.2.4u26.aarch64pigsty10.9 KiBpostgresql-19-pg-byteamagic_0.2.4-1PGSTY~resolute_arm64.deb
软件包版本平台仓库大小下载
pg_byteamagic_180.2.4el8.x86_64pigsty19.1 KiBpg_byteamagic_18-0.2.4-1PGSTY.el8.x86_64.rpm
pg_byteamagic_180.2.4el8.aarch64pigsty19.4 KiBpg_byteamagic_18-0.2.4-1PGSTY.el8.aarch64.rpm
pg_byteamagic_180.2.4el9.x86_64pigsty19.5 KiBpg_byteamagic_18-0.2.4-1PGSTY.el9.x86_64.rpm
pg_byteamagic_180.2.4el9.aarch64pigsty19.4 KiBpg_byteamagic_18-0.2.4-1PGSTY.el9.aarch64.rpm
pg_byteamagic_180.2.4el10.x86_64pigsty19.4 KiBpg_byteamagic_18-0.2.4-1PGSTY.el10.x86_64.rpm
pg_byteamagic_180.2.4el10.aarch64pigsty19.3 KiBpg_byteamagic_18-0.2.4-1PGSTY.el10.aarch64.rpm
postgresql-18-pg-byteamagic0.2.4d12.x86_64pigsty10.6 KiBpostgresql-18-pg-byteamagic_0.2.4-1PGSTY~bookworm_amd64.deb
postgresql-18-pg-byteamagic0.2.4d12.aarch64pigsty10.8 KiBpostgresql-18-pg-byteamagic_0.2.4-1PGSTY~bookworm_arm64.deb
postgresql-18-pg-byteamagic0.2.4d13.x86_64pigsty10.7 KiBpostgresql-18-pg-byteamagic_0.2.4-1PGSTY~trixie_amd64.deb
postgresql-18-pg-byteamagic0.2.4d13.aarch64pigsty10.7 KiBpostgresql-18-pg-byteamagic_0.2.4-1PGSTY~trixie_arm64.deb
postgresql-18-pg-byteamagic0.2.4u22.x86_64pigsty10.8 KiBpostgresql-18-pg-byteamagic_0.2.4-1PGSTY~jammy_amd64.deb
postgresql-18-pg-byteamagic0.2.4u22.aarch64pigsty10.7 KiBpostgresql-18-pg-byteamagic_0.2.4-1PGSTY~jammy_arm64.deb
postgresql-18-pg-byteamagic0.2.4u24.x86_64pigsty10.8 KiBpostgresql-18-pg-byteamagic_0.2.4-1PGSTY~noble_amd64.deb
postgresql-18-pg-byteamagic0.2.4u24.aarch64pigsty10.9 KiBpostgresql-18-pg-byteamagic_0.2.4-1PGSTY~noble_arm64.deb
postgresql-18-pg-byteamagic0.2.4u26.x86_64pigsty10.9 KiBpostgresql-18-pg-byteamagic_0.2.4-1PGSTY~resolute_amd64.deb
postgresql-18-pg-byteamagic0.2.4u26.aarch64pigsty10.9 KiBpostgresql-18-pg-byteamagic_0.2.4-1PGSTY~resolute_arm64.deb
软件包版本平台仓库大小下载
pg_byteamagic_170.2.4el8.x86_64pigsty19.1 KiBpg_byteamagic_17-0.2.4-1PGSTY.el8.x86_64.rpm
pg_byteamagic_170.2.4el8.aarch64pigsty19.3 KiBpg_byteamagic_17-0.2.4-1PGSTY.el8.aarch64.rpm
pg_byteamagic_170.2.4el9.x86_64pigsty19.5 KiBpg_byteamagic_17-0.2.4-1PGSTY.el9.x86_64.rpm
pg_byteamagic_170.2.4el9.aarch64pigsty19.4 KiBpg_byteamagic_17-0.2.4-1PGSTY.el9.aarch64.rpm
pg_byteamagic_170.2.4el10.x86_64pigsty19.4 KiBpg_byteamagic_17-0.2.4-1PGSTY.el10.x86_64.rpm
pg_byteamagic_170.2.4el10.aarch64pigsty19.3 KiBpg_byteamagic_17-0.2.4-1PGSTY.el10.aarch64.rpm
postgresql-17-pg-byteamagic0.2.4d12.x86_64pigsty10.6 KiBpostgresql-17-pg-byteamagic_0.2.4-1PGSTY~bookworm_amd64.deb
postgresql-17-pg-byteamagic0.2.4d12.aarch64pigsty10.8 KiBpostgresql-17-pg-byteamagic_0.2.4-1PGSTY~bookworm_arm64.deb
postgresql-17-pg-byteamagic0.2.4d13.x86_64pigsty10.7 KiBpostgresql-17-pg-byteamagic_0.2.4-1PGSTY~trixie_amd64.deb
postgresql-17-pg-byteamagic0.2.4d13.aarch64pigsty10.7 KiBpostgresql-17-pg-byteamagic_0.2.4-1PGSTY~trixie_arm64.deb
postgresql-17-pg-byteamagic0.2.4u22.x86_64pigsty11.0 KiBpostgresql-17-pg-byteamagic_0.2.4-1PGSTY~jammy_amd64.deb
postgresql-17-pg-byteamagic0.2.4u22.aarch64pigsty10.9 KiBpostgresql-17-pg-byteamagic_0.2.4-1PGSTY~jammy_arm64.deb
postgresql-17-pg-byteamagic0.2.4u24.x86_64pigsty10.8 KiBpostgresql-17-pg-byteamagic_0.2.4-1PGSTY~noble_amd64.deb
postgresql-17-pg-byteamagic0.2.4u24.aarch64pigsty10.9 KiBpostgresql-17-pg-byteamagic_0.2.4-1PGSTY~noble_arm64.deb
postgresql-17-pg-byteamagic0.2.4u26.x86_64pigsty10.9 KiBpostgresql-17-pg-byteamagic_0.2.4-1PGSTY~resolute_amd64.deb
postgresql-17-pg-byteamagic0.2.4u26.aarch64pigsty10.9 KiBpostgresql-17-pg-byteamagic_0.2.4-1PGSTY~resolute_arm64.deb
软件包版本平台仓库大小下载
pg_byteamagic_160.2.4el8.x86_64pigsty19.1 KiBpg_byteamagic_16-0.2.4-1PGSTY.el8.x86_64.rpm
pg_byteamagic_160.2.4el8.aarch64pigsty19.3 KiBpg_byteamagic_16-0.2.4-1PGSTY.el8.aarch64.rpm
pg_byteamagic_160.2.4el9.x86_64pigsty19.5 KiBpg_byteamagic_16-0.2.4-1PGSTY.el9.x86_64.rpm
pg_byteamagic_160.2.4el9.aarch64pigsty19.4 KiBpg_byteamagic_16-0.2.4-1PGSTY.el9.aarch64.rpm
pg_byteamagic_160.2.4el10.x86_64pigsty19.4 KiBpg_byteamagic_16-0.2.4-1PGSTY.el10.x86_64.rpm
pg_byteamagic_160.2.4el10.aarch64pigsty19.3 KiBpg_byteamagic_16-0.2.4-1PGSTY.el10.aarch64.rpm
postgresql-16-pg-byteamagic0.2.4d12.x86_64pigsty10.6 KiBpostgresql-16-pg-byteamagic_0.2.4-1PGSTY~bookworm_amd64.deb
postgresql-16-pg-byteamagic0.2.4d12.aarch64pigsty10.8 KiBpostgresql-16-pg-byteamagic_0.2.4-1PGSTY~bookworm_arm64.deb
postgresql-16-pg-byteamagic0.2.4d13.x86_64pigsty10.7 KiBpostgresql-16-pg-byteamagic_0.2.4-1PGSTY~trixie_amd64.deb
postgresql-16-pg-byteamagic0.2.4d13.aarch64pigsty10.7 KiBpostgresql-16-pg-byteamagic_0.2.4-1PGSTY~trixie_arm64.deb
postgresql-16-pg-byteamagic0.2.4u22.x86_64pigsty11.0 KiBpostgresql-16-pg-byteamagic_0.2.4-1PGSTY~jammy_amd64.deb
postgresql-16-pg-byteamagic0.2.4u22.aarch64pigsty10.9 KiBpostgresql-16-pg-byteamagic_0.2.4-1PGSTY~jammy_arm64.deb
postgresql-16-pg-byteamagic0.2.4u24.x86_64pigsty10.8 KiBpostgresql-16-pg-byteamagic_0.2.4-1PGSTY~noble_amd64.deb
postgresql-16-pg-byteamagic0.2.4u24.aarch64pigsty10.9 KiBpostgresql-16-pg-byteamagic_0.2.4-1PGSTY~noble_arm64.deb
postgresql-16-pg-byteamagic0.2.4u26.x86_64pigsty10.9 KiBpostgresql-16-pg-byteamagic_0.2.4-1PGSTY~resolute_amd64.deb
postgresql-16-pg-byteamagic0.2.4u26.aarch64pigsty10.9 KiBpostgresql-16-pg-byteamagic_0.2.4-1PGSTY~resolute_arm64.deb
软件包版本平台仓库大小下载
pg_byteamagic_150.2.4el8.x86_64pigsty19.0 KiBpg_byteamagic_15-0.2.4-1PGSTY.el8.x86_64.rpm
pg_byteamagic_150.2.4el8.aarch64pigsty19.3 KiBpg_byteamagic_15-0.2.4-1PGSTY.el8.aarch64.rpm
pg_byteamagic_150.2.4el9.x86_64pigsty19.4 KiBpg_byteamagic_15-0.2.4-1PGSTY.el9.x86_64.rpm
pg_byteamagic_150.2.4el9.aarch64pigsty19.4 KiBpg_byteamagic_15-0.2.4-1PGSTY.el9.aarch64.rpm
pg_byteamagic_150.2.4el10.x86_64pigsty19.4 KiBpg_byteamagic_15-0.2.4-1PGSTY.el10.x86_64.rpm
pg_byteamagic_150.2.4el10.aarch64pigsty19.3 KiBpg_byteamagic_15-0.2.4-1PGSTY.el10.aarch64.rpm
postgresql-15-pg-byteamagic0.2.4d12.x86_64pigsty10.6 KiBpostgresql-15-pg-byteamagic_0.2.4-1PGSTY~bookworm_amd64.deb
postgresql-15-pg-byteamagic0.2.4d12.aarch64pigsty10.8 KiBpostgresql-15-pg-byteamagic_0.2.4-1PGSTY~bookworm_arm64.deb
postgresql-15-pg-byteamagic0.2.4d13.x86_64pigsty10.7 KiBpostgresql-15-pg-byteamagic_0.2.4-1PGSTY~trixie_amd64.deb
postgresql-15-pg-byteamagic0.2.4d13.aarch64pigsty10.7 KiBpostgresql-15-pg-byteamagic_0.2.4-1PGSTY~trixie_arm64.deb
postgresql-15-pg-byteamagic0.2.4u22.x86_64pigsty11.0 KiBpostgresql-15-pg-byteamagic_0.2.4-1PGSTY~jammy_amd64.deb
postgresql-15-pg-byteamagic0.2.4u22.aarch64pigsty10.9 KiBpostgresql-15-pg-byteamagic_0.2.4-1PGSTY~jammy_arm64.deb
postgresql-15-pg-byteamagic0.2.4u24.x86_64pigsty10.8 KiBpostgresql-15-pg-byteamagic_0.2.4-1PGSTY~noble_amd64.deb
postgresql-15-pg-byteamagic0.2.4u24.aarch64pigsty10.9 KiBpostgresql-15-pg-byteamagic_0.2.4-1PGSTY~noble_arm64.deb
postgresql-15-pg-byteamagic0.2.4u26.x86_64pigsty10.9 KiBpostgresql-15-pg-byteamagic_0.2.4-1PGSTY~resolute_amd64.deb
postgresql-15-pg-byteamagic0.2.4u26.aarch64pigsty10.9 KiBpostgresql-15-pg-byteamagic_0.2.4-1PGSTY~resolute_arm64.deb

源码

pig build pkg pg_byteamagic;		# build rpm/deb

安装

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

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

使用 pig 安装扩展。

pig install pg_byteamagic;		# install by package name
pig install byteamagic;		# install by extension name

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

在数据库中创建扩展。

CREATE EXTENSION byteamagic;

用法

来源: official repo, official doc

byteamagic 会对 bytea 值运行 libmagic,因此 PostgreSQL 可以识别数据库中 blob 的 MIME 类型或人类可读文件类型。包名是 pg_byteamagic,但扩展名是 byteamagic。

CREATE EXTENSION byteamagic;

SELECT byteamagic_mime(data) FROM files;
SELECT byteamagic_text(data) FROM files;

函数

  • byteamagic_mime(bytea) returns text: 返回 MIME 类型,对应 file --mime-type。
  • byteamagic_text(bytea) returns text: 返回描述性的文件类型文本,对应 file。

常见用法

SELECT
  id,
  byteamagic_mime(blob) AS mime,
  byteamagic_text(blob) AS kind
FROM uploads;

注意事项

  • 它只检查 bytea 内容;没有运算符、自定义类型或额外的 SQL 管理对象。
  • 构建或安装需要 PostgreSQL 开发头文件,以及系统 libmagic 开发包。
  • 上游文档非常简略;当前面向用户的行为与长期存在的文档页一致。

表格阅读器