external_file
Access external server-side files through PostgreSQL functions
Repository
darold/external_file
https://github.com/darold/external_file
Source
external_file-1.2.tar.gz
external_file-1.2.tar.gz
Overview
| Package | Version | Category | License | Language |
|---|---|---|---|---|
external_file | 1.2 | UTIL | PostgreSQL | SQL |
| ID | Extension | Bin | Lib | Load | Create | Trust | Reloc | Schema |
|---|---|---|---|---|---|---|---|---|
| 4285 | external_file | No | No | No | Yes | No | No | external_file |
Fixed schema external_file; superuser required.
Version
| Type | Repo | Version | PG Ver | Package | Deps |
|---|---|---|---|---|---|
| EXT | PIGSTY | 1.2 | 1817161514 | external_file | - |
| RPM | PIGSTY | 1.2 | 1817161514 | external_file_$v | - |
| DEB | PIGSTY | 1.2 | 1817161514 | postgresql-$v-external-file | - |
Build
You can build the RPM / DEB packages for external_file using pig build:
pig build pkg external_file # build RPM / DEB packages
Install
You can install external_file 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 external_file; # Install for current active PG version
pig ext install -y external_file -v 18 # PG 18
pig ext install -y external_file -v 17 # PG 17
pig ext install -y external_file -v 16 # PG 16
pig ext install -y external_file -v 15 # PG 15
pig ext install -y external_file -v 14 # PG 14
dnf install -y external_file_18 # PG 18
dnf install -y external_file_17 # PG 17
dnf install -y external_file_16 # PG 16
dnf install -y external_file_15 # PG 15
dnf install -y external_file_14 # PG 14
apt install -y postgresql-18-external-file # PG 18
apt install -y postgresql-17-external-file # PG 17
apt install -y postgresql-16-external-file # PG 16
apt install -y postgresql-15-external-file # PG 15
apt install -y postgresql-14-external-file # PG 14
Create Extension:
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.
Feedback
Was this page helpful?
Thanks for the feedback! Please let us know how we can improve.
Sorry to hear that. Please let us know how we can improve.