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
|
Source
pig build pkg external_file; # build rpm/debInstall
Make sure PGDG and PIGSTY repo available:
pig repo add pgsql -u # add both repo and update cacheInstall 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 14Create 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 anefilelocator.readEfile(efile): reads the target file intobytea.writeEfile(bytea, efile): writesbyteato 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_fileschema 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