Exporting sequences' current values will fail in non-quoted scenarios
In case you have a sequence that contains uppercase letters and referencing those you need to quote them - e.g. "MySequence" - the dump logic will fail. (Yes, I know, it is self-inflicted.)
The code here - https://gitlab.com/dalibo/postgresql_anonymizer/-/blob/master/bin/pg_dump_anon.sh#L238 - will not properly quote the sequence names. It will also not provide their schemas.
More over, for some reason (which I did not dig into deeper), if your sequence is part of a table definition (e.g. SERIAL like here), it will not be returned as part of information_schema.sequences
view.
On top of that, these "SERIAL" sequences are not considered proper sequences by pg_dump and will not get exported by the code here - https://gitlab.com/dalibo/postgresql_anonymizer/-/blob/master/bin/pg_dump_anon.sh#L254
I ended up with hacking this through with following code, which will generate the DDL required for setting the current value of all of the sequences:
seq_update=$(psql "${psql_opts[@]}" \
-c " \
SELECT 'SELECT pg_catalog.setval(''' || quote_ident(nspname) || '.' || quote_ident(c.relname) || ''', ' || nextval(c.oid) || ', false);' \
FROM pg_catalog.pg_class AS c \
JOIN pg_catalog.pg_namespace AS ns \
ON c.relnamespace = ns.oid \
WHERE c.relkind = 'S' AND nspname != 'anon'; \
")
I am providing this here for reference should someone want to pick it up and turn it into a proper PR. I am not aware of the side-effects this might have on real systems. I am running this on a copy of a DB anyway.