adminpack
administrative functions for PostgreSQL
Overview
| Package | Version | Category | License | Language |
|---|---|---|---|---|
adminpack | 2.1 | ADMIN | PostgreSQL | C |
| ID | Extension | Bin | Lib | Load | Create | Trust | Reloc | Schema |
|---|---|---|---|---|---|---|---|---|
| 5970 | adminpack | No | Yes | No | Yes | No | No | - |
| Related | fio lo file_fdw ddlx pgdd pg_catcheck pg_cheat_funcs pg_repack |
|---|
Version
| PG18 | PG17 | PG16 | PG15 | PG14 |
|---|---|---|---|---|
| ✗ | ✗ | 2.1 | 2.1 | 2.1 |
Install
Note: This is a built-in contrib extension of PostgreSQL
CREATE EXTENSION adminpack;
Usage
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
| Function | Returns | Description |
|---|---|---|
pg_file_write(filename, data, append) | bigint | Write text to file; returns bytes written |
pg_file_sync(filename) | void | Flush file or directory to disk |
pg_file_rename(old, new [, archive]) | boolean | Rename file, optionally archiving existing target |
pg_file_unlink(filename) | boolean | Delete a file |
pg_logdir_ls() | setof record | List log files with timestamps |
Access Control
- All functions default to superuser-only access
- Permissions can be granted via
GRANTto non-superusers - File access is restricted to the database cluster directory unless the user has
pg_read_server_filesorpg_write_server_filesroles
Note: adminpack was removed in PostgreSQL 17. For PostgreSQL 16 and earlier only.
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.