
What's wrong with: ALTER TABLE foo ADD column bar bigserial;Will be filled with unique values automatically (starting with 1).If you want a number for every existing row, every row in the table has to be updated. Or do you not?The table will be bloated to twice it's size if it cannot reuse dead tuples or free space on the data pages. Performance of the operation might benefit a lot from a lower than 100 or just random dead tuples spread out over the table. Else you may want to run VACUUM FULL ANALYZE afterwards to recover disk space. This won't be quick, though.You may be interested in this extension. It helps you gather statistics on your tables.