postgres truncate is slow

后端 未结 4 1513
孤城傲影
孤城傲影 2021-01-11 23:02

In postgres 9.2 (CentOS), TRUNCATE TABLE command occasionally took a really long time to run. One time, it took more than 1.5 hours to truncate a table with 100K records, ev

4条回答
  •  渐次进展
    2021-01-11 23:24

    Check if the truncate was blocked by any query

    SELECT
        activity.pid,
        activity.usename,
        activity.query,
        blocking.pid AS blocking_id,
        blocking.query AS blocking_query
    FROM pg_stat_activity AS activity
    JOIN pg_stat_activity AS blocking ON blocking.pid = ANY(pg_blocking_pids(activity.pid));
    

    If necessary terminate it SELECT pg_terminate_backend(PID);

提交回复
热议问题