Backport columns_for_distinct in postgres adapter from #6792

I've skipped the finder stuff because there was no relation#distinct, maybe I'm missing something