通过nodejs将数据插入SQLite的内存错误

时间:2019-01-26 21:37:39

标签: node.js sqlite better-sqlite3

我正在使用better-sqlite从现有表中向FTS5虚拟表中插入约25万行

const insertStmt = db.prepare('INSERT INTO vtbl (a, b, c) VALUES (?, ?, ?)');
const selectStmt = db.prepare('SELECT a, b, c FROM tbl');

const rows = selectStmt.all();
for (let i = 0, j = rows.length; i < j; i++) {
    const r = rows[i];
    insertStmt.run(r.a, r.b, r.c)
}

但是程序死于以下错误

<--- Last few GCs --->

[6152:0x102803600]    30143 ms: Mark-sweep 1325.4 (1426.1) -> 1325.4 (1426.6) MB, 72.4 / 0.0 ms  (average mu = 0.265, current mu = 0.179) allocation failure scavenge might not succeed
[6152:0x102803600]    30226 ms: Mark-sweep 1326.0 (1426.6) -> 1325.9 (1427.6) MB, 72.5 / 0.0 ms  (average mu = 0.201, current mu = 0.133) allocation failure scavenge might not succeed


<--- JS stacktrace --->

==== JS stack trace =========================================

    0: ExitFrame [pc: 0x6d1fbdbe3d]
Security context: 0x1232b127bbd1 <JSObject>
    1: /* anonymous */ [0x12321753bc89] [/Users/punkish/Projects/foo/bin/sq.js:12] [bytecode=0x1232660d5d51 offset=64](this=0x12321753bd81 <Object map = 0x123241e02571>,exports=0x12321753bd81 <Object map = 0x123241e02571>,require=0x12321753bd41 <JSFunction require (sfi = 0x1232660c5fa1)>,module=0x12321753bcf1 <Module map = 0x123241e508b1>,__filename=0x1232...

FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory

我也尝试使用iterator

for (const r of selectStmt.iterate()) {
    insertStmt.run(r.a, r.b, r.c)
}

但是我收到a statement is already running so can't run another statement' (I am assuming that the insertStmt can't be run while the selectStmt`仍在迭代的错误。

那么,我该如何解决这个问题?

0 个答案:

没有答案