pg_orphaned

pg_orphaned

pg_orphaned : Deal with orphaned files

Overview

ID Extension Package Version Category License Language
5200
pg_orphaned
pg_orphaned
1.0
ADMIN
PostgreSQL
C
Attribute Has Binary Has Library Need Load Has DDL Relocatable Trusted
--s-d--
No
Yes
No
Yes
no
no
Relationships
See Also
pg_dirtyread
pg_surgery
amcheck
pageinspect
pg_visibility
pg_checksums
pg_catcheck
pg_repack

Packages

Type Repo Version PG Major Compatibility Package Pattern Dependencies
EXT
PIGSTY
1.0
18
17
16
15
14
pg_orphaned -
RPM
PIGSTY
1.0
18
17
16
15
14
pg_orphaned_$v -
DEB
PIGSTY
1.0
18
17
16
15
14
postgresql-$v-pg-orphaned -
Linux / PG PG18 PG17 PG16 PG15 PG14
el8.x86_64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
el8.aarch64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
el9.x86_64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
el9.aarch64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
el10.x86_64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
el10.aarch64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
d12.x86_64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
d12.aarch64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
d13.x86_64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
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
Package Version OS ORG SIZE File URL
pg_orphaned_18 1.0 el8.x86_64 pigsty 21.3 KiB pg_orphaned_18-1.0-1PIGSTY.el8.x86_64.rpm
pg_orphaned_18 1.0 el8.aarch64 pigsty 21.1 KiB pg_orphaned_18-1.0-1PIGSTY.el8.aarch64.rpm
pg_orphaned_18 1.0 el9.x86_64 pigsty 21.4 KiB pg_orphaned_18-1.0-1PIGSTY.el9.x86_64.rpm
pg_orphaned_18 1.0 el9.aarch64 pigsty 21.4 KiB pg_orphaned_18-1.0-1PIGSTY.el9.aarch64.rpm
pg_orphaned_18 1.0 el10.x86_64 pigsty 21.4 KiB pg_orphaned_18-1.0-1PIGSTY.el10.x86_64.rpm
pg_orphaned_18 1.0 el10.aarch64 pigsty 21.5 KiB pg_orphaned_18-1.0-1PIGSTY.el10.aarch64.rpm
postgresql-18-pg-orphaned 1.0 d12.x86_64 pigsty 29.1 KiB postgresql-18-pg-orphaned_1.0-1PIGSTY~bookworm_amd64.deb
postgresql-18-pg-orphaned 1.0 d12.aarch64 pigsty 28.9 KiB postgresql-18-pg-orphaned_1.0-1PIGSTY~bookworm_arm64.deb
postgresql-18-pg-orphaned 1.0 d13.x86_64 pigsty 28.9 KiB postgresql-18-pg-orphaned_1.0-1PIGSTY~trixie_amd64.deb
postgresql-18-pg-orphaned 1.0 d13.aarch64 pigsty 29.0 KiB postgresql-18-pg-orphaned_1.0-1PIGSTY~trixie_arm64.deb
postgresql-18-pg-orphaned 1.0 u22.x86_64 pigsty 30.8 KiB postgresql-18-pg-orphaned_1.0-1PIGSTY~jammy_amd64.deb
postgresql-18-pg-orphaned 1.0 u22.aarch64 pigsty 30.9 KiB postgresql-18-pg-orphaned_1.0-1PIGSTY~jammy_arm64.deb
postgresql-18-pg-orphaned 1.0 u24.x86_64 pigsty 30.1 KiB postgresql-18-pg-orphaned_1.0-1PIGSTY~noble_amd64.deb
postgresql-18-pg-orphaned 1.0 u24.aarch64 pigsty 30.3 KiB postgresql-18-pg-orphaned_1.0-1PIGSTY~noble_arm64.deb
Package Version OS ORG SIZE File URL
pg_orphaned_17 1.0 el8.x86_64 pigsty 21.3 KiB pg_orphaned_17-1.0-1PIGSTY.el8.x86_64.rpm
pg_orphaned_17 1.0 el8.aarch64 pigsty 21.1 KiB pg_orphaned_17-1.0-1PIGSTY.el8.aarch64.rpm
pg_orphaned_17 1.0 el9.x86_64 pigsty 21.3 KiB pg_orphaned_17-1.0-1PIGSTY.el9.x86_64.rpm
pg_orphaned_17 1.0 el9.aarch64 pigsty 21.4 KiB pg_orphaned_17-1.0-1PIGSTY.el9.aarch64.rpm
pg_orphaned_17 1.0 el10.x86_64 pigsty 21.4 KiB pg_orphaned_17-1.0-1PIGSTY.el10.x86_64.rpm
pg_orphaned_17 1.0 el10.aarch64 pigsty 21.5 KiB pg_orphaned_17-1.0-1PIGSTY.el10.aarch64.rpm
postgresql-17-pg-orphaned 1.0 d12.x86_64 pigsty 29.1 KiB postgresql-17-pg-orphaned_1.0-1PIGSTY~bookworm_amd64.deb
postgresql-17-pg-orphaned 1.0 d12.aarch64 pigsty 28.9 KiB postgresql-17-pg-orphaned_1.0-1PIGSTY~bookworm_arm64.deb
postgresql-17-pg-orphaned 1.0 d13.x86_64 pigsty 28.9 KiB postgresql-17-pg-orphaned_1.0-1PIGSTY~trixie_amd64.deb
postgresql-17-pg-orphaned 1.0 d13.aarch64 pigsty 29.0 KiB postgresql-17-pg-orphaned_1.0-1PIGSTY~trixie_arm64.deb
postgresql-17-pg-orphaned 1.0 u22.x86_64 pigsty 34.8 KiB postgresql-17-pg-orphaned_1.0-1PIGSTY~jammy_amd64.deb
postgresql-17-pg-orphaned 1.0 u22.aarch64 pigsty 35.0 KiB postgresql-17-pg-orphaned_1.0-1PIGSTY~jammy_arm64.deb
postgresql-17-pg-orphaned 1.0 u24.x86_64 pigsty 30.1 KiB postgresql-17-pg-orphaned_1.0-1PIGSTY~noble_amd64.deb
postgresql-17-pg-orphaned 1.0 u24.aarch64 pigsty 30.3 KiB postgresql-17-pg-orphaned_1.0-1PIGSTY~noble_arm64.deb
Package Version OS ORG SIZE File URL
pg_orphaned_16 1.0 el8.x86_64 pigsty 21.3 KiB pg_orphaned_16-1.0-1PIGSTY.el8.x86_64.rpm
pg_orphaned_16 1.0 el8.aarch64 pigsty 21.1 KiB pg_orphaned_16-1.0-1PIGSTY.el8.aarch64.rpm
pg_orphaned_16 1.0 el9.x86_64 pigsty 21.3 KiB pg_orphaned_16-1.0-1PIGSTY.el9.x86_64.rpm
pg_orphaned_16 1.0 el9.aarch64 pigsty 21.4 KiB pg_orphaned_16-1.0-1PIGSTY.el9.aarch64.rpm
pg_orphaned_16 1.0 el10.x86_64 pigsty 21.4 KiB pg_orphaned_16-1.0-1PIGSTY.el10.x86_64.rpm
pg_orphaned_16 1.0 el10.aarch64 pigsty 21.5 KiB pg_orphaned_16-1.0-1PIGSTY.el10.aarch64.rpm
postgresql-16-pg-orphaned 1.0 d12.x86_64 pigsty 29.1 KiB postgresql-16-pg-orphaned_1.0-1PIGSTY~bookworm_amd64.deb
postgresql-16-pg-orphaned 1.0 d12.aarch64 pigsty 28.8 KiB postgresql-16-pg-orphaned_1.0-1PIGSTY~bookworm_arm64.deb
postgresql-16-pg-orphaned 1.0 d13.x86_64 pigsty 28.9 KiB postgresql-16-pg-orphaned_1.0-1PIGSTY~trixie_amd64.deb
postgresql-16-pg-orphaned 1.0 d13.aarch64 pigsty 29.0 KiB postgresql-16-pg-orphaned_1.0-1PIGSTY~trixie_arm64.deb
postgresql-16-pg-orphaned 1.0 u22.x86_64 pigsty 34.4 KiB postgresql-16-pg-orphaned_1.0-1PIGSTY~jammy_amd64.deb
postgresql-16-pg-orphaned 1.0 u22.aarch64 pigsty 34.6 KiB postgresql-16-pg-orphaned_1.0-1PIGSTY~jammy_arm64.deb
postgresql-16-pg-orphaned 1.0 u24.x86_64 pigsty 30.1 KiB postgresql-16-pg-orphaned_1.0-1PIGSTY~noble_amd64.deb
postgresql-16-pg-orphaned 1.0 u24.aarch64 pigsty 30.3 KiB postgresql-16-pg-orphaned_1.0-1PIGSTY~noble_arm64.deb
Package Version OS ORG SIZE File URL
pg_orphaned_15 1.0 el8.x86_64 pigsty 21.3 KiB pg_orphaned_15-1.0-1PIGSTY.el8.x86_64.rpm
pg_orphaned_15 1.0 el8.aarch64 pigsty 21.2 KiB pg_orphaned_15-1.0-1PIGSTY.el8.aarch64.rpm
pg_orphaned_15 1.0 el9.x86_64 pigsty 21.4 KiB pg_orphaned_15-1.0-1PIGSTY.el9.x86_64.rpm
pg_orphaned_15 1.0 el9.aarch64 pigsty 21.5 KiB pg_orphaned_15-1.0-1PIGSTY.el9.aarch64.rpm
pg_orphaned_15 1.0 el10.x86_64 pigsty 21.5 KiB pg_orphaned_15-1.0-1PIGSTY.el10.x86_64.rpm
pg_orphaned_15 1.0 el10.aarch64 pigsty 21.6 KiB pg_orphaned_15-1.0-1PIGSTY.el10.aarch64.rpm
postgresql-15-pg-orphaned 1.0 d12.x86_64 pigsty 29.2 KiB postgresql-15-pg-orphaned_1.0-1PIGSTY~bookworm_amd64.deb
postgresql-15-pg-orphaned 1.0 d12.aarch64 pigsty 28.9 KiB postgresql-15-pg-orphaned_1.0-1PIGSTY~bookworm_arm64.deb
postgresql-15-pg-orphaned 1.0 d13.x86_64 pigsty 28.9 KiB postgresql-15-pg-orphaned_1.0-1PIGSTY~trixie_amd64.deb
postgresql-15-pg-orphaned 1.0 d13.aarch64 pigsty 29.0 KiB postgresql-15-pg-orphaned_1.0-1PIGSTY~trixie_arm64.deb
postgresql-15-pg-orphaned 1.0 u22.x86_64 pigsty 34.5 KiB postgresql-15-pg-orphaned_1.0-1PIGSTY~jammy_amd64.deb
postgresql-15-pg-orphaned 1.0 u22.aarch64 pigsty 34.7 KiB postgresql-15-pg-orphaned_1.0-1PIGSTY~jammy_arm64.deb
postgresql-15-pg-orphaned 1.0 u24.x86_64 pigsty 30.2 KiB postgresql-15-pg-orphaned_1.0-1PIGSTY~noble_amd64.deb
postgresql-15-pg-orphaned 1.0 u24.aarch64 pigsty 30.4 KiB postgresql-15-pg-orphaned_1.0-1PIGSTY~noble_arm64.deb
Package Version OS ORG SIZE File URL
pg_orphaned_14 1.0 el8.x86_64 pigsty 21.3 KiB pg_orphaned_14-1.0-1PIGSTY.el8.x86_64.rpm
pg_orphaned_14 1.0 el8.aarch64 pigsty 21.2 KiB pg_orphaned_14-1.0-1PIGSTY.el8.aarch64.rpm
pg_orphaned_14 1.0 el9.x86_64 pigsty 21.4 KiB pg_orphaned_14-1.0-1PIGSTY.el9.x86_64.rpm
pg_orphaned_14 1.0 el9.aarch64 pigsty 21.5 KiB pg_orphaned_14-1.0-1PIGSTY.el9.aarch64.rpm
pg_orphaned_14 1.0 el10.x86_64 pigsty 21.5 KiB pg_orphaned_14-1.0-1PIGSTY.el10.x86_64.rpm
pg_orphaned_14 1.0 el10.aarch64 pigsty 21.6 KiB pg_orphaned_14-1.0-1PIGSTY.el10.aarch64.rpm
postgresql-14-pg-orphaned 1.0 d12.x86_64 pigsty 29.1 KiB postgresql-14-pg-orphaned_1.0-1PIGSTY~bookworm_amd64.deb
postgresql-14-pg-orphaned 1.0 d12.aarch64 pigsty 28.9 KiB postgresql-14-pg-orphaned_1.0-1PIGSTY~bookworm_arm64.deb
postgresql-14-pg-orphaned 1.0 d13.x86_64 pigsty 28.9 KiB postgresql-14-pg-orphaned_1.0-1PIGSTY~trixie_amd64.deb
postgresql-14-pg-orphaned 1.0 d13.aarch64 pigsty 29.0 KiB postgresql-14-pg-orphaned_1.0-1PIGSTY~trixie_arm64.deb
postgresql-14-pg-orphaned 1.0 u22.x86_64 pigsty 34.4 KiB postgresql-14-pg-orphaned_1.0-1PIGSTY~jammy_amd64.deb
postgresql-14-pg-orphaned 1.0 u22.aarch64 pigsty 34.6 KiB postgresql-14-pg-orphaned_1.0-1PIGSTY~jammy_arm64.deb
postgresql-14-pg-orphaned 1.0 u24.x86_64 pigsty 30.1 KiB postgresql-14-pg-orphaned_1.0-1PIGSTY~noble_amd64.deb
postgresql-14-pg-orphaned 1.0 u24.aarch64 pigsty 30.3 KiB postgresql-14-pg-orphaned_1.0-1PIGSTY~noble_arm64.deb

Source

pig build pkg pg_orphaned;		# build rpm/deb

Install

Make sure PGDG and PIGSTY repo available:

pig repo add pgsql -u   # add both repo and update cache

Install this extension with pig:

pig install pg_orphaned;		# install via package name, for the active PG version

pig install pg_orphaned -v 18;   # install for PG 18
pig install pg_orphaned -v 17;   # install for PG 17
pig install pg_orphaned -v 16;   # install for PG 16
pig install pg_orphaned -v 15;   # install for PG 15
pig install pg_orphaned -v 14;   # install for PG 14

Create this extension with:

CREATE EXTENSION pg_orphaned;

Usage

pg_orphaned: Deal with orphaned files

pg_orphaned provides functions to detect and manage orphaned data files in PostgreSQL. It handles corner cases like in-progress transactions that could cause false positives by using a dirty snapshot.

List Orphaned Files

-- List orphaned files (default: older than 1 day marked as "older")
SELECT * FROM pg_list_orphaned();

-- Custom age threshold
SELECT * FROM pg_list_orphaned('10 seconds');
SELECT * FROM pg_list_orphaned('1 minute');

Returns: dbname, path, name, size, mod_time, relfilenode, reloid, older (boolean).

Move Orphaned Files to Backup

-- Move files older than the threshold to orphaned_backup directory
SELECT pg_move_orphaned('1 minute');

List Moved Files

SELECT * FROM pg_list_orphaned_moved();

Move Files Back (if still orphaned)

SELECT pg_move_back_orphaned();

Remove Moved Files

SELECT pg_remove_moved_orphaned();

Typical Workflow

-- 1. Check for orphaned files
SELECT * FROM pg_list_orphaned('1 minute');

-- 2. Move them to backup (only those older than threshold)
SELECT pg_move_orphaned('1 minute');

-- 3. Verify what was moved
SELECT * FROM pg_list_orphaned_moved();

-- 4. After confirming, remove the backup files
SELECT pg_remove_moved_orphaned();

Note: functions operate on orphaned files for the database you are connected to. Always double-check carefully before moving or removing files.

Last updated on