Fix: Log must be done before query.
Fix: Restore compatibility with old modules.
Fix: Avoid pgsql error of duplicate record making rollback.