From 742f4a86499fb17a839c5cba5341abfeba498b47 Mon Sep 17 00:00:00 2001 From: Markus Podar Date: Sat, 15 Aug 2020 23:42:37 +0200 Subject: [PATCH] [7.x] Allow setting synchronous_commit for Postgres MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- .../Database/Connectors/PostgresConnector.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/Illuminate/Database/Connectors/PostgresConnector.php b/src/Illuminate/Database/Connectors/PostgresConnector.php index c40369d75f94..b960938f0ab7 100755 --- a/src/Illuminate/Database/Connectors/PostgresConnector.php +++ b/src/Illuminate/Database/Connectors/PostgresConnector.php @@ -47,6 +47,8 @@ public function connect(array $config) // determine if the option has been specified and run a statement if so. $this->configureApplicationName($connection, $config); + $this->configureSynchronousCommit($connection, $config); + return $connection; } @@ -173,4 +175,20 @@ protected function addSslOptions($dsn, array $config) return $dsn; } + + /** + * Configure the synchronous_commit setting + * + * @param \PDO $connection + * @param array $config + * @return void + */ + protected function configureSynchronousCommit($connection, array $config) + { + if (! isset($config['synchronous_commit'])) { + return; + } + + $connection->prepare("set synchronous_commit to '{$config['synchronous_commit']}'")->execute(); + } }