Skip to content

datalink

SQL/MED DATALINK data type and functions for controlled access to files outside PostgreSQL

datalink · SQL/MED DATALINK data type and functions for controlled access to files outside PostgreSQL

Overview

IDExtensionPackageVersionCategoryLicenseLanguage
100326datalinkdatalink0.5.0TYPEPostgreSQLC

PostgreSQL · 10, 11, 12, 13, 14, 15, 16, 17, 18

Relationships
Requiresuri uuid-ossp

Usage

Sources:

datalink version 0.5.0 is a proof of concept for the SQL/MED DATALINK type. A value references a URL or a file below a registered base directory and can carry a comment; database-controlled modes attempt token-based access, copy-on-write behavior, and cleanup/recovery of external files.

Minimal construction

The module requires uuid-ossp and uri and must be installed by a superuser. The SQL extension library and worker are separate binaries: preload datalink_bgw, not datalink, and restart PostgreSQL before creating the extension:

shared_preload_libraries = 'datalink_bgw'
CREATE EXTENSION "uuid-ossp";
CREATE EXTENSION uri;
CREATE EXTENSION datalink;
CREATE TABLE persons (id integer, picture datalink);
INSERT INTO persons VALUES (1, DLVALUE('img1.jpg', 'MyBaseDir', 'portrait'));

Register base directories in pg_catalog.pg_datalink_bases before using local paths. The worker defines datalink.dl_naptime, datalink.dl_token_expiry, datalink.dl_base_directory, datalink.dl_token_path, and datalink.dl_keep_max_copies; review their paths and retention values before startup. The PostgreSQL OS account needs the relevant filesystem permissions.

Upstream explicitly says this is not for production. It creates, copies, renames, symlinks, and deletes server-side files, while a background worker removes token files and some external copies. Defaults and semantics are early-stage and the source has no current compatibility matrix. Test only inside an isolated directory tree with backups and an unprivileged OS account.

Table reader