Remove LR files from basebackup when preparing standby.

Standby can't modify them as it doesn't write WAL.
This commit is contained in:
Arseny Sher
2024-03-14 17:47:47 +03:00
parent 83855a907c
commit 5fbaa3fd78
2 changed files with 21 additions and 1 deletions

View File

@@ -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")?;
}
}

View File

@@ -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<P: AsRef<Path>>(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<P: AsRef<Path>>(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<String, String>,