Question

I have a very large table in my database and I am trying to create a serial column for it. The problem I think the table is being replicated while I am creating this serial, which there is no room for. First off is my assumption correct? Second is there a way I can create a serial and have a vacuum continuously or is there a way I can create this column that would not do this?

Was it helpful?

Solution

If you don't have enough space to hold two copies of your biggest table, then you are in for a world of pain. It can be done, but you will be constantly beating your head against a wall.

To add a primary key, you would need to add the column to hold the key (nullable, with no default), add the sequence, change the column to have a default to draw from the sequence, then make several passes over the table filling in another chunk of values each time, with vacuuming in between. Then change the column to not null, then set the sequence to be owned by the column.

The best way to fill in the chunks depends on what other data and indexes are in the table.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top