I tried altering some fields ... My command was unable to succeed
Postgres writes new row versions when updating anything. When the transaction succeeds (commits), those become visible and the old row versions are dead as soon as no older transaction is still running.
If your transaction fails (as it obviously did), the transaction is rolled back, and those new row versions themselves become dead tuples.
That's the nature of PostgreSQL's MVCC model. Use VACUUM
to free up disk space occupied by dead tuples. If your failed operation mostly occupies data pages at the physical end of the file holding your table, plain VACUUM
might be able to free up some or all of the that space. (Which would be fortunate, as VACUUM
is less invasive and much cheaper than VACUUM FULL
.) Else you need VACUUM FULL
:
VACUUM FULL tablename;
Takes an exclusive lock, and also may take some time for big tables!
If autovacuum
is running (as it should and is per default), chances are that some of the space is freed up after some time automatically.
VACUUM FULL
rewrites the whole table, so it needs plenty of free space as "wiggle room". You obviously don't have enough, so read the chapter "Disk full" in this related answer:
TABLESPACE
?
One more option. You mentioned:
tablespaces on a separate machine
If there is enough free space on a different TABLESPACE
, you can (temporarily) change the tablespace for the table, which results in migrating the table to the different storage location. ALTER TABLE
can do that:
This form changes the table's tablespace to the specified tablespace
and moves the data file(s) associated with the table to the new
tablespace. Indexes on the table, if any, are not moved; but they can
be moved separately with additional SET TABLESPACE
commands.
So:
ALTER TABLE name SET TABLESPACE new_tablespace;
The name of the default tablespace is pg_default
by default (sic!). If in doubt, read the chapter "Tablespaces" in the manual.
pg_dump
/ restore
If all else fails, a dump-restore cycle can save you, as that implicitly removes all dead tuples and rewrites the table in pristine condition.