Skip to content

Commit b1f9fc5

Browse files
authored
[7.x] Allow setting synchronous_commit for Postgres (#33897)
See https://www.postgresql.org/docs/current/runtime-config-wal.html#GUC-SYNCHRONOUS-COMMIT > Specifies whether transaction commit will wait for WAL records to be written to disk before the command returns a “success” indication to the client. Valid values are on, remote_apply, remote_write, local, and off > … > So, turning synchronous_commit off can be a useful alternative when performance is more important than exact certainty about the durability of a transaction.
1 parent f1451bf commit b1f9fc5

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/Illuminate/Database/Connectors/PostgresConnector.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ public function connect(array $config)
4747
// determine if the option has been specified and run a statement if so.
4848
$this->configureApplicationName($connection, $config);
4949

50+
$this->configureSynchronousCommit($connection, $config);
51+
5052
return $connection;
5153
}
5254

@@ -173,4 +175,20 @@ protected function addSslOptions($dsn, array $config)
173175

174176
return $dsn;
175177
}
178+
179+
/**
180+
* Configure the synchronous_commit setting.
181+
*
182+
* @param \PDO $connection
183+
* @param array $config
184+
* @return void
185+
*/
186+
protected function configureSynchronousCommit($connection, array $config)
187+
{
188+
if (! isset($config['synchronous_commit'])) {
189+
return;
190+
}
191+
192+
$connection->prepare("set synchronous_commit to '{$config['synchronous_commit']}'")->execute();
193+
}
176194
}

0 commit comments

Comments
 (0)