Skip to content

byteamagic

Detect MIME types and file formats from PostgreSQL bytea values

pg_byteamagic · Detect MIME types and file formats from PostgreSQL bytea values

Overview

IDExtensionPackageVersionCategoryLicenseLanguage
4275byteamagicpg_byteamagic0.2.4UTILBSD-2-ClauseC
AttributeHas BinaryHas LibraryNeed LoadHas DDLRelocatableTrusted
--s-d-rNoYesNoYesyesno
Extension name is byteamagic; package name is pg_byteamagic.

Packages

TypeRepoVersionPG Major CompatibilityPackage PatternDependencies
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
PackageVersionOSORGSIZEFile URL
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
PackageVersionOSORGSIZEFile URL
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
PackageVersionOSORGSIZEFile URL
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
PackageVersionOSORGSIZEFile URL
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
PackageVersionOSORGSIZEFile URL
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

Source

pig build pkg pg_byteamagic;		# build rpm/deb

Install

Make sure PGDG and PIGSTY repo available:

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

Install this extension with 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 this extension with:

CREATE EXTENSION byteamagic;

Usage

Sources: official repo, official doc

byteamagic runs libmagic on bytea values, so PostgreSQL can identify the MIME type or human-readable file type of blobs stored in the database. The package name is pg_byteamagic, but the extension name is byteamagic.

CREATE EXTENSION byteamagic;

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

Functions

  • byteamagic_mime(bytea) returns text: MIME type, equivalent to file --mime-type.
  • byteamagic_text(bytea) returns text: descriptive file type text, equivalent to file.

Common Use

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

Caveats

  • It only inspects bytea content; there are no operators, custom types, or extra SQL management objects.
  • Build/install requires PostgreSQL development headers plus the system libmagic development package.
  • The upstream documentation is minimal; current user-facing behavior is unchanged from the long-standing doc page.

Table reader