permify repair datastore
command helps prevent PostgreSQL XID wraparound issues by safely advancing the transaction ID counter. This is essential after database migrations or when dealing with XID-related problems.
Overview
XID (Transaction ID) wraparound is a PostgreSQL issue that occurs when the database’s transaction counter approaches its maximum value. This command provides a safe solution by:- Analyzing maximum referenced XIDs in transactions table
- Advancing PostgreSQL’s XID counter to stay ahead of referenced XIDs
- Using safe batch processing to avoid performance impact
Usage
Required Flags
Flag | Description | Example |
---|---|---|
--database-uri | Database connection URI | postgres://user:pass@localhost:5432/permify |
Optional Flags
Flag | Default | Description |
---|---|---|
--database-engine | postgres | Database engine (only postgres supported) |
--batch-size | 1000 | Batch size for XID advancement |
--dry-run | false | Perform a dry run without making changes |
--verbose | true | Enable verbose logging |
--retries | 3 | Maximum number of retries |
Examples
Basic Usage
Dry Run
Test what would be changed without making actual modifications:Custom Batch Size
Use a smaller batch size for production environments:How It Works
- Current XID Check: Gets the current PostgreSQL transaction ID using
pg_current_xact_id()
- Reference Analysis: Finds the maximum transaction ID referenced in the transactions table
- Gap Calculation: Calculates the difference and adds a safety buffer
- Batch Processing: Advances the XID counter in configurable batches to minimize performance impact
When to Use
- After database migrations
- When PostgreSQL warns about XID wraparound
- As a preventive measure in high-transaction environments
- When encountering XID-related errors
Safety Features
- Dry Run Mode: Test changes before applying them
- Batch Processing: Avoids overwhelming the database
- Retry Logic: Handles temporary failures gracefully
- Verbose Logging: Provides detailed progress information
- Data Preservation: Never modifies existing application data
Output Example
Troubleshooting
Common Issues
Connection Error- Verify database URI is correct
- Ensure PostgreSQL is running and accessible
- Ensure database user has sufficient privileges
- User needs ability to execute
pg_current_xact_id()
and transaction operations
Best Practices
- Always run with
--dry-run
first in production - Use appropriate
--batch-size
for your environment - Monitor PostgreSQL logs during execution
- Schedule regular maintenance to prevent XID buildup
- Keep database backups before running repair operations