provision_fill: move most db accesses into transactions