How to reduce foreign key performance impact in PostgreSQL
If you are a superuser, you can temporarily disable the system triggers that implement the foreign key checks:

BEGIN;
ALTER TABLE example_2 DISABLE TRIGGER ALL;
INSERT INTO example_2
   SELECT g FROM generate_series(1, 1000) g,
                 generate_series(1, 10000);
ALTER TABLE example_2 ENABLE TRIGGER ALL;
COMMIT;


Dire warning: Do this only if you are 100% certain that your data modifications will not produce inconsistencies. This is dangerous, which is also the reason why only superusers can do it.