Skip to content

Commit e4beb2b

Browse files
committed
Disable synchronous_commit when running faster
1 parent 556fd41 commit e4beb2b

File tree

2 files changed

+19
-13
lines changed

2 files changed

+19
-13
lines changed

src/cli.rs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,10 @@ pub struct ClusterArgs {
7676

7777
/// Run the cluster in a "faster" mode.
7878
///
79-
/// This disables `fsync` and `full_page_writes` in the cluster. This can
80-
/// make the cluster faster but it can also lead to unrecoverable data
81-
/// corruption in the event of a power failure or system crash. Useful for
82-
/// tests, for example, but probably not production.
79+
/// This disables `fsync`, `full_page_writes`, and `synchronous_commit` in
80+
/// the cluster. This can make the cluster faster but it can also lead to
81+
/// unrecoverable data corruption in the event of a power failure or system
82+
/// crash. Useful for tests, for example, but probably not production.
8383
///
8484
/// In the future this may make additional or different changes. See
8585
/// https://www.postgresql.org/docs/16/runtime-config-wal.html for more
@@ -88,23 +88,27 @@ pub struct ClusterArgs {
8888
/// This option is STICKY. Once you've used it, the cluster will be
8989
/// configured to be "faster but less safe" and you do not need to specify
9090
/// it again. To find out if the cluster is running in this mode, open a
91-
/// `psql` shell (e.g. `postgresfixture shell`) and run `SHOW fsync;` and
92-
/// `SHOW full_page_writes;`.
91+
/// `psql` shell (e.g. `postgresfixture shell`) and run `SHOW fsync; SHOW
92+
/// full_page_writes; SHOW synchronous_commit;`.
9393
#[clap(long = "faster-but-less-safe", action = clap::ArgAction::SetTrue, default_value_t = false, display_order = 2)]
9494
pub faster: bool,
9595

9696
/// Run the cluster in a "safer" mode.
9797
///
9898
/// This is the opposite of `--faster-but-less-safe`, i.e. it runs with
99-
/// `fsync` and `full_page_writes` enabled in the cluster. This is the
100-
/// default when neither `--faster-but-less-safe` nor `--safe-but-slower`
101-
/// have been specified.
99+
/// `fsync`, `full_page_writes`, and `synchronous_commit` enabled in the
100+
/// cluster.
101+
///
102+
/// NOTE: this actually *resets* the `fsync`, `full_page_writes`, and
103+
/// `synchronous_commit` settings to their defaults. Unless they've been
104+
/// configured differently in the cluster's `postgresql.conf`, the default
105+
/// for these settings is on/enabled.
102106
///
103107
/// This option is STICKY. Once you've used it, the cluster will be
104108
/// configured to be "slower and safer" and you do not need to specify it
105109
/// again. To find out if the cluster is running in this mode, open a `psql`
106-
/// shell (e.g. `postgresfixture shell`) and run `SHOW fsync;` and `SHOW
107-
/// full_page_writes;`.
110+
/// shell (e.g. `postgresfixture shell`) and run `SHOW fsync; SHOW
111+
/// full_page_writes; SHOW synchronous_commit;`.
108112
#[clap(long = "slower-but-safer", action = clap::ArgAction::SetTrue, default_value_t = false, display_order = 3, conflicts_with = "faster")]
109113
pub slower: bool,
110114
}

src/main.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,15 +179,17 @@ fn initialise(
179179
let mut conn = cluster.connect("template1")?;
180180
conn.execute("ALTER SYSTEM SET fsync = 'off'", &[])?;
181181
conn.execute("ALTER SYSTEM SET full_page_writes = 'off'", &[])?;
182+
conn.execute("ALTER SYSTEM SET synchronous_commit = 'off'", &[])?;
182183
// TODO: Check `pg_file_settings` for errors before reloading.
183184
conn.execute("SELECT pg_reload_conf()", &[])?;
184185
Ok(())
185186
}
186187
} else if slower {
187188
|cluster: &cluster::Cluster| {
188189
let mut conn = cluster.connect("template1")?;
189-
conn.execute("ALTER SYSTEM SET fsync = 'on'", &[])?;
190-
conn.execute("ALTER SYSTEM SET full_page_writes = 'on'", &[])?;
190+
conn.execute("ALTER SYSTEM RESET fsync", &[])?;
191+
conn.execute("ALTER SYSTEM RESET full_page_writes", &[])?;
192+
conn.execute("ALTER SYSTEM RESET synchronous_commit", &[])?;
191193
// TODO: Check `pg_file_settings` for errors before reloading.
192194
conn.execute("SELECT pg_reload_conf()", &[])?;
193195
Ok(())

0 commit comments

Comments
 (0)