PostgreSQL: Reset Sequences

This is a little perl script which takes, database, username (and password) and schema as an input and resets
the sequences (serial columns) for the user or schema.

By reset, i mean :

select setval("sequence name", max(id)) from "table"

In other words set the sequence equal to the max id in the table.

Note: This only works if you’ve used the serial datatype.

./reset_sequences.pl
Usage: reset_requences.pl -d  [-s "schema"] [-u "user"] [-p "password"]

If you specify a user it will reset all of the sequences for that user. If you specify a schema it will reset all of the sequences for that schema (assuming you have permission). If you specify both it will limit to the user’s sequences in the schema.

Download: reset_sequences.pl

Leave a comment

0 Comments.

Leave a Reply


[ Ctrl + Enter ]