Skip to main content
The 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
Important: This approach does NOT modify existing data, only advances the XID counter.

Usage

Required Flags

Optional Flags

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

  1. Current XID Check: Gets the current PostgreSQL transaction ID using pg_current_xact_id()
  2. Reference Analysis: Finds the maximum transaction ID referenced in the transactions table
  3. Gap Calculation: Calculates the difference and adds a safety buffer
  4. 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
Permission Error
  • 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