Skip to content

Commit

Permalink
Disable synchronous commit on all connections
Browse files Browse the repository at this point in the history
This simplifies the code, because we don't have to decide whether to set
this or not on each connection. And it doesn't matter much when setting
this for read-only connections which don't need this.

Setting synchronous_commit = off speeds up writing to the database,
because commis are not delayed until the WAL is written to disk. It
can not lead to corruption of the database.

https://www.postgresql.org/docs/current/runtime-config-wal.html#GUC-SYNCHRONOUS-COMMIT
  • Loading branch information
joto committed Feb 3, 2024
1 parent c22ac73 commit dac98d6
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 6 deletions.
3 changes: 0 additions & 3 deletions src/db-copy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,6 @@ void db_copy_thread_t::thread_t::operator()()
try {
m_conn = std::make_unique<pg_conn_t>(m_connection_params, "copy");

// Let commits happen faster by delaying when they actually occur.
m_conn->exec("SET synchronous_commit = off");

// Disable sequential scan on database tables in the copy threads.
// The copy threads only do COPYs (which are unaffected by this
// setting) and DELETEs which we know benefit from the index. For
Expand Down
1 change: 0 additions & 1 deletion src/flex-table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,6 @@ void table_connection_t::connect(connection_params_t const &connection_params)

m_db_connection =
std::make_unique<pg_conn_t>(connection_params, "out.flex.table");
m_db_connection->exec("SET synchronous_commit = off");
}

static void enable_check_trigger(pg_conn_t const &db_connection,
Expand Down
5 changes: 5 additions & 0 deletions src/pgsql.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ pg_conn_t::pg_conn_t(connection_params_t const &connection_params,
if (!get_logger().debug_enabled()) {
exec("SET client_min_messages = WARNING");
}

// Disable synchronous_commit on all connections. For some connections it
// might not matter, especially if they read only, but then it doesn't
// hurt either.
exec("SET synchronous_commit = off");
}

void pg_conn_t::close()
Expand Down
2 changes: 0 additions & 2 deletions src/table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ void table_t::sync() { m_copy.sync(); }
void table_t::connect()
{
m_sql_conn = std::make_unique<pg_conn_t>(m_connection_params, "out.pgsql");
//let commits happen faster by delaying when they actually occur
m_sql_conn->exec("SET synchronous_commit = off");
}

void table_t::start(connection_params_t const &connection_params,
Expand Down

0 comments on commit dac98d6

Please sign in to comment.