Retry queries on lost database connection