diff --git a/compute_tools/src/compute.rs b/compute_tools/src/compute.rs index 0fa315682d..dc1470fd98 100644 --- a/compute_tools/src/compute.rs +++ b/compute_tools/src/compute.rs @@ -683,6 +683,7 @@ impl ComputeNode { ComputeMode::Primary => {} ComputeMode::Replica | ComputeMode::Static(..) => { add_standby_signal(pgdata_path)?; + remove_logrep_files(pgdata_path).context("remove_logrep_files")?; } } diff --git a/compute_tools/src/pg_helpers.rs b/compute_tools/src/pg_helpers.rs index 5deb50d6b7..0c84856158 100644 --- a/compute_tools/src/pg_helpers.rs +++ b/compute_tools/src/pg_helpers.rs @@ -1,6 +1,5 @@ use std::collections::HashMap; use std::fmt::Write; -use std::fs; use std::fs::File; use std::io::{BufRead, BufReader}; use std::os::unix::fs::PermissionsExt; @@ -8,6 +7,7 @@ use std::path::Path; use std::process::Child; use std::thread::JoinHandle; use std::time::{Duration, Instant}; +use std::{fs, io}; use anyhow::{bail, Result}; use ini::Ini; @@ -366,6 +366,25 @@ pub fn create_pgdata(pgdata: &str) -> Result<()> { Ok(()) } +/// Remove contents of the given directory. It must exist. +fn remove_dir_contents>(path: P) -> io::Result<()> { + for entry in fs::read_dir(path)? { + fs::remove_file(entry?.path())?; + } + Ok(()) +} + +/// Logical replication slots and snapshot files are currently stored on +/// pageserver via logical replication messages, so standby can't write them. So +/// we remove them from the basebackup prepared for the standby. In particular +/// this removes noise from ls_monitor failing to drop them. +pub fn remove_logrep_files>(pgdata: P) -> Result<()> { + remove_dir_contents(pgdata.as_ref().join("pg_replslot"))?; + remove_dir_contents(pgdata.as_ref().join("pg_logical/snapshots"))?; + remove_dir_contents(pgdata.as_ref().join("pg_logical/mappings"))?; + Ok(()) +} + /// Update pgbouncer.ini with provided options fn update_pgbouncer_ini( pgbouncer_config: HashMap,