Fix missing queries using temp files and locks with CSV log files. Thanks to avandras for the report.