I'm facing performance issues migrating from postgres 10 to 12 (also from 11 to 12) even with a new DB. Th performance difference is huge 300ms in pg10 vs 3 minutes in pg12.
I have a view that abstracts the data in the database:
CREATE OR REPLACE VIEW public.my_constraints
Assuming your DDL changes fairly seldomly, and you already have a well structured deployment process in place for that, perhaps just change this to a materialized view and refresh (concurrently) after any DDL gets executed. That way, you have stats on what your view has in it and are not subject to issues with planning the execution of the query in this view.