Search Postgresql Archives

Re: delete is getting hung when there is a huge data in table

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> Now issue is that when this script for the deletion of data is launched , it is taking more than 7 days and doing nothing i.e not a single row has been deleted.

Deleting a large number of rows can take a long time. Often it's quicker to delete smaller chunks. The LIMIT clause is not supported by DELETE, so you need some kind of subquery.

We use something like:

do $_$declare
    num_rows bigint;
begin
    loop
        delete from YourTable where id in
            (select id from YourTable where id < 500 limit 100);
        get diagnostics num_rows = row_count;
        raise notice 'deleted % rows', num_rows;
        exit when num_rows = 0;
    end loop;
end;$_$;

This deletes rows with an id smaller than 500 in chunks of 100.

Kind regards,
Andomar


--
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux