Skip to content

Commit dac98d6

Browse files
committed
Disable synchronous commit on all connections
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
1 parent c22ac73 commit dac98d6

File tree

4 files changed

+5
-6
lines changed

4 files changed

+5
-6
lines changed

src/db-copy.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,6 @@ void db_copy_thread_t::thread_t::operator()()
130130
try {
131131
m_conn = std::make_unique<pg_conn_t>(m_connection_params, "copy");
132132

133-
// Let commits happen faster by delaying when they actually occur.
134-
m_conn->exec("SET synchronous_commit = off");
135-
136133
// Disable sequential scan on database tables in the copy threads.
137134
// The copy threads only do COPYs (which are unaffected by this
138135
// setting) and DELETEs which we know benefit from the index. For

src/flex-table.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,6 @@ void table_connection_t::connect(connection_params_t const &connection_params)
247247

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

253252
static void enable_check_trigger(pg_conn_t const &db_connection,

src/pgsql.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ pg_conn_t::pg_conn_t(connection_params_t const &connection_params,
7575
if (!get_logger().debug_enabled()) {
7676
exec("SET client_min_messages = WARNING");
7777
}
78+
79+
// Disable synchronous_commit on all connections. For some connections it
80+
// might not matter, especially if they read only, but then it doesn't
81+
// hurt either.
82+
exec("SET synchronous_commit = off");
7883
}
7984

8085
void pg_conn_t::close()

src/table.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,6 @@ void table_t::sync() { m_copy.sync(); }
6767
void table_t::connect()
6868
{
6969
m_sql_conn = std::make_unique<pg_conn_t>(m_connection_params, "out.pgsql");
70-
//let commits happen faster by delaying when they actually occur
71-
m_sql_conn->exec("SET synchronous_commit = off");
7270
}
7371

7472
void table_t::start(connection_params_t const &connection_params,

0 commit comments

Comments
 (0)