Thanks all for your suggestions. In the end there was another process using the database heavily which was causing the problem.