byteamagic

Detect MIME types and file formats from PostgreSQL bytea values

Overview

PackageVersionCategoryLicenseLanguage
pg_byteamagic0.2.4UTILBSD 2-ClauseC
IDExtensionBinLibLoadCreateTrustRelocSchema
4275byteamagicNoYesNoYesNoYes-

Extension name is byteamagic; package name is pg_byteamagic.

Version

TypeRepoVersionPG VerPackageDeps
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

Build

You can build the RPM / DEB packages for pg_byteamagic using pig build:

pig build pkg pg_byteamagic         # build RPM / DEB packages

Install

You can install pg_byteamagic directly. First, make sure the PGDG and PIGSTY repositories are added and enabled:

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

Install the extension using pig or apt/yum/dnf:

pig install pg_byteamagic;          # Install for current active PG version
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:

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.

Last Modified 2026-04-19: update extension stub docs (9f178c3)