When I am tasked with importing data to specific tables on a database, sequences often get messed up. This little piece of SQL will return the correct selects to update the sequence for each table.

select 'select setval(' || regexp_replace(column_default, E'^nextval\((.*)\).*', E'\1') || ', max(' || column_name || ')) from ' || table_schema || '.' || table_name || ';' from information_schema.columns where column_default ~ '^nextval';

As with anybody’s code, sql or otherwise use at your own risk, and only after a backup of the db.