Skip to content

Commit

Permalink
[7.x] Allow setting synchronous_commit for Postgres (#33897)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mfn committed Aug 17, 2020
1 parent f1451bf commit b1f9fc5
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/Illuminate/Database/Connectors/PostgresConnector.php
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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();
}
}

0 comments on commit b1f9fc5

Please sign in to comment.