Something in your posts table is broken beyond repair, it may be a column in a row, or multiple rows and multiple columns.
What you can try doing is finding which id is broken by selecting it:
psql discourse
% select * from posts where id < 1000
% select * from posts where id > 1000 and id < 2000
and so on until you isolate the problem row.
Then if you are lucky you can just fix the row by deleting data from it, if you are unlucky you can just delete the row completely