我在尝试从tostack depth limit exceeded
存储一行时遇到。为了解决批量更新,我一直在使用这样的查询:R
PostgreSQL
sql_query_data <- sprintf("BEGIN;
CREATE TEMPORARY TABLE
ts_updates(ts_key varchar, ts_data hstore, ts_frequency integer) ON COMMIT DROP;
INSERT INTO ts_updates(ts_key, ts_data) VALUES %s;
LOCK TABLE %s.timeseries_main IN EXCLUSIVE MODE;
UPDATE %s.timeseries_main
SET ts_data = ts_updates.ts_data,
ts_frequency = ts_updates.ts_frequency
FROM ts_updates
WHERE ts_updates.ts_key = %s.timeseries_main.ts_key;
INSERT INTO %s.timeseries_main
SELECT ts_updates.ts_key, ts_updates.ts_data, ts_updates.ts_frequency
FROM ts_updates
LEFT OUTER JOIN %s.timeseries_main ON (%s.timeseries_main.ts_key = ts_updates.ts_key)
WHERE %s.timeseries_main.ts_key IS NULL;
COMMIT;",
values, schema, schema, schema, schema, schema, schema, schema)
}
到目前为止,这个查询在更新数百万条记录的同时保持低插入数量的效果非常好。到目前为止,每当我遇到堆栈大小问题时,我都会将我的记录分成多个块并从那里继续。
然而,这种策略现在面临一些麻烦。我不再有很多记录了,但有少数记录hstore
更大一些。但无论如何,它并不是真正的“大”。我阅读了@Craig Ringer 的建议,他建议不要接近 1GB 的限制。所以我假设 hstore 本身的大小不是问题,但我收到了这条消息:
Error in postgresqlExecStatement(conn, statement, ...) :
RS-DBI driver: (could not Retrieve the result : ERROR: stack depth limit exceeded
HINT: Increase the configuration parameter "max_stack_depth" (currently 2048kB), after ensuring the platform's stack depth limit is adequate.
)
编辑:我确实将限制增加到 7 MB 并遇到了同样的错误,指出 7 MB 是不够的。这对我来说真的很奇怪,因为我的查询本身只有 1.7 MB(通过将其粘贴到文本文件来检查它)。任何人都可以对此有所了解吗?