Migrate Home Assistant from SQLite to PostgreSQL

For a while I had been using the standard SQLite database for Home Assistant. However after adding more integrations it became very slow. I couldn't find an online guide to migrate from SQLite to an external PostgreSQL server. So I decided to write one for you my potential reader :))