dump data from specific table postgresql
pg_dump -U user_name -W -h localhost -d database_name -t table1 -t table2 > new_data.sql
Fix Sequence
- Cach 1:
SELECT 'SELECT SETVAL(' ||
quote_literal(quote_ident(PGT.schemaname) || '.' || quote_ident(S.relname)) ||
', COALESCE(MAX(' || quote_ident(C.attname) || '), 1) ) FROM ' ||
quote_ident(PGT.schemaname) || '.' || quote_ident(T.relname) || ';'
FROM pg_class AS S,
pg_depend AS D,
pg_class AS T,
pg_attribute AS C,
pg_tables AS PGT
WHERE S.relkind = 'S'
AND S.oid = D.objid
AND D.refobjid = T.oid
AND D.refobjid = C.attrelid
AND D.refobjsubid = C.attnum
AND T.relname = PGT.tablename
ORDER BY S.relname;
https://wiki.postgresql.org/wiki/Fixing_Sequences
- Cach 2:
ALTER SEQUENCE sequence_name RESTART WITH your_next_free_id;
https://stackoverflow.com/questions/42547583/symfony-doctrine-id-already-exist