adminpack

administrative functions for PostgreSQL

Overview

PackageVersionCategoryLicenseLanguage
adminpack2.1ADMINPostgreSQLC
IDExtensionBinLibLoadCreateTrustRelocSchema
5970adminpackNoYesNoYesNoNo-
Relatedfio lo file_fdw ddlx pgdd pg_catcheck pg_cheat_funcs pg_repack

Version

PG18PG17PG16PG15PG14
2.12.12.1

Install

Note: This is a built-in contrib extension of PostgreSQL

CREATE EXTENSION adminpack;

Usage

adminpack: administrative functions for PostgreSQL

The adminpack extension provides server-side file management and log access functions, primarily used by pgAdmin and other administration tools. All functions are restricted to superusers by default.

File Operations

-- Write text to a file (append=false: file must not exist; append=true: append)
SELECT pg_file_write('/tmp/test.txt', 'Hello World', false);   -- returns bytes written

-- Append to existing file
SELECT pg_file_write('/tmp/test.txt', E'\nMore data', true);

-- Sync file to disk
SELECT pg_file_sync('/tmp/test.txt');

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

-- Rename with archiving (moves existing newname to archive first)
SELECT pg_file_rename('/tmp/old.txt', '/tmp/new.txt', '/tmp/archive.txt');

-- Delete a file
SELECT pg_file_unlink('/tmp/test.txt');   -- returns true on success

Log File Access

-- List server log files (requires default log_filename format)
SELECT * FROM pg_logdir_ls();

Returns timestamps and paths of log files from the log_directory.

Function Reference

FunctionReturnsDescription
pg_file_write(filename, data, append)bigintWrite text to file; returns bytes written
pg_file_sync(filename)voidFlush file or directory to disk
pg_file_rename(old, new [, archive])booleanRename file, optionally archiving existing target
pg_file_unlink(filename)booleanDelete a file
pg_logdir_ls()setof recordList log files with timestamps

Access Control

  • All functions default to superuser-only access
  • Permissions can be granted via GRANT to non-superusers
  • File access is restricted to the database cluster directory unless the user has pg_read_server_files or pg_write_server_files roles

Note: adminpack was removed in PostgreSQL 17. For PostgreSQL 16 and earlier only.


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