By default, temp tables are persisted until the end of the session.
This causes "Out of shared memory" errors in the database, which then
auto-vacuums the orphaned temp tables to free memory. To fix this, we
drop temp tables when the transaction finishes, using ON COMMIT DROP.
Issue-ID: CPS-1533
Signed-off-by: danielhanrahan <daniel.hanrahan@est.tech>
Change-Id: Iac47d85e9621531a4a95b99c4becc8cc95242721
final StringBuilder sqlStringBuilder = new StringBuilder("CREATE TEMPORARY TABLE ");
sqlStringBuilder.append(tempTableName);
defineColumns(sqlStringBuilder, columnNames);
+ sqlStringBuilder.append(" ON COMMIT DROP;");
insertData(sqlStringBuilder, tempTableName, columnNames, sqlData);
entityManager.createNativeQuery(sqlStringBuilder.toString()).executeUpdate();
return tempTableName;
sqlStringBuilder.append(",");
}
}
- sqlStringBuilder.append(");");
+ sqlStringBuilder.append(")");
}
private static void insertData(final StringBuilder sqlStringBuilder,