restore_data

Function restore_data 

Source
pub async fn restore_data(target_url: &str, input_path: &str) -> Result<()>
Expand description

Restore data using pg_restore

Uses PostgreSQL directory format restore with:

  • Single-threaded restore to respect FK dependency order
  • Automatic decompression of compressed dump files
  • Optimized for directory format dumps created by dump_data()

§Why Single-Threaded?

Parallel restore (--jobs=N) requires --disable-triggers to avoid FK constraint violations when tables are restored out of dependency order. However, --disable-triggers requires superuser privileges, which managed PostgreSQL services (SerenDB, AWS RDS, Neon, etc.) do not grant.

Single-threaded restore naturally processes tables in FK dependency order, avoiding the need for elevated privileges while ensuring data integrity.

§Note on Retry Behavior

Unlike schema restoration, data restoration does NOT use retry logic. This is intentional because pg_restore with –data-only is NOT idempotent - if it partially succeeds and then fails, retrying would cause duplicate key constraint violations.

If data restoration fails due to connection issues, the user should re-run the command with –drop-existing to ensure a clean slate.