0

我在尝试从tostack depth limit exceeded存储一行时遇到。为了解决批量更新,我一直在使用这样的查询:RPostgreSQL

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(通过将其粘贴到文本文件来检查它)。任何人都可以对此有所了解吗?

4

1 回答 1

1

按照提示的建议增加 max_stack_depth。[来自官方文档](http://www.postgresql.org/docs/9.1/static/runtime-config-resource.html):

此参数的理想设置是内核强制执行的实际堆栈大小限制(由 ulimit -s 或本地等效项设置),减去大约 1 兆字节的安全余量。

默认设置为 2 兆字节 (2MB),相对较小,不太可能导致崩溃。

超级用户可以根据连接更改此设置,也可以通过 postgresql.conf 文件为所有用户设置(需要重新启动 postgres 服务器)。

于 2016-04-07T16:08:21.140 回答