pg_ttl_index
Automatic data expiration with TTL indexes
pg_ttl_index : Automatic data expiration with TTL indexes
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 2730 | pg_ttl_index | pg_ttl_index | 3.0.0 |
FEAT | PostgreSQL | C |
| Attribute | Has Binary | Has Library | Need Load | Has DDL | Relocatable | Trusted |
|---|---|---|---|---|---|---|
| --sLd-r | No | Yes | Yes | Yes | yes | no |
| Relationships | |
|---|---|
| See Also | timescaledb pg_partman citus pg_fkpart timeseries pg_cron |
pg 14 breaks; rm README from RPM/DEB
Packages
| Type | Repo | Version | PG Major Compatibility | Package Pattern | Dependencies |
|---|---|---|---|---|---|
| EXT | PIGSTY | 3.0.0 |
18 17 16 15 14 | pg_ttl_index |
- |
| RPM | PIGSTY | 3.0.0 |
18 17 16 15 14 | pg_ttl_index_$v |
- |
| DEB | PIGSTY | 3.0.0 |
18 17 16 15 14 | postgresql-$v-ttl-index |
- |
| Linux / PG | PG18 | PG17 | PG16 | PG15 | PG14 |
|---|---|---|---|---|---|
| el8.x86_64 | PIGSTY 3.0.0 | PIGSTY 3.0.0 | PIGSTY 3.0.0 | PIGSTY 3.0.0 | N/A |
| el8.aarch64 | PIGSTY 3.0.0 | PIGSTY 3.0.0 | PIGSTY 3.0.0 | PIGSTY 3.0.0 | N/A |
| el9.x86_64 | PIGSTY 3.0.0 | PIGSTY 3.0.0 | PIGSTY 3.0.0 | PIGSTY 3.0.0 | N/A |
| el9.aarch64 | PIGSTY 3.0.0 | PIGSTY 3.0.0 | PIGSTY 3.0.0 | PIGSTY 3.0.0 | N/A |
| el10.x86_64 | PIGSTY 3.0.0 | PIGSTY 3.0.0 | PIGSTY 3.0.0 | PIGSTY 3.0.0 | N/A |
| el10.aarch64 | PIGSTY 3.0.0 | PIGSTY 3.0.0 | PIGSTY 3.0.0 | PIGSTY 3.0.0 | N/A |
| d12.x86_64 | PIGSTY 3.0.0 | PIGSTY 3.0.0 | PIGSTY 3.0.0 | PIGSTY 3.0.0 | N/A |
| d12.aarch64 | PIGSTY 3.0.0 | PIGSTY 3.0.0 | PIGSTY 3.0.0 | PIGSTY 3.0.0 | N/A |
| d13.x86_64 | PIGSTY 3.0.0 | PIGSTY 3.0.0 | PIGSTY 3.0.0 | PIGSTY 3.0.0 | N/A |
| d13.aarch64 | PIGSTY 3.0.0 | PIGSTY 3.0.0 | PIGSTY 3.0.0 | PIGSTY 3.0.0 | N/A |
| u22.x86_64 | PIGSTY 3.0.0 | PIGSTY 3.0.0 | PIGSTY 3.0.0 | PIGSTY 3.0.0 | N/A |
| u22.aarch64 | PIGSTY 3.0.0 | PIGSTY 3.0.0 | PIGSTY 3.0.0 | PIGSTY 3.0.0 | N/A |
| u24.x86_64 | PIGSTY 3.0.0 | PIGSTY 3.0.0 | PIGSTY 3.0.0 | PIGSTY 3.0.0 | N/A |
| u24.aarch64 | PIGSTY 3.0.0 | PIGSTY 3.0.0 | PIGSTY 3.0.0 | PIGSTY 3.0.0 | N/A |
| u26.x86_64 | PIGSTY 3.0.0 | PIGSTY 3.0.0 | PIGSTY 3.0.0 | PIGSTY 3.0.0 | N/A |
| u26.aarch64 | PIGSTY 3.0.0 | PIGSTY 3.0.0 | PIGSTY 3.0.0 | PIGSTY 3.0.0 | N/A |
Source
github.com/ibrahimkarimeddin/postgres-extensions-pg_ttl
postgres-extensions-pg_ttl-3.0.0.tar.gz
Install
Make sure PGDG and PIGSTY repo available:
Install this extension with pig:
Config this extension to shared_preload_libraries:
Create this extension with:
Usage
pg_ttl_index provides automatic data expiration by associating a TTL (time-to-live) with a timestamp column. A background worker periodically deletes rows whose timestamp exceeds the configured expiration interval.
Quick Start
Functions
| Function | Description |
|---|---|
ttl_start_worker() |
Start the background worker for automatic cleanup |
ttl_worker_status() |
Check if the worker is running |
ttl_runner() |
Manually trigger cleanup |
ttl_create_index(table, column, expire_seconds [, batch_size]) |
Configure TTL expiration |
ttl_drop_index(table, column) |
Remove TTL configuration |
ttl_summary() |
List all TTL indexes with stats |
Examples
Session management with 24-hour expiry:
Log retention for 7 days:
Cache entries with custom expiry column (0 means the column itself holds the absolute expiry time):
Monitoring
Pause cleanup for a specific table:
Configuration
| Parameter | Description | Default |
|---|---|---|
pg_ttl_index.naptime |
Cleanup interval in seconds | 60 |
pg_ttl_index.enabled |
Enable/disable worker globally | on |