From 29b493f8859f1ce0eeadaba75462006499f6f26d Mon Sep 17 00:00:00 2001 From: danielhanrahan Date: Thu, 2 Mar 2023 23:27:09 +0000 Subject: Drop temp table when transaction finishes 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 Change-Id: Iac47d85e9621531a4a95b99c4becc8cc95242721 --- cps-ri/src/main/java/org/onap/cps/spi/repository/TempTableCreator.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cps-ri/src/main/java/org/onap/cps/spi/repository/TempTableCreator.java b/cps-ri/src/main/java/org/onap/cps/spi/repository/TempTableCreator.java index 338b0b1c64..d798932c02 100644 --- a/cps-ri/src/main/java/org/onap/cps/spi/repository/TempTableCreator.java +++ b/cps-ri/src/main/java/org/onap/cps/spi/repository/TempTableCreator.java @@ -60,6 +60,7 @@ public class TempTableCreator { 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; @@ -95,7 +96,7 @@ public class TempTableCreator { sqlStringBuilder.append(","); } } - sqlStringBuilder.append(");"); + sqlStringBuilder.append(")"); } private static void insertData(final StringBuilder sqlStringBuilder, -- cgit 1.2.3-korg