Allow setting configuration parameters to the postgres cluster
Ekleog opened this issue · comments
Hey! I'm looking into postgresfixture for running tests, and after submitting allenap/rust-postgresfixture#124 I noticed that it does not actually seem to support setting postgresql.conf
parameters from the API.
Is it true, or did I miss the place to do it?
I'd need it in order to implement the optimizations listed here (eg. fsync=off), for test running.
(Maybe postgresqlfixture could even come with an unsafe set of settings optimized for speed so that not everyone has to read through the same documentation in order to get fast tests)
What do you think?
Yeah, there's no way to set configuration parameters beforehand. Two things though:
ALTER SYSTEM
can be used to make these kinds of changes. The cluster does need to be restarted, that's the downside.fsync=off
is set by default for clusters created by this library (here).
I'm not sure if I want to fix this. Apart from fsync=off
what other settings do you want to set? Would ALTER SYSTEM
be a reasonable mechanism?
allenap/rust-postgresfixture#82 is also relevant. If fsync=off
is no longer the default, it should probably be a straightforward option to choose.
Hmm so this answer lists quite a lot of configuration parameters, though I have literally no knowledge of actual pgsql configuration.
Would configuring be as simple as writing a configuration file at some location in the cluster directory before launching it? Seems to me like the current fsync
parameter is handled by a -F
flag, if I github search the code properly.
If it's actually that, then the easiest solution might be to just allow the user to provide a verbatim configuration file, and just write it to disk while creating the cluster. WDYT?
Allowing a configuration file seems like broadening the surface too wide, and catching errors too late. I'm still thinking about ALTER SYSTEM
. Perhaps I could add a Cluster::new_with_config
function, something like:
enum Config {
AlterSystem(String, String)
AlterSystemSetDefault(String)
AlterSystemReset(String)
AlterSystemResetAll,
}
impl Cluster {
pub fn new_with_config<P: AsRef<Path>>(
datadir: P,
runtime: runtime::Runtime,
config: Vec<Config>,
) -> Self {
// ...
}
}
This would use ALTER SYSTEM
and then reload or restart as necessary.
Maybe the Config
enum could be something like:
enum Config {
FsyncOn,
FsyncOff,
FsyncReset,
// ... others ...
Set(String, String),
Reset(String),
ResetAll,
}
I don't know. I don't think that this is a blocker because ALTER SYSTEM
can be used already. I could add some documentation to explain how to use it though.