first use select to show all tables from old owner

SELECT tablename, schemaname,tableowner FROM pg_tables WHERE schemaname = 'public' AND tableowner = 'oldowner';

and make script for looping alter table owner to
DO $$
DECLARE
row record;
BEGIN
FOR row IN SELECT tablename, schemaname FROM pg_tables WHERE schemaname = 'public' AND tableowner = 'oldowner' LOOP
EXECUTE FORMAT('ALTER TABLE %I.%I OWNER TO newowner', row.schemaname, row.tablename);
END LOOP;
END;
$$;