Bharat Darakh
Bharat Darakh

Reputation: 345

ERROR: could not extend file "pg_tblspc/4815857/PG_11_201809051/16321": No space left on device

My postgres table occupied 100% memory and want to truncate it.

When I USE TRUNCATE TABLE TABLE_NAME statement it gives be below Error:

ERROR: could not extend file "pg_tblspc/4815857/PG_11_201809051/16321": No space left on device HINT: Check free disk space.

So I tried DELETE FROM TABLE_NAME statement which doesn't free the used space.

How can I force the truncate?

Upvotes: 3

Views: 4309

Answers (1)

Laurenz Albe
Laurenz Albe

Reputation: 248215

TRUNCATE needs to create a new (empty) file for the table, which probably causes your problem. You can DROP the table and recreate it.

Another, more cumbersome way would be

DELETE FROM table_name;
VACUUM table_name;  -- no FULL!

While VACUUM normally does not shrink the table, it will truncate emply pages off the end of the table. If the table is empty, that would remove all pages.

Upvotes: 4

Related Questions