Logging of terminal off/on changes, db query speed-up