Improve stats collection: support for different database types