This article discusses how you can use PostgreSQL along with ts_stat or MADlib for term frequency and Inverse document frequency analysis.