Best practice probably for
- restore schema without indexes
- and possibly without limitation,
- upload data
- then create restrictions
- and create indexes.
If an index exists, then bulk loading will force PostgreSQL to write to the database and index. And bulk loading will make your table statistics useless. But if you first load the data and then create the index, the statistics are automatically updated.
We store scripts that create indexes and scripts that create tables in different files under version control. That's why.
In your case, changing the auto-vacuum settings may help you. You may also consider disabling autovacuum for some tables or for all tables, but this can be a bit extreme.
source share