Skip to content

Commit b791cdf

Browse files
committed
bump nixpkgs, add auto-explain option
1 parent fa2db4b commit b791cdf

4 files changed

Lines changed: 29 additions & 18 deletions

File tree

flake.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
inputs = {
55
flake-utils.url = "github:numtide/flake-utils";
6-
nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.05";
6+
nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.11";
77
};
88

99
outputs = { self, flake-utils, nixpkgs }:
@@ -30,17 +30,11 @@
3030
"${package-name}" = pkgs.rustPlatform.buildRustPackage {
3131
pname = package-name;
3232
version = "0.1.0";
33-
cargoSha256 = "sha256-6V1NbCW3y1GA8y8yL5hP/GVNHjdhbsvT31t2iwEfkec=";
33+
cargoHash = "sha256-L8cCKVhrXbazm4NvGKWU+i571lk8zA29bvaNdxU0BDM=";
3434
src = ./src;
3535
buildInputs =
3636
let
37-
darwin-frameworks = with pkgs.darwin.apple_sdk.frameworks;
38-
[
39-
CoreFoundation
40-
CoreServices
41-
SystemConfiguration
42-
pkgs.libiconv
43-
];
37+
darwin-frameworks = [ ];
4438
system-dependent = if pkgs.stdenv.isDarwin then darwin-frameworks else [ ];
4539
in
4640
system-dependent;

src/src/cli/parser/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ pub struct Args {
99
/// Run postgres in an existing db cluster
1010
#[arg(long)]
1111
pub use_existing_dir: bool,
12+
/// Automatically configure auto-explain
13+
#[arg(long)]
14+
pub auto_explain: bool,
1215
/// Localhost port to listen on
1316
#[arg(short, long)]
1417
pub port: Option<u16>,

src/src/lib.rs

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ fn run<'a>(args: &'a cli::Args, muxer: &'a mut PgMuxer) -> Result<(), Error<'a>>
184184
.map_err(|e| (&args.directory as &'a Path, e))?;
185185
if !args.use_existing_dir {
186186
muxer.init_db(&args.directory)?;
187-
tweak_postgresql_conf(&args.directory, args.port).unwrap();
187+
tweak_postgresql_conf(&args.directory, args.auto_explain, args.port).unwrap();
188188
}
189189
muxer.run_postgres(&args.directory, args.port)?;
190190
if !args.use_existing_dir {
@@ -227,7 +227,7 @@ fn run<'a>(args: &'a cli::Args, muxer: &'a mut PgMuxer) -> Result<(), Error<'a>>
227227
Ok(())
228228
}
229229

230-
fn tweak_postgresql_conf(db_path: &Path, port: Option<u16>) -> io::Result<()> {
230+
fn tweak_postgresql_conf(db_path: &Path, auto_explain: bool, port: Option<u16>) -> io::Result<()> {
231231
let mut conf_path = PathBuf::from(db_path);
232232
conf_path.push("postgresql.conf");
233233
let file = OpenOptions::new().append(true).open(conf_path)?;
@@ -236,14 +236,28 @@ fn tweak_postgresql_conf(db_path: &Path, port: Option<u16>) -> io::Result<()> {
236236
None => &[("listen_addresses", "")],
237237
Some(_) => &[],
238238
};
239+
for (k, v) in port_options {
240+
writeln!(file, "{k} = '{v}'")?;
241+
}
239242
let options: &[(&str, &str)] = &[
240243
("unix_socket_directories", db_path.to_str().unwrap()),
241244
("log_connections", "on"),
242245
("log_disconnections", "on"),
243246
];
244-
for options in [port_options, options] {
245-
for (k, v) in options {
246-
writeln!(file, "{k} = '{v}'")?;
247+
for (k, v) in options {
248+
writeln!(file, "{k} = '{v}'")?;
249+
}
250+
if auto_explain {
251+
let auto_explain_options: &[(&str, &str)] = &[
252+
("session_preload_libraries", "'auto_explain'"),
253+
("auto_explain.log_min_duration", "0"),
254+
("auto_explain.log_analyze", "true"),
255+
("auto_explain.log_buffers", "true"),
256+
("auto_explain.log_triggers", "true"),
257+
("auto_explain.log_nested_statements", "true"),
258+
];
259+
for (k, v) in auto_explain_options {
260+
writeln!(file, "{k} = {v}")?;
247261
}
248262
}
249263
file.flush()?;

0 commit comments

Comments
 (0)