Unrecognized error type (ActiveRecord::StatementInvalid: PG::ProgramLimitExceeded

Are you on PG13

You might try a vacuum and reindex. I think if you search for those you should find some examples, but PostgreSQL 13 update might give you some hints.