我最近在我的 RedHat 服务器上安装了一个 PostgreSQL 14.1,与我的旧 12.9 并行。两个实例都在运行它们的默认配置。服务器本身有 48 个 CPU 和 188 GB RAM,对于 12.9 来说似乎绰绰有余
一切都按预期工作,但我不断收到错误消息。
out of memory - Failed on request of size 24576 in memory context "TupleSort main"
SQL state: 53200
SQL 表:pos 有 18 584 522 行 // orderedposteps 有 18 行 // posteps 有 18 行
CREATE TEMP TABLE actualpos ON COMMIT DROP AS
SELECT DISTINCT lsa.id
FROM pos sa
JOIN orderedposteps osas ON osas.stepid = sa.stepid
JOIN posteps sas ON sas.id = osas.stepid
JOIN LATERAL
(
SELECT innersa.*
FROM pos innersa
JOIN orderedposteps innerosas ON innerosas.stepid = innersa.stepid
WHERE (innersa.id = sa.id) AND
(innersa.iscached IS FALSE) AND
(innersa.isobsolete IS FALSE)
ORDER BY innersa.createdtimestamp DESC, innerosas.stepindex DESC
LIMIT 1
) lsa ON TRUE
LEFT JOIN LATERAL
(
SELECT innersa.*
FROM pos innersa
JOIN orderedposteps innerosas ON innerosas.stepid = innersa.stepid
WHERE (innersa.id = sa.id) AND
(innersa.iscached IS TRUE) AND
(innersa.isobsolete IS FALSE)
ORDER BY innersa.createdtimestamp DESC, innerosas.stepindex DESC
LIMIT 1
) sacheck ON TRUE
LEFT JOIN orderedposteps osascheck ON osascheck.stepid = sacheck.stepid
WHERE ((sacheck IS NULL) OR (sacheck.createdtimestamp < sa.createdtimestamp) OR (osascheck.stepindex < osas.stepindex))
AND (((osas.stepindex < v_laststepindex) AND (sa.isfailure != sas.isvalidsum) AND (sa.iscached IS FALSE)) OR ((osas.stepindex = v_laststepindex) AND (sa.iscached IS FALSE)))
ORDER BY lsa.createdtimestamp DESC LIMIT 50000
我能看到的唯一区别是内存利用率,由 htop 显示。虽然 12.9 只消耗最多 10 GB 的 RAM,但 14.1 增长到 62 GB 并在达到或多或少 62 GB 时崩溃。
我已经尝试通过增加 work_mem
ALTER SYSTEM SET work_mem = '4MB';
也使用 pgtune 来更改其他一些值,但没有任何显着影响。
我很确定可以简化和调整 SQL,我可以这样做,但我想了解 12.9 和 14.1 之间的区别在哪里,或者要明智地更改配置,而不是重构一个函数以使用最新版本。