Skip to content
external_file

external_file

external_file : Access external server-side files through PostgreSQL functions

Overview

ID Extension Package Version Category License Language
4285
external_file
external_file
1.2
UTIL
PostgreSQL
SQL
Attribute Has Binary Has Library Need Load Has DDL Relocatable Trusted
----d--
No
No
No
Yes
no
no
Relationships
Schemas external_file

Fixed schema external_file; superuser required.

Packages

Type Repo Version PG Major Compatibility Package Pattern Dependencies
EXT
PIGSTY
1.2
18
17
16
15
14
external_file -
RPM
PIGSTY
1.2
18
17
16
15
14
external_file_$v -
DEB
PIGSTY
1.2
18
17
16
15
14
postgresql-$v-external-file -
Linux / PG PG18 PG17 PG16 PG15 PG14
el8.x86_64
PIGSTY 1.2
PIGSTY 1.2
PIGSTY 1.2
PIGSTY 1.2
PIGSTY 1.2
el8.aarch64
PIGSTY 1.2
PIGSTY 1.2
PIGSTY 1.2
PIGSTY 1.2
PIGSTY 1.2
el9.x86_64
PIGSTY 1.2
PIGSTY 1.2
PIGSTY 1.2
PIGSTY 1.2
PIGSTY 1.2
el9.aarch64
PIGSTY 1.2
PIGSTY 1.2
PIGSTY 1.2
PIGSTY 1.2
PIGSTY 1.2
el10.x86_64
PIGSTY 1.2
PIGSTY 1.2
PIGSTY 1.2
PIGSTY 1.2
PIGSTY 1.2
el10.aarch64
PIGSTY 1.2
PIGSTY 1.2
PIGSTY 1.2
PIGSTY 1.2
PIGSTY 1.2
d12.x86_64
PIGSTY 1.2
PIGSTY 1.2
PIGSTY 1.2
PIGSTY 1.2
PIGSTY 1.2
d12.aarch64
PIGSTY 1.2
PIGSTY 1.2
PIGSTY 1.2
PIGSTY 1.2
PIGSTY 1.2
d13.x86_64
PIGSTY 1.2
PIGSTY 1.2
PIGSTY 1.2
PIGSTY 1.2
PIGSTY 1.2
d13.aarch64
PIGSTY 1.2
PIGSTY 1.2
PIGSTY 1.2
PIGSTY 1.2
PIGSTY 1.2
u22.x86_64
PIGSTY 1.2
PIGSTY 1.2
PIGSTY 1.2
PIGSTY 1.2
PIGSTY 1.2
u22.aarch64
PIGSTY 1.2
PIGSTY 1.2
PIGSTY 1.2
PIGSTY 1.2
PIGSTY 1.2
u24.x86_64
PIGSTY 1.2
PIGSTY 1.2
PIGSTY 1.2
PIGSTY 1.2
PIGSTY 1.2
u24.aarch64
PIGSTY 1.2
PIGSTY 1.2
PIGSTY 1.2
PIGSTY 1.2
PIGSTY 1.2
u26.x86_64
PIGSTY 1.2
PIGSTY 1.2
PIGSTY 1.2
PIGSTY 1.2
PIGSTY 1.2
u26.aarch64
PIGSTY 1.2
PIGSTY 1.2
PIGSTY 1.2
PIGSTY 1.2
PIGSTY 1.2
Package Version OS ORG SIZE File URL
external_file_18 1.2 el8.x86_64 pigsty 12.9 KiB external_file_18-1.2-1PIGSTY.el8.x86_64.rpm
external_file_18 1.2 el8.aarch64 pigsty 12.9 KiB external_file_18-1.2-1PIGSTY.el8.aarch64.rpm
external_file_18 1.2 el9.x86_64 pigsty 12.9 KiB external_file_18-1.2-1PIGSTY.el9.x86_64.rpm
external_file_18 1.2 el9.aarch64 pigsty 12.9 KiB external_file_18-1.2-1PIGSTY.el9.aarch64.rpm
external_file_18 1.2 el10.x86_64 pigsty 13.0 KiB external_file_18-1.2-1PIGSTY.el10.x86_64.rpm
external_file_18 1.2 el10.aarch64 pigsty 13.0 KiB external_file_18-1.2-1PIGSTY.el10.aarch64.rpm
postgresql-18-external-file 1.2 d12.x86_64 pigsty 7.1 KiB postgresql-18-external-file_1.2-1PIGSTY~bookworm_amd64.deb
postgresql-18-external-file 1.2 d12.aarch64 pigsty 7.1 KiB postgresql-18-external-file_1.2-1PIGSTY~bookworm_arm64.deb
postgresql-18-external-file 1.2 d13.x86_64 pigsty 7.1 KiB postgresql-18-external-file_1.2-1PIGSTY~trixie_amd64.deb
postgresql-18-external-file 1.2 d13.aarch64 pigsty 7.1 KiB postgresql-18-external-file_1.2-1PIGSTY~trixie_arm64.deb
postgresql-18-external-file 1.2 u22.x86_64 pigsty 7.1 KiB postgresql-18-external-file_1.2-1PIGSTY~jammy_amd64.deb
postgresql-18-external-file 1.2 u22.aarch64 pigsty 7.1 KiB postgresql-18-external-file_1.2-1PIGSTY~jammy_arm64.deb
postgresql-18-external-file 1.2 u24.x86_64 pigsty 7.1 KiB postgresql-18-external-file_1.2-1PIGSTY~noble_amd64.deb
postgresql-18-external-file 1.2 u24.aarch64 pigsty 7.1 KiB postgresql-18-external-file_1.2-1PIGSTY~noble_arm64.deb
postgresql-18-external-file 1.2 u26.x86_64 pigsty 7.2 KiB postgresql-18-external-file_1.2-1PIGSTY~resolute_amd64.deb
postgresql-18-external-file 1.2 u26.aarch64 pigsty 7.2 KiB postgresql-18-external-file_1.2-1PIGSTY~resolute_arm64.deb

Source

pig build pkg external_file;		# 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 external_file;		# install via package name, for the active PG version

pig install external_file -v 18;   # install for PG 18
pig install external_file -v 17;   # install for PG 17
pig install external_file -v 16;   # install for PG 16
pig install external_file -v 15;   # install for PG 15
pig install external_file -v 14;   # install for PG 14

Create this extension with:

CREATE EXTENSION external_file;

Usage

Source: README, Release v1.2

external_file stores file locators as (directory, filename) pairs and accesses server-side files through PostgreSQL lo_* helpers rather than direct file reads.

Basic workflow

CREATE EXTENSION external_file;

INSERT INTO directories(directory_name, directory_path)
VALUES ('temporary', '/tmp/');

INSERT INTO directory_roles(directory_name, directory_role, directory_read, directory_write)
VALUES ('temporary', 'app_reader', true, false);

SELECT writeEfile('\x48656c6c6f0a', ('temporary', 'hello.txt'));
SELECT readEfile(efilename('temporary', 'hello.txt'));
SELECT copyEfile(('temporary', 'hello.txt'), ('temporary', 'hello-copy.txt'));

Core objects

  • directories: maps an alias to an on-server directory path.
  • directory_roles: grants read/write rights on that alias to roles.
  • efilename(directory, filename): constructs an efile locator.
  • readEfile(efile): reads the target file into bytea.
  • writeEfile(bytea, efile): writes bytea to the target file.
  • copyEfile(src, dest): copies one external file to another.
  • getEfilePath(efile, need_read, need_write): resolves the full path and checks access.

Caveats

  • Creating the extension requires a PostgreSQL superuser.
  • Upstream creates all objects in the external_file schema by default.
  • The PostgreSQL OS user still needs filesystem read/write permission on the target directory.
  • Filenames must not contain / or \; access is intentionally mediated through the directory tables.
Last updated on