Skip to content
byteamagic

byteamagic

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

Overview

ID Extension Package Version Category License Language
4275
byteamagic
pg_byteamagic
0.2.4
UTIL
BSD 2-Clause
C
Attribute Has Binary Has Library Need Load Has DDL Relocatable Trusted
--s-d-r
No
Yes
No
Yes
yes
no

Extension name is byteamagic; package name is pg_byteamagic.

Packages

Type Repo Version PG Major Compatibility Package Pattern Dependencies
EXT
PIGSTY
0.2.4
18
17
16
15
14
pg_byteamagic -
RPM
PIGSTY
0.2.4
18
17
16
15
14
pg_byteamagic_$v -
DEB
PIGSTY
0.2.4
18
17
16
15
14
postgresql-$v-pg-byteamagic -
Linux / PG PG18 PG17 PG16 PG15 PG14
el8.x86_64
PIGSTY 0.2.4
PIGSTY 0.2.4
PIGSTY 0.2.4
PIGSTY 0.2.4
PIGSTY 0.2.4
el8.aarch64
PIGSTY 0.2.4
PIGSTY 0.2.4
PIGSTY 0.2.4
PIGSTY 0.2.4
PIGSTY 0.2.4
el9.x86_64
PIGSTY 0.2.4
PIGSTY 0.2.4
PIGSTY 0.2.4
PIGSTY 0.2.4
PIGSTY 0.2.4
el9.aarch64
PIGSTY 0.2.4
PIGSTY 0.2.4
PIGSTY 0.2.4
PIGSTY 0.2.4
PIGSTY 0.2.4
el10.x86_64
PIGSTY 0.2.4
PIGSTY 0.2.4
PIGSTY 0.2.4
PIGSTY 0.2.4
PIGSTY 0.2.4
el10.aarch64
PIGSTY 0.2.4
PIGSTY 0.2.4
PIGSTY 0.2.4
PIGSTY 0.2.4
PIGSTY 0.2.4
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
u26.x86_64
PIGSTY 0.2.4
PIGSTY 0.2.4
PIGSTY 0.2.4
PIGSTY 0.2.4
PIGSTY 0.2.4
u26.aarch64
PIGSTY 0.2.4
PIGSTY 0.2.4
PIGSTY 0.2.4
PIGSTY 0.2.4
PIGSTY 0.2.4
Package Version OS ORG SIZE File URL
pg_byteamagic_18 0.2.4 el8.x86_64 pigsty 13.8 KiB pg_byteamagic_18-0.2.4-1PIGSTY.el8.x86_64.rpm
pg_byteamagic_18 0.2.4 el8.aarch64 pigsty 13.9 KiB pg_byteamagic_18-0.2.4-1PIGSTY.el8.aarch64.rpm
pg_byteamagic_18 0.2.4 el9.x86_64 pigsty 13.8 KiB pg_byteamagic_18-0.2.4-1PIGSTY.el9.x86_64.rpm
pg_byteamagic_18 0.2.4 el9.aarch64 pigsty 13.6 KiB pg_byteamagic_18-0.2.4-1PIGSTY.el9.aarch64.rpm
pg_byteamagic_18 0.2.4 el10.x86_64 pigsty 13.8 KiB pg_byteamagic_18-0.2.4-1PIGSTY.el10.x86_64.rpm
pg_byteamagic_18 0.2.4 el10.aarch64 pigsty 13.9 KiB pg_byteamagic_18-0.2.4-1PIGSTY.el10.aarch64.rpm
postgresql-18-pg-byteamagic 0.2.4 d12.x86_64 pigsty 10.5 KiB postgresql-18-pg-byteamagic_0.2.4-1PIGSTY~bookworm_amd64.deb
postgresql-18-pg-byteamagic 0.2.4 d12.aarch64 pigsty 10.7 KiB postgresql-18-pg-byteamagic_0.2.4-1PIGSTY~bookworm_arm64.deb
postgresql-18-pg-byteamagic 0.2.4 d13.x86_64 pigsty 10.7 KiB postgresql-18-pg-byteamagic_0.2.4-1PIGSTY~trixie_amd64.deb
postgresql-18-pg-byteamagic 0.2.4 d13.aarch64 pigsty 10.6 KiB postgresql-18-pg-byteamagic_0.2.4-1PIGSTY~trixie_arm64.deb
postgresql-18-pg-byteamagic 0.2.4 u22.x86_64 pigsty 10.7 KiB postgresql-18-pg-byteamagic_0.2.4-1PIGSTY~jammy_amd64.deb
postgresql-18-pg-byteamagic 0.2.4 u22.aarch64 pigsty 10.6 KiB postgresql-18-pg-byteamagic_0.2.4-1PIGSTY~jammy_arm64.deb
postgresql-18-pg-byteamagic 0.2.4 u24.x86_64 pigsty 10.7 KiB postgresql-18-pg-byteamagic_0.2.4-1PIGSTY~noble_amd64.deb
postgresql-18-pg-byteamagic 0.2.4 u24.aarch64 pigsty 10.8 KiB postgresql-18-pg-byteamagic_0.2.4-1PIGSTY~noble_arm64.deb
postgresql-18-pg-byteamagic 0.2.4 u26.x86_64 pigsty 10.8 KiB postgresql-18-pg-byteamagic_0.2.4-1PIGSTY~resolute_amd64.deb
postgresql-18-pg-byteamagic 0.2.4 u26.aarch64 pigsty 10.8 KiB postgresql-18-pg-byteamagic_0.2.4-1PIGSTY~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 via package name, for the active PG version
pig install byteamagic;		# install by extension name, for the current active PG version

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
pig install byteamagic -v 14;   # install for PG 14

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.
Last updated on