Skip to content

Commit

Permalink
Disable PostgreSQL autovacuum for staging table
Browse files Browse the repository at this point in the history
Only drop staging table on incremental mode.
  • Loading branch information
osalvador committed Jan 10, 2019
1 parent 60dc7aa commit a6fd326
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
4 changes: 1 addition & 3 deletions src/main/java/org/replicadb/manager/OracleManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,7 @@ else if (options.getSourceWhere() != null && !options.getSourceWhere().isEmpty()
escapeTableName(tableName) + " where ora_hash(rowid," + (options.getJobs() - 1) + ") = ?";
}


LOG.debug("Reading table with command: " + sqlCmd);
return super.execute(sqlCmd, nThread);
return super.execute(sqlCmd, (Object) nThread);
}

private void oracleAlterSession(Boolean directRead) throws SQLException {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/replicadb/manager/PostgresqlManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ protected void createStagingTable() throws SQLException {
Statement statement = this.getConnection().createStatement();
String sinkStagingTable = getQualifiedStagingTableName();

String sql = "CREATE UNLOGGED TABLE IF NOT EXISTS " + sinkStagingTable + " ( LIKE " + this.getSinkTableName() + " INCLUDING DEFAULTS INCLUDING CONSTRAINTS )";
String sql = "CREATE UNLOGGED TABLE IF NOT EXISTS " + sinkStagingTable + " ( LIKE " + this.getSinkTableName() + " INCLUDING DEFAULTS INCLUDING CONSTRAINTS ) WITH (autovacuum_enabled=false)";

LOG.info("Creating staging table with this command: " + sql);
statement.executeUpdate(sql);
Expand Down
13 changes: 9 additions & 4 deletions src/main/java/org/replicadb/manager/SqlManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -447,10 +447,15 @@ public void postSinkTasks() throws SQLException {

@Override
public void cleanUp() throws SQLException {
// Only drop staging table if it was created automatically
if (options.getSinkStagingTable() == null || options.getSinkStagingTable().isEmpty()) {
// Drop staging table
this.dropStagingTable();

// On INCREMENTAL mode
if (options.getMode().equals(ReplicationMode.INCREMENTAL.getModeText())) {

// Only drop staging table if it was created automatically
if (options.getSinkStagingTable() == null || options.getSinkStagingTable().isEmpty()) {
// Drop staging table
this.dropStagingTable();
}
}

}
Expand Down

0 comments on commit a6fd326

Please sign in to comment.