[logs] optionally, trucate tables
authorAsier Lostalé <asier.lostale@openbravo.com>
Thu, 12 Feb 2015 10:00:36 +0100
changeset 25969 70b425fb8e82
parent 25968 16ef04853fbd
child 25970 323e172fa622
[logs] optionally, trucate tables
modules/org.openbravo.utility.cleanup.log/src-db/database/model/tables/OBULOG_CONFIG.xml
modules/org.openbravo.utility.cleanup.log/src-db/database/sourcedata/AD_COLUMN.xml
modules/org.openbravo.utility.cleanup.log/src-db/database/sourcedata/AD_ELEMENT.xml
modules/org.openbravo.utility.cleanup.log/src-db/database/sourcedata/AD_FIELD.xml
modules/org.openbravo.utility.cleanup.log/src/org/openbravo/utility/cleanup/log/LogCleanUpProcess.java
--- a/modules/org.openbravo.utility.cleanup.log/src-db/database/model/tables/OBULOG_CONFIG.xml	Wed Feb 11 17:15:22 2015 +0100
+++ b/modules/org.openbravo.utility.cleanup.log/src-db/database/model/tables/OBULOG_CONFIG.xml	Thu Feb 12 10:00:36 2015 +0100
@@ -49,6 +49,10 @@
         <default/>
         <onCreateDefault/>
       </column>
+      <column name="ISTRUNCATE" primaryKey="false" required="true" type="CHAR" size="1" autoIncrement="false">
+        <default><![CDATA[N]]></default>
+        <onCreateDefault><![CDATA['N']]></onCreateDefault>
+      </column>
       <foreign-key foreignTable="AD_CLIENT" name="OBULOG_CONFIG_CLIENT">
         <reference local="AD_CLIENT_ID" foreign="AD_CLIENT_ID"/>
       </foreign-key>
--- a/modules/org.openbravo.utility.cleanup.log/src-db/database/sourcedata/AD_COLUMN.xml	Wed Feb 11 17:15:22 2015 +0100
+++ b/modules/org.openbravo.utility.cleanup.log/src-db/database/sourcedata/AD_COLUMN.xml	Thu Feb 12 10:00:36 2015 +0100
@@ -72,6 +72,46 @@
 <!--119FD7FE5FC6487D98DF783651AA2356-->  <ISUSEDSEQUENCE><![CDATA[N]]></ISUSEDSEQUENCE>
 <!--119FD7FE5FC6487D98DF783651AA2356--></AD_COLUMN>
 
+<!--1618C0B1974845A8BDF65C878849136F--><AD_COLUMN>
+<!--1618C0B1974845A8BDF65C878849136F-->  <AD_COLUMN_ID><![CDATA[1618C0B1974845A8BDF65C878849136F]]></AD_COLUMN_ID>
+<!--1618C0B1974845A8BDF65C878849136F-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--1618C0B1974845A8BDF65C878849136F-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--1618C0B1974845A8BDF65C878849136F-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--1618C0B1974845A8BDF65C878849136F-->  <NAME><![CDATA[Truncate Table]]></NAME>
+<!--1618C0B1974845A8BDF65C878849136F-->  <DESCRIPTION><![CDATA[Truncates all the data in the table]]></DESCRIPTION>
+<!--1618C0B1974845A8BDF65C878849136F-->  <HELP><![CDATA[Truncate all data in the table (technically truncate table DB statement). When flagged, all data in the table will be completely removed not being possible to define any other restriction.
+
+It is only possible to truncate a table in case there is no any other table in the system having a foreign key pointing to this one.
+
+Truncating a table results performs better in terms of time/resources consumption.]]></HELP>
+<!--1618C0B1974845A8BDF65C878849136F-->  <COLUMNNAME><![CDATA[IsTruncate]]></COLUMNNAME>
+<!--1618C0B1974845A8BDF65C878849136F-->  <AD_TABLE_ID><![CDATA[D370F1BCD26D42D8A33AFF5D3941BEF7]]></AD_TABLE_ID>
+<!--1618C0B1974845A8BDF65C878849136F-->  <AD_REFERENCE_ID><![CDATA[20]]></AD_REFERENCE_ID>
+<!--1618C0B1974845A8BDF65C878849136F-->  <FIELDLENGTH><![CDATA[1]]></FIELDLENGTH>
+<!--1618C0B1974845A8BDF65C878849136F-->  <DEFAULTVALUE><![CDATA[N]]></DEFAULTVALUE>
+<!--1618C0B1974845A8BDF65C878849136F-->  <ISKEY><![CDATA[N]]></ISKEY>
+<!--1618C0B1974845A8BDF65C878849136F-->  <ISPARENT><![CDATA[N]]></ISPARENT>
+<!--1618C0B1974845A8BDF65C878849136F-->  <ISMANDATORY><![CDATA[Y]]></ISMANDATORY>
+<!--1618C0B1974845A8BDF65C878849136F-->  <ISUPDATEABLE><![CDATA[Y]]></ISUPDATEABLE>
+<!--1618C0B1974845A8BDF65C878849136F-->  <ISIDENTIFIER><![CDATA[N]]></ISIDENTIFIER>
+<!--1618C0B1974845A8BDF65C878849136F-->  <SEQNO><![CDATA[130]]></SEQNO>
+<!--1618C0B1974845A8BDF65C878849136F-->  <ISTRANSLATED><![CDATA[N]]></ISTRANSLATED>
+<!--1618C0B1974845A8BDF65C878849136F-->  <ISENCRYPTED><![CDATA[N]]></ISENCRYPTED>
+<!--1618C0B1974845A8BDF65C878849136F-->  <ISSELECTIONCOLUMN><![CDATA[N]]></ISSELECTIONCOLUMN>
+<!--1618C0B1974845A8BDF65C878849136F-->  <AD_ELEMENT_ID><![CDATA[C5F5D6EBAE6542A997648A5B646700ED]]></AD_ELEMENT_ID>
+<!--1618C0B1974845A8BDF65C878849136F-->  <ISSESSIONATTR><![CDATA[N]]></ISSESSIONATTR>
+<!--1618C0B1974845A8BDF65C878849136F-->  <ISSECONDARYKEY><![CDATA[N]]></ISSECONDARYKEY>
+<!--1618C0B1974845A8BDF65C878849136F-->  <ISDESENCRYPTABLE><![CDATA[N]]></ISDESENCRYPTABLE>
+<!--1618C0B1974845A8BDF65C878849136F-->  <DEVELOPMENTSTATUS><![CDATA[RE]]></DEVELOPMENTSTATUS>
+<!--1618C0B1974845A8BDF65C878849136F-->  <AD_MODULE_ID><![CDATA[8A34B301DC524EA3A07513DF9F42CC90]]></AD_MODULE_ID>
+<!--1618C0B1974845A8BDF65C878849136F-->  <POSITION><![CDATA[13]]></POSITION>
+<!--1618C0B1974845A8BDF65C878849136F-->  <ISTRANSIENT><![CDATA[N]]></ISTRANSIENT>
+<!--1618C0B1974845A8BDF65C878849136F-->  <ISAUTOSAVE><![CDATA[Y]]></ISAUTOSAVE>
+<!--1618C0B1974845A8BDF65C878849136F-->  <VALIDATEONNEW><![CDATA[Y]]></VALIDATEONNEW>
+<!--1618C0B1974845A8BDF65C878849136F-->  <IMAGESIZEVALUESACTION><![CDATA[N]]></IMAGESIZEVALUESACTION>
+<!--1618C0B1974845A8BDF65C878849136F-->  <ISUSEDSEQUENCE><![CDATA[N]]></ISUSEDSEQUENCE>
+<!--1618C0B1974845A8BDF65C878849136F--></AD_COLUMN>
+
 <!--2E2532E89A084C8FA45A7B802C342CBF--><AD_COLUMN>
 <!--2E2532E89A084C8FA45A7B802C342CBF-->  <AD_COLUMN_ID><![CDATA[2E2532E89A084C8FA45A7B802C342CBF]]></AD_COLUMN_ID>
 <!--2E2532E89A084C8FA45A7B802C342CBF-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
--- a/modules/org.openbravo.utility.cleanup.log/src-db/database/sourcedata/AD_ELEMENT.xml	Wed Feb 11 17:15:22 2015 +0100
+++ b/modules/org.openbravo.utility.cleanup.log/src-db/database/sourcedata/AD_ELEMENT.xml	Thu Feb 12 10:00:36 2015 +0100
@@ -26,4 +26,22 @@
 <!--87622BE79A504BE48BE22DF76CE1D8A2-->  <ISGLOSSARY><![CDATA[N]]></ISGLOSSARY>
 <!--87622BE79A504BE48BE22DF76CE1D8A2--></AD_ELEMENT>
 
+<!--C5F5D6EBAE6542A997648A5B646700ED--><AD_ELEMENT>
+<!--C5F5D6EBAE6542A997648A5B646700ED-->  <AD_ELEMENT_ID><![CDATA[C5F5D6EBAE6542A997648A5B646700ED]]></AD_ELEMENT_ID>
+<!--C5F5D6EBAE6542A997648A5B646700ED-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--C5F5D6EBAE6542A997648A5B646700ED-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--C5F5D6EBAE6542A997648A5B646700ED-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--C5F5D6EBAE6542A997648A5B646700ED-->  <COLUMNNAME><![CDATA[IsTruncate]]></COLUMNNAME>
+<!--C5F5D6EBAE6542A997648A5B646700ED-->  <NAME><![CDATA[Truncate Table]]></NAME>
+<!--C5F5D6EBAE6542A997648A5B646700ED-->  <PRINTNAME><![CDATA[Truncate Table]]></PRINTNAME>
+<!--C5F5D6EBAE6542A997648A5B646700ED-->  <DESCRIPTION><![CDATA[Truncates all the data in the table]]></DESCRIPTION>
+<!--C5F5D6EBAE6542A997648A5B646700ED-->  <HELP><![CDATA[Truncate all data in the table (technically truncate table DB statement). When flagged, all data in the table will be completely removed not being possible to define any other restriction.
+
+It is only possible to truncate a table in case there is no any other table in the system having a foreign key pointing to this one.
+
+Truncating a table results performs better in terms of time/resources consumption.]]></HELP>
+<!--C5F5D6EBAE6542A997648A5B646700ED-->  <AD_MODULE_ID><![CDATA[8A34B301DC524EA3A07513DF9F42CC90]]></AD_MODULE_ID>
+<!--C5F5D6EBAE6542A997648A5B646700ED-->  <ISGLOSSARY><![CDATA[N]]></ISGLOSSARY>
+<!--C5F5D6EBAE6542A997648A5B646700ED--></AD_ELEMENT>
+
 </data>
--- a/modules/org.openbravo.utility.cleanup.log/src-db/database/sourcedata/AD_FIELD.xml	Wed Feb 11 17:15:22 2015 +0100
+++ b/modules/org.openbravo.utility.cleanup.log/src-db/database/sourcedata/AD_FIELD.xml	Thu Feb 12 10:00:36 2015 +0100
@@ -44,7 +44,7 @@
 <!--6C561A964545449AB2DBCCF9FA8053E1-->  <ISDISPLAYED><![CDATA[Y]]></ISDISPLAYED>
 <!--6C561A964545449AB2DBCCF9FA8053E1-->  <DISPLAYLENGTH><![CDATA[1]]></DISPLAYLENGTH>
 <!--6C561A964545449AB2DBCCF9FA8053E1-->  <ISREADONLY><![CDATA[N]]></ISREADONLY>
-<!--6C561A964545449AB2DBCCF9FA8053E1-->  <SEQNO><![CDATA[40]]></SEQNO>
+<!--6C561A964545449AB2DBCCF9FA8053E1-->  <SEQNO><![CDATA[1000]]></SEQNO>
 <!--6C561A964545449AB2DBCCF9FA8053E1-->  <ISSAMELINE><![CDATA[N]]></ISSAMELINE>
 <!--6C561A964545449AB2DBCCF9FA8053E1-->  <ISFIELDONLY><![CDATA[N]]></ISFIELDONLY>
 <!--6C561A964545449AB2DBCCF9FA8053E1-->  <ISENCRYPTED><![CDATA[N]]></ISENCRYPTED>
@@ -57,6 +57,38 @@
 <!--6C561A964545449AB2DBCCF9FA8053E1-->  <EM_OBUIAPP_SHOWSUMMARY><![CDATA[N]]></EM_OBUIAPP_SHOWSUMMARY>
 <!--6C561A964545449AB2DBCCF9FA8053E1--></AD_FIELD>
 
+<!--7677FABAECB146919F4A6666F787B0D7--><AD_FIELD>
+<!--7677FABAECB146919F4A6666F787B0D7-->  <AD_FIELD_ID><![CDATA[7677FABAECB146919F4A6666F787B0D7]]></AD_FIELD_ID>
+<!--7677FABAECB146919F4A6666F787B0D7-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--7677FABAECB146919F4A6666F787B0D7-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--7677FABAECB146919F4A6666F787B0D7-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--7677FABAECB146919F4A6666F787B0D7-->  <NAME><![CDATA[Truncate Table]]></NAME>
+<!--7677FABAECB146919F4A6666F787B0D7-->  <DESCRIPTION><![CDATA[Truncates all the data in the table]]></DESCRIPTION>
+<!--7677FABAECB146919F4A6666F787B0D7-->  <HELP><![CDATA[Truncate all data in the table (technically truncate table DB statement). When flagged, all data in the table will be completely removed not being possible to define any other restriction.
+
+It is only possible to truncate a table in case there is no any other table in the system having a foreign key pointing to this one.
+
+Truncating a table results performs better in terms of time/resources consumption.]]></HELP>
+<!--7677FABAECB146919F4A6666F787B0D7-->  <ISCENTRALLYMAINTAINED><![CDATA[Y]]></ISCENTRALLYMAINTAINED>
+<!--7677FABAECB146919F4A6666F787B0D7-->  <AD_TAB_ID><![CDATA[60097D591A22496696B79D80FE53F2A9]]></AD_TAB_ID>
+<!--7677FABAECB146919F4A6666F787B0D7-->  <AD_COLUMN_ID><![CDATA[1618C0B1974845A8BDF65C878849136F]]></AD_COLUMN_ID>
+<!--7677FABAECB146919F4A6666F787B0D7-->  <IGNOREINWAD><![CDATA[N]]></IGNOREINWAD>
+<!--7677FABAECB146919F4A6666F787B0D7-->  <ISDISPLAYED><![CDATA[Y]]></ISDISPLAYED>
+<!--7677FABAECB146919F4A6666F787B0D7-->  <DISPLAYLENGTH><![CDATA[1]]></DISPLAYLENGTH>
+<!--7677FABAECB146919F4A6666F787B0D7-->  <ISREADONLY><![CDATA[N]]></ISREADONLY>
+<!--7677FABAECB146919F4A6666F787B0D7-->  <SEQNO><![CDATA[20]]></SEQNO>
+<!--7677FABAECB146919F4A6666F787B0D7-->  <ISSAMELINE><![CDATA[N]]></ISSAMELINE>
+<!--7677FABAECB146919F4A6666F787B0D7-->  <ISFIELDONLY><![CDATA[N]]></ISFIELDONLY>
+<!--7677FABAECB146919F4A6666F787B0D7-->  <ISENCRYPTED><![CDATA[N]]></ISENCRYPTED>
+<!--7677FABAECB146919F4A6666F787B0D7-->  <SHOWINRELATION><![CDATA[N]]></SHOWINRELATION>
+<!--7677FABAECB146919F4A6666F787B0D7-->  <ISFIRSTFOCUSEDFIELD><![CDATA[N]]></ISFIRSTFOCUSEDFIELD>
+<!--7677FABAECB146919F4A6666F787B0D7-->  <AD_MODULE_ID><![CDATA[8A34B301DC524EA3A07513DF9F42CC90]]></AD_MODULE_ID>
+<!--7677FABAECB146919F4A6666F787B0D7-->  <STARTINODDCOLUMN><![CDATA[N]]></STARTINODDCOLUMN>
+<!--7677FABAECB146919F4A6666F787B0D7-->  <STARTNEWLINE><![CDATA[N]]></STARTNEWLINE>
+<!--7677FABAECB146919F4A6666F787B0D7-->  <ISSHOWNINSTATUSBAR><![CDATA[N]]></ISSHOWNINSTATUSBAR>
+<!--7677FABAECB146919F4A6666F787B0D7-->  <EM_OBUIAPP_SHOWSUMMARY><![CDATA[N]]></EM_OBUIAPP_SHOWSUMMARY>
+<!--7677FABAECB146919F4A6666F787B0D7--></AD_FIELD>
+
 <!--7FFF3E59819D4B229D8513E0B3E987D0--><AD_FIELD>
 <!--7FFF3E59819D4B229D8513E0B3E987D0-->  <AD_FIELD_ID><![CDATA[7FFF3E59819D4B229D8513E0B3E987D0]]></AD_FIELD_ID>
 <!--7FFF3E59819D4B229D8513E0B3E987D0-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
@@ -70,6 +102,7 @@
 <!--7FFF3E59819D4B229D8513E0B3E987D0-->  <AD_COLUMN_ID><![CDATA[CDD88BCF980748AD989429F1BDD116C7]]></AD_COLUMN_ID>
 <!--7FFF3E59819D4B229D8513E0B3E987D0-->  <IGNOREINWAD><![CDATA[N]]></IGNOREINWAD>
 <!--7FFF3E59819D4B229D8513E0B3E987D0-->  <ISDISPLAYED><![CDATA[Y]]></ISDISPLAYED>
+<!--7FFF3E59819D4B229D8513E0B3E987D0-->  <DISPLAYLOGIC><![CDATA[@IsTruncate@ = false]]></DISPLAYLOGIC>
 <!--7FFF3E59819D4B229D8513E0B3E987D0-->  <DISPLAYLENGTH><![CDATA[2000]]></DISPLAYLENGTH>
 <!--7FFF3E59819D4B229D8513E0B3E987D0-->  <ISREADONLY><![CDATA[N]]></ISREADONLY>
 <!--7FFF3E59819D4B229D8513E0B3E987D0-->  <SEQNO><![CDATA[50]]></SEQNO>
@@ -153,9 +186,10 @@
 <!--B9A3BB99CD334F538B1A310823A48161-->  <AD_COLUMN_ID><![CDATA[2E2532E89A084C8FA45A7B802C342CBF]]></AD_COLUMN_ID>
 <!--B9A3BB99CD334F538B1A310823A48161-->  <IGNOREINWAD><![CDATA[N]]></IGNOREINWAD>
 <!--B9A3BB99CD334F538B1A310823A48161-->  <ISDISPLAYED><![CDATA[Y]]></ISDISPLAYED>
+<!--B9A3BB99CD334F538B1A310823A48161-->  <DISPLAYLOGIC><![CDATA[@IsTruncate@ = false]]></DISPLAYLOGIC>
 <!--B9A3BB99CD334F538B1A310823A48161-->  <DISPLAYLENGTH><![CDATA[32]]></DISPLAYLENGTH>
 <!--B9A3BB99CD334F538B1A310823A48161-->  <ISREADONLY><![CDATA[N]]></ISREADONLY>
-<!--B9A3BB99CD334F538B1A310823A48161-->  <SEQNO><![CDATA[30]]></SEQNO>
+<!--B9A3BB99CD334F538B1A310823A48161-->  <SEQNO><![CDATA[40]]></SEQNO>
 <!--B9A3BB99CD334F538B1A310823A48161-->  <ISSAMELINE><![CDATA[N]]></ISSAMELINE>
 <!--B9A3BB99CD334F538B1A310823A48161-->  <ISFIELDONLY><![CDATA[N]]></ISFIELDONLY>
 <!--B9A3BB99CD334F538B1A310823A48161-->  <ISENCRYPTED><![CDATA[N]]></ISENCRYPTED>
@@ -181,9 +215,10 @@
 <!--D9AD923C7A7B4FAD946BAF7724684461-->  <AD_COLUMN_ID><![CDATA[06C49E49E02B4AA99E14D9D2CBE00C54]]></AD_COLUMN_ID>
 <!--D9AD923C7A7B4FAD946BAF7724684461-->  <IGNOREINWAD><![CDATA[N]]></IGNOREINWAD>
 <!--D9AD923C7A7B4FAD946BAF7724684461-->  <ISDISPLAYED><![CDATA[Y]]></ISDISPLAYED>
+<!--D9AD923C7A7B4FAD946BAF7724684461-->  <DISPLAYLOGIC><![CDATA[@IsTruncate@ = false]]></DISPLAYLOGIC>
 <!--D9AD923C7A7B4FAD946BAF7724684461-->  <DISPLAYLENGTH><![CDATA[2]]></DISPLAYLENGTH>
 <!--D9AD923C7A7B4FAD946BAF7724684461-->  <ISREADONLY><![CDATA[N]]></ISREADONLY>
-<!--D9AD923C7A7B4FAD946BAF7724684461-->  <SEQNO><![CDATA[20]]></SEQNO>
+<!--D9AD923C7A7B4FAD946BAF7724684461-->  <SEQNO><![CDATA[30]]></SEQNO>
 <!--D9AD923C7A7B4FAD946BAF7724684461-->  <ISSAMELINE><![CDATA[N]]></ISSAMELINE>
 <!--D9AD923C7A7B4FAD946BAF7724684461-->  <ISFIELDONLY><![CDATA[N]]></ISFIELDONLY>
 <!--D9AD923C7A7B4FAD946BAF7724684461-->  <ISENCRYPTED><![CDATA[N]]></ISENCRYPTED>
--- a/modules/org.openbravo.utility.cleanup.log/src/org/openbravo/utility/cleanup/log/LogCleanUpProcess.java	Wed Feb 11 17:15:22 2015 +0100
+++ b/modules/org.openbravo.utility.cleanup.log/src/org/openbravo/utility/cleanup/log/LogCleanUpProcess.java	Thu Feb 12 10:00:36 2015 +0100
@@ -86,10 +86,17 @@
 
       long totalDeletedRows = 0L;
       Set<String> tablesWithDeletions = new LinkedHashSet<String>();
+      Set<String> tablesToTruncate = new LinkedHashSet<String>();
       for (LogCleanUpConfig config : qConfig.list()) {
         long t = System.currentTimeMillis();
         Entity entity = ModelProvider.getInstance().getEntityByTableId(
             (String) DalUtil.getId(config.getTable()));
+
+        if (config.isTruncateTable()) {
+          tablesToTruncate.add(entity.getTableName());
+          continue;
+        }
+
         logMsg = "Cleaning up entity " + entity.getName();
         bgLogger.log(logMsg + "\n");
         log.debug(logMsg);
@@ -127,6 +134,7 @@
       bgLogger.log(logMsg + "\n\n");
       log.debug(logMsg);
 
+      truncateTables(tablesToTruncate, bgLogger);
       vacuumTables(tablesWithDeletions, bgLogger);
 
     } finally {
@@ -134,6 +142,38 @@
     }
   }
 
+  private void truncateTables(Set<String> tablesToTruncate, ProcessLogger bgLogger) {
+    Connection con = OBDal.getInstance().getConnection(false);
+    PreparedStatement ps = null;
+    String logMsg;
+    String truncateStatement = "";
+    for (String tableName : tablesToTruncate) {
+      truncateStatement += truncateStatement.isEmpty() ? "" : ", ";
+      truncateStatement += tableName;
+    }
+
+    try {
+      long truncateTime = System.currentTimeMillis();
+      ps = con.prepareStatement("truncate table " + truncateStatement);
+      ps.execute();
+      logMsg = "Truncated tables " + truncateStatement + " in "
+          + (System.currentTimeMillis() - truncateTime) + " ms.";
+      bgLogger.log(logMsg + "\n");
+      log.debug(logMsg);
+    } catch (SQLException e) {
+      log.error("Error truncating tables {} ", truncateStatement, e);
+      bgLogger.log("Error truncating tables " + truncateStatement + " " + e.getMessage() + "\n");
+    } finally {
+      if (ps != null) {
+        try {
+          ps.close();
+        } catch (SQLException e) {
+          log.error("Coulnd't close prepared statement to truncate tables {}" + truncateStatement);
+        }
+      }
+    }
+  }
+
   private void vacuumTables(Set<String> tablesWithDeletions, ProcessLogger bgLogger) {
     if (!"POSTGRE".equals(OBPropertiesProvider.getInstance().getOpenbravoProperties()
         .get("bbdd.rdbms"))) {
@@ -142,7 +182,7 @@
       return;
     }
     String logMsg;
-    Connection con = OBDal.getInstance().getConnection();
+    Connection con = OBDal.getInstance().getConnection(false);
     try {
       // auto commit is required in order to be able to execute vacuum
       con.setAutoCommit(true);
@@ -150,11 +190,11 @@
       for (String tableName : tablesWithDeletions) {
         PreparedStatement ps = null;
         try {
-          logMsg = "About to execute vacuum full for " + tableName;
+          logMsg = "About to execute vacuum for " + tableName;
           log.debug(logMsg);
           bgLogger.log(logMsg + "\n");
           long vacuumTime = System.currentTimeMillis();
-          ps = con.prepareStatement("vacuum full analyze " + tableName);
+          ps = con.prepareStatement("vacuum analyze " + tableName);
           ps.execute();
           logMsg = "Vacuum for " + tableName + " executed in "
               + (System.currentTimeMillis() - vacuumTime) + " ms";
@@ -171,12 +211,16 @@
           }
         }
       }
-
-      // resetting auto commit to properly release DAL trx
-      con.setAutoCommit(false);
     } catch (SQLException e1) {
       log.error("Errer executing vacuum", e1);
       bgLogger.equals("Error executing vacuum: " + e1.getMessage());
+    } finally {
+      // resetting auto commit to properly release DAL trx
+      try {
+        con.setAutoCommit(false);
+      } catch (SQLException e) {
+        log.error("Errer executing vacuum", e);
+      }
     }
   }
 }