Alter postgresql table with huge data
One idea, without knowing the error you get, is that the operation times out.  This sometimes happens when the locks to be taken conflict with other operations or there are too many indexes and constraints to update and check. My answer below gives an idea for this scenario.  Other possibilities are that you ran out of disk space - add more disks to fix it, and consider the solution below to change the table structure.

Now that you cannot insert into your table anymore, you can just as well create a similar table with bigint instead of the integer PK column.  Copy over the existing data.  When done (and the necessary indexes built), you can simply rename both tables in the same transaction, so that the new one will in the end have the name of the present one.

With normal operation this would be a bit more complicated (has to duplicate the inserts to write to the new table and so on), but in your case it should work as described above.

Copying a table's data without the constraints and indexes will be possibly much faster than altering it in place (for most cases, at least).

Note: 9.1 will run out of support soon, please consider upgrading to a more recent version.