IntersectMBO / cardano-db-sync

A component that follows the Cardano chain and stores blocks and transactions in PostgreSQL

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Fix snapshot restoration script

kderme opened this issue · comments

Currently if an error occurs, eg out of disk which is common, the restoartion script continues and may end with missing data. It is therefore advised to use -v ON_ERROR_STOP=1. However this has revealed a different error, which needs to be mitigated.

psql:db-sync-snapshot-schema-13.1-block-9767060-x86_64.sql:23: ERROR:  schema "public" already exists

It is therefore advised to use -v ON_ERROR_STOP=1

-v variable=assignment is not valid for pg_restore (only psql), so this won't work for our new snapshot format. Instead we'll need to pass --exit-on-error when using pg_restore

The problem is that, when running pg_dump, we specify --schema=public, which generates a CREATE SCHEMA public statement. There are a few ways to work around this:

  1. Run pg_dump without --schema=public, or
  2. Call pg_restore with --schema=public, which skips the CREATE SCHEMA statement

I'm going to go with option 2, because I think the results will be more predictable