Maybe you could install a local mail client like Thunderbird and connect it to your Gmail via POP3? POP will download the mails and delete them from the server. Then you’ll just have to figure out how to export the mails from Thunderbird/your client of choice.
EDIT: This article contains relevant information.
EDIT 2: Alternativly you could just use IMAP instead of POP to download everything and then delete the mails from the server manually.
Use something like pgAdmin, DBeaver or the pg cli to connect to your postgres instance. Then run the command from the changelog as a SQL query.