(postgres_bin: &Path, initdb_bin: &Path)
| 3324 | |
| 3325 | impl NativePostgres { |
| 3326 | fn start(postgres_bin: &Path, initdb_bin: &Path) -> Result<Self> { |
| 3327 | let root = env::current_dir() |
| 3328 | .context("read current directory")? |
| 3329 | .join("target/perf") |
| 3330 | .join(format!( |
| 3331 | "native-postgres-{}-{}", |
| 3332 | std::process::id(), |
| 3333 | now_micros()? |
| 3334 | )); |
| 3335 | let data_dir = root.join("data"); |
| 3336 | let socket_dir = root.join("socket"); |
| 3337 | fs::create_dir_all(&data_dir).with_context(|| format!("create {}", data_dir.display()))?; |
| 3338 | fs::create_dir_all(&socket_dir) |
| 3339 | .with_context(|| format!("create {}", socket_dir.display()))?; |
| 3340 | |
| 3341 | let init_status = Command::new(initdb_bin) |
| 3342 | .arg("-D") |
| 3343 | .arg(&data_dir) |
| 3344 | .args([ |
| 3345 | "-A", |
| 3346 | "trust", |
| 3347 | "-U", |
| 3348 | "postgres", |
| 3349 | "--encoding=UTF8", |
| 3350 | "--no-instructions", |
| 3351 | ]) |
| 3352 | .stdout(Stdio::null()) |
| 3353 | .stderr(Stdio::piped()) |
| 3354 | .status() |
| 3355 | .with_context(|| format!("spawn native initdb {}", initdb_bin.display()))?; |
| 3356 | ensure!( |
| 3357 | init_status.success(), |
| 3358 | "native initdb failed with {init_status}" |
| 3359 | ); |
| 3360 | |
| 3361 | let port = 55432 + (std::process::id() % 1000) as u16; |
| 3362 | let log_path = root.join("postgres.log"); |
| 3363 | let log = fs::File::create(&log_path) |
| 3364 | .with_context(|| format!("create native Postgres log {}", log_path.display()))?; |
| 3365 | let mut command = Command::new(postgres_bin); |
| 3366 | command.arg("-D").arg(&data_dir); |
| 3367 | #[cfg(unix)] |
| 3368 | { |
| 3369 | command |
| 3370 | .arg("-h") |
| 3371 | .arg("127.0.0.1") |
| 3372 | .arg("-k") |
| 3373 | .arg(&socket_dir); |
| 3374 | } |
| 3375 | #[cfg(not(unix))] |
| 3376 | { |
| 3377 | command.arg("-h").arg("127.0.0.1"); |
| 3378 | } |
| 3379 | let child = command |
| 3380 | .arg("-p") |
| 3381 | .arg(port.to_string()) |
| 3382 | .args([ |
| 3383 | "-F", |
no test coverage detected