Set a sequence to the max value of a table column select setval('my_sequence', max(my_column)) from my_table; commit;