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
|
Source
pig build pkg pg_orphaned; # build rpm/debInstall
Make sure PGDG and PIGSTY repo available:
pig repo add pgsql -u # add both repo and update cacheInstall 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 14Create this extension with:
CREATE EXTENSION pg_orphaned;Usage
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