fio

PostgreSQL File I/O Functions

Overview

PackageVersionCategoryLicenseLanguage
pg_fio1.0ADMINBSD 3-ClauseC
IDExtensionBinLibLoadCreateTrustRelocSchema
5230fioNoYesNoYesNoYes-
Relatedpgfincore adminpack file_fdw pageinspect pgstattuple pg_repack pg_rewrite pg_squeeze

Version

TypeRepoVersionPG VerPackageDeps
EXTPIGSTY1.01817161514pg_fio-
RPMPIGSTY1.01817161514pg_fio_$v-
DEBPIGSTY1.01817161514postgresql-$v-pg-fio-
OS / PGPG18PG17PG16PG15PG14
el8.x86_64
el8.aarch64
el9.x86_64
el9.aarch64
el10.x86_64
el10.aarch64
d12.x86_64
d12.aarch64
d13.x86_64
d13.aarch64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
u22.x86_64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
u22.aarch64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
u24.x86_64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
u24.aarch64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0

Build

You can build the RPM / DEB packages for pg_fio using pig build:

pig build pkg pg_fio         # build RPM / DEB packages

Install

You can install pg_fio 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 pg_fio;          # Install for current active PG version
pig ext install -y pg_fio -v 18  # PG 18
pig ext install -y pg_fio -v 17  # PG 17
pig ext install -y pg_fio -v 16  # PG 16
pig ext install -y pg_fio -v 15  # PG 15
pig ext install -y pg_fio -v 14  # PG 14
dnf install -y pg_fio_18       # PG 18
dnf install -y pg_fio_17       # PG 17
dnf install -y pg_fio_16       # PG 16
dnf install -y pg_fio_15       # PG 15
dnf install -y pg_fio_14       # PG 14
apt install -y postgresql-18-pg-fio   # PG 18
apt install -y postgresql-17-pg-fio   # PG 17
apt install -y postgresql-16-pg-fio   # PG 16
apt install -y postgresql-15-pg-fio   # PG 15
apt install -y postgresql-14-pg-fio   # PG 14

Create Extension:

CREATE EXTENSION fio;

Usage

fio: PostgreSQL File I/O Functions

The fio extension provides file system I/O functions accessible from SQL, enabling reading, writing, and managing files and directories directly from PostgreSQL.

File Operations

-- Read file contents (returns bytea)
SELECT fio_readfile('/etc/hostname');

-- Write content to file
SELECT fio_writefile('/tmp/output.txt', 'Hello World'::bytea);

-- Write with auto-create directory and overwrite
SELECT fio_writefile('/tmp/newdir/output.txt', 'data'::bytea, true, true);

-- Remove a file
SELECT fio_removefile('/tmp/output.txt');

-- Rename / move a file
SELECT fio_renamefile('/tmp/old.txt', '/tmp/new.txt');

Directory Operations

-- List directory contents
SELECT fio_readdir('/usr/', '*');

-- List with pattern filter
SELECT fio_readdir('/var/log/', '*.log');

-- Create a directory with permissions
SELECT fio_mkdir('/tmp/mydir', '0755');

-- Create nested directories recursively
SELECT fio_mkdir('/tmp/a/b/c', '0755', true);

-- Change file/directory permissions
SELECT fio_chmod('/tmp/mydir', '0700');

Function Reference

FunctionDescription
fio_readfile(path)Read file contents as bytea
fio_writefile(path, content, mkdir, overwrite)Write bytea content to file
fio_removefile(path)Delete a file
fio_renamefile(old, new)Rename or move a file
fio_readdir(path, pattern)List directory entries matching pattern
fio_mkdir(path, mode, recursive)Create directory with permissions
fio_chmod(path, mode)Change file/directory permissions

Last Modified 2026-03-12: add pg extension catalog (95749bf)