{"record":{"id":"b43a9d3432abc001","repo":"pentaho/pentaho-kettle","slug":"error-while-truncating","errorCode":null,"errorMessage":"Error while truncating ","messagePattern":"Error while truncating ","errorType":"exception","errorClass":"KettleException","httpStatus":null,"severity":"error","filePath":"plugins/postgresql-db-bulk-loader/impl/src/main/java/org/pentaho/di/trans/steps/pgbulkloader/PGBulkLoader.java","lineNumber":214,"sourceCode":"\n  void processTruncate() throws Exception {\n    Connection connection = data.db.getConnection();\n\n    String loadAction = environmentSubstitute( meta.getLoadAction() );\n\n    if ( loadAction.equalsIgnoreCase( \"truncate\" ) ) {\n      DatabaseMeta dm = meta.getDatabaseMeta();\n      String tableName =\n        dm.getQuotedSchemaTableCombination( environmentSubstitute( meta.getSchemaName() ),\n          environmentSubstitute( meta.getTableName() ) );\n      logBasic( \"Launching command: \" + \"TRUNCATE \" + tableName );\n\n      Statement statement = connection.createStatement();\n\n      try {\n        statement.executeUpdate( \"TRUNCATE \" + tableName );\n      } catch ( Exception ex ) {\n        throw new KettleException( \"Error while truncating \" + tableName, ex );\n      } finally {\n        statement.close();\n      }\n    }\n  }\n\n  public boolean processRow( StepMetaInterface smi, StepDataInterface sdi ) throws KettleException {\n    meta = (PGBulkLoaderMeta) smi;\n    data = (PGBulkLoaderData) sdi;\n\n    try {\n      Object[] r = getRow(); // Get row from input rowset & set row busy!\n\n      if ( r == null ) { // no more input to be expected...\n\n        setOutputDone();\n\n        // Close the output stream...","sourceCodeStart":196,"sourceCodeEnd":232,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/plugins/postgresql-db-bulk-loader/impl/src/main/java/org/pentaho/di/trans/steps/pgbulkloader/PGBulkLoader.java#L196-L232","documentation":"processTruncate executes 'TRUNCATE <table>' when the step's truncate option is enabled, and rethrows any SQL failure as a KettleException with the table name. The table could not be emptied before the COPY load.","triggerScenarios":"do_copy invokes processTruncate with the truncate option checked and statement.executeUpdate(\"TRUNCATE \" + tableName) throws: table missing, insufficient privilege, table name needing quoting, or lock conflicts with concurrent sessions.","commonSituations":"Non-superuser without TRUNCATE privilege on the target table; schema-qualified or mixed-case table name unquoted; other long-running transactions blocking the lock TRUNCATE needs; pointing at the wrong database where the table doesn't exist.","solutions":["Grant TRUNCATE (or table ownership) to the connection user, or disable the 'Truncate table' option and empty the table another way","Verify the table exists in the connected database/schema; use the correct schema-qualified name","Quote the identifier (schema.\"Table\") if it contains mixed case or special characters, e.g. via properly quoted table name in the step metadata","Check pg_locks/pg_stat_activity for sessions blocking the TRUNCATE and terminate them"],"exampleFix":"-- before (fails for mixed-case name)\nTRUNCATE MyTable\n-- after\nTRUNCATE \"public\".\"MyTable\"","handlingStrategy":"validation","validationCode":"// run before enabling truncate\ntry ( Connection c = dm.getConnection(); Statement s = c.createStatement() ) {\n  s.executeQuery( \"SELECT has_table_privilege( CURRENT_USER, '\" + tableName + \"', 'TRUNCATE' )\" );\n}","typeGuard":null,"tryCatchPattern":"try {\n  step.processRow();\n} catch ( KettleException e ) {\n  if ( e.getMessage().startsWith( \"Error while truncating\" ) ) {\n    // fall back to DELETE FROM, or grant TRUNCATE, then retry\n  }\n}","preventionTips":["Grant TRUNCATE or table ownership to the loader's DB user","Use correct schema-qualified, quoted table names for mixed-case identifiers","Only enable 'Truncate table' when concurrent writers won't hold conflicting locks"],"tags":["postgresql","truncate","sql","permissions"],"backgroundTag":"sql-query-failed","analyzedSha":"f3058517a153da500bf4551f46d79b91bf8ec552","analyzedAt":"2026-09-13T14:04:16.340Z","contentChangedAt":"2026-09-13T14:04:16.340Z","schemaVersion":2},"datasetVersion":"2026-09-20T23:17:15.980Z"}