diff --git a/control_plane/src/local_env.rs b/control_plane/src/local_env.rs index 14bb4cf346..f4fbc99420 100644 --- a/control_plane/src/local_env.rs +++ b/control_plane/src/local_env.rs @@ -197,25 +197,18 @@ impl Default for SafekeeperConf { } impl LocalEnv { + pub fn pg_distrib_dir_raw(&self) -> PathBuf { + self.pg_distrib_dir.clone() + } + pub fn pg_distrib_dir(&self, pg_version: u32) -> PathBuf { - let mut path = self.pg_distrib_dir.clone(); + let path = self.pg_distrib_dir.clone(); - if pg_version != DEFAULT_PG_VERSION { - // step up to the parent directory - // We assume that the pg_distrib subdirs - // for different pg versions - // are located in the same directory - // and follow the naming convention: v14, v15, etc. - path.pop(); - - match pg_version { - 14 => return path.join(format!("v{pg_version}")), - 15 => return path.join(format!("v{pg_version}")), - _ => panic!("Unsupported postgres version: {}", pg_version), - }; + match pg_version { + 14 => path.join(format!("v{pg_version}")), + 15 => path.join(format!("v{pg_version}")), + _ => panic!("Unsupported postgres version: {}", pg_version), } - - path } pub fn pg_bin_dir(&self, pg_version: u32) -> PathBuf { @@ -319,7 +312,7 @@ impl LocalEnv { let mut env: LocalEnv = toml::from_str(toml)?; // Find postgres binaries. - // Follow POSTGRES_DISTRIB_DIR if set, otherwise look in "pg_install/v14". + // Follow POSTGRES_DISTRIB_DIR if set, otherwise look in "pg_install". // Note that later in the code we assume, that distrib dirs follow the same pattern // for all postgres versions. if env.pg_distrib_dir == Path::new("") { @@ -327,7 +320,7 @@ impl LocalEnv { env.pg_distrib_dir = postgres_bin.into(); } else { let cwd = env::current_dir()?; - env.pg_distrib_dir = cwd.join("pg_install/v14") + env.pg_distrib_dir = cwd.join("pg_install") } } diff --git a/control_plane/src/storage.rs b/control_plane/src/storage.rs index 9032f99971..bfbd6e91c3 100644 --- a/control_plane/src/storage.rs +++ b/control_plane/src/storage.rs @@ -118,7 +118,7 @@ impl PageServerNode { // FIXME: the paths should be shell-escaped to handle paths with spaces, quotas etc. let pg_distrib_dir_param = format!( "pg_distrib_dir='{}'", - self.env.pg_distrib_dir(pg_version).display() + self.env.pg_distrib_dir_raw().display() ); let authg_type_param = format!("auth_type='{}'", self.env.pageserver.auth_type); diff --git a/docs/settings.md b/docs/settings.md index 30db495dbe..878681fce1 100644 --- a/docs/settings.md +++ b/docs/settings.md @@ -155,6 +155,8 @@ for other files and for sockets for incoming connections. #### pg_distrib_dir A directory with Postgres installation to use during pageserver activities. +Since pageserver supports several postgres versions, `pg_distrib_dir` contains +a subdirectory for each version with naming convention `v{PG_MAJOR_VERSION}/`. Inside that dir, a `bin/postgres` binary should be present. The default distrib dir is `./pg_install/`. diff --git a/pageserver/src/config.rs b/pageserver/src/config.rs index a4346c0190..b75f8f8265 100644 --- a/pageserver/src/config.rs +++ b/pageserver/src/config.rs @@ -21,7 +21,6 @@ use utils::{ use crate::tenant::TIMELINES_SEGMENT_NAME; use crate::tenant_config::{TenantConf, TenantConfOpt}; -use crate::DEFAULT_PG_VERSION; /// The name of the metadata file pageserver creates per timeline. pub const METADATA_FILE_NAME: &str = "metadata"; @@ -210,7 +209,7 @@ impl Default for PageServerConfigBuilder { workdir: Set(PathBuf::new()), pg_distrib_dir: Set(env::current_dir() .expect("cannot access current directory") - .join(format!("pg_install/v{}", DEFAULT_PG_VERSION))), + .join(format!("pg_install",))), auth_type: Set(AuthType::Trust), auth_validation_public_key_path: Set(None), remote_storage_config: Set(None), @@ -376,24 +375,13 @@ impl PageServerConf { // Postgres distribution paths // pub fn pg_distrib_dir(&self, pg_version: u32) -> PathBuf { - let mut path = self.pg_distrib_dir.clone(); + let path = self.pg_distrib_dir.clone(); - if pg_version != DEFAULT_PG_VERSION { - // step up to the parent directory - // We assume that the pg_distrib subdirs - // for different pg versions - // are located in the same directory - // and follow the naming convention: v14, v15, etc. - path.pop(); - - match pg_version { - 14 => return path.join(format!("v{pg_version}")), - 15 => return path.join(format!("v{pg_version}")), - _ => panic!("Unsupported postgres version: {}", pg_version), - }; + match pg_version { + 14 => path.join(format!("v{pg_version}")), + 15 => path.join(format!("v{pg_version}")), + _ => panic!("Unsupported postgres version: {}", pg_version), } - - path } pub fn pg_bin_dir(&self, pg_version: u32) -> PathBuf { @@ -477,14 +465,6 @@ impl PageServerConf { ); } - let pg_version = DEFAULT_PG_VERSION; - if !conf.pg_bin_dir(pg_version).join("postgres").exists() { - bail!( - "Can't find postgres binary at {}", - conf.pg_bin_dir(pg_version).display() - ); - } - conf.default_tenant_conf = t_conf.merge(TenantConf::default()); Ok(conf) @@ -654,6 +634,7 @@ mod tests { use tempfile::{tempdir, TempDir}; use super::*; + use crate::DEFAULT_PG_VERSION; const ALL_BASE_VALUES_TOML: &str = r#" # Initial configuration file created by 'pageserver --init' @@ -892,9 +873,10 @@ broker_endpoints = ['{broker_endpoint}'] let workdir = tempdir_path.join("workdir"); fs::create_dir_all(&workdir)?; - let pg_distrib_dir = tempdir_path.join(format!("pg_distrib/v{DEFAULT_PG_VERSION}")); - fs::create_dir_all(&pg_distrib_dir)?; - let postgres_bin_dir = pg_distrib_dir.join("bin"); + let pg_distrib_dir = tempdir_path.join("pg_distrib"); + let pg_distrib_dir_versioned = pg_distrib_dir.join(format!("v{DEFAULT_PG_VERSION}")); + fs::create_dir_all(&pg_distrib_dir_versioned)?; + let postgres_bin_dir = pg_distrib_dir_versioned.join("bin"); fs::create_dir_all(&postgres_bin_dir)?; fs::write(postgres_bin_dir.join("postgres"), "I'm postgres, trust me")?; diff --git a/pageserver/src/http/routes.rs b/pageserver/src/http/routes.rs index a55c6c973e..72cbb0e819 100644 --- a/pageserver/src/http/routes.rs +++ b/pageserver/src/http/routes.rs @@ -174,7 +174,7 @@ async fn timeline_create_handler(mut request: Request) -> Result { // Created. Construct a TimelineInfo for it.