db now closed manually to prevent locking during pipe