diff --git a/control_plane/src/compute.rs b/control_plane/src/compute.rs index 11688167b8..faa600101d 100644 --- a/control_plane/src/compute.rs +++ b/control_plane/src/compute.rs @@ -420,8 +420,16 @@ impl PostgresNode { self.pg_ctl(&["restart"]) } - pub fn stop(&self) -> Result<()> { - self.pg_ctl(&["-m", "immediate", "stop"]) + pub fn stop(&self, destroy: bool) -> Result<()> { + self.pg_ctl(&["-m", "immediate", "stop"])?; + if destroy { + println!( + "Destroying postgres data directory '{}'", + self.pgdata().to_str().unwrap() + ); + fs::remove_dir_all(&self.pgdata())?; + } + Ok(()) } pub fn connstr(&self) -> String { @@ -453,7 +461,7 @@ impl Drop for PostgresNode { // and checking it here. But let just clean datadirs on start. fn drop(&mut self) { if self.is_test { - let _ = self.stop(); + let _ = self.stop(true); } } } diff --git a/zenith/src/main.rs b/zenith/src/main.rs index 654756b561..68ccb42666 100644 --- a/zenith/src/main.rs +++ b/zenith/src/main.rs @@ -61,7 +61,16 @@ fn main() -> Result<()> { .subcommand(SubCommand::with_name("list")) .subcommand(SubCommand::with_name("create").arg(timeline_arg.clone())) .subcommand(SubCommand::with_name("start").arg(timeline_arg.clone())) - .subcommand(SubCommand::with_name("stop").arg(timeline_arg.clone())), + .subcommand( + SubCommand::with_name("stop") + .arg(timeline_arg.clone()) + .arg( + Arg::with_name("destroy") + .help("Also delete data directory (now optional, should be default in future)") + .long("destroy") + .required(false) + ) + ) ) .subcommand( SubCommand::with_name("remote") @@ -356,12 +365,13 @@ fn handle_pg(pg_match: &ArgMatches, env: &local_env::LocalEnv) -> Result<()> { } ("stop", Some(sub_m)) => { let timeline_name = sub_m.value_of("timeline").unwrap_or("main"); + let destroy = sub_m.is_present("destroy"); + let node = cplane .nodes .get(timeline_name) .ok_or_else(|| anyhow!("postgres {} is not found", timeline_name))?; - node.stop()?; - // TODO: destroy data directory here + node.stop(destroy)?; } _ => {}