pgrx icon indicating copy to clipboard operation
pgrx copied to clipboard

cargo pgx init behaves differently on pg14 as opposed to earlier pgs

Open fingon opened this issue 4 years ago • 4 comments

Given pgs that are compiled similarly, the behaviour differs for pg 14:

$ cargo pgx --version
cargo-pgx 0.2.5
$ rm -rf ~/.pgx
$ cargo pgx init --pg12=/usr/pgsql-12/bin/pg_config
   Validating /usr/pgsql-12/bin/pg_config
 Initializing data directory at /home/mstenber/.pgx/data-12
$ cargo pgx init --pg13=/usr/pgsql-13/bin/pg_config
   Validating /usr/pgsql-13/bin/pg_config
 Initializing data directory at /home/mstenber/.pgx/data-13
$ cargo pgx init --pg14=/usr/pgsql-14/bin/pg_config
   Validating /usr/pgsql-14/bin/pg_config
 Initializing data directory at /home/mstenber/.pgx/data-14
      [error] : No such file or directory (os error 2)

It is not immediately obvious to me what is the difference, so decided to fire an issue just in case :)

fingon avatar Nov 23 '21 07:11 fingon

That error message is unfortunate. :(

Couple of questions:

  • What's the contents of ~/.pgx/config.toml?
  • Are we sure /usr/pgsql-14/bin/pg_config exists on your machine?
  • What happens if you just run a plain cargo pgx init and let it download/compile/install all the Postgres versions?

I'm doing exactly what you're doing for automated ZoimboDB build system across numerous Linux distros (all via Docker), and it works just fine, so I feel like there's something specific to your machine, but we need to dial in what it might be.

I also notice that you're using aarch64 -- I don't have access to one of those, so could it be that PG14 does something different on that platform? I don't know why it would, just guessing...

eeeebbbbrrrr avatar Nov 23 '21 16:11 eeeebbbbrrrr

Looking at the code, I think maybe you're missing initdb in /usr/pgsql-14/bin/ Could that be the case?

The code is:

pub(crate) fn initdb(bindir: &PathBuf, datadir: &PathBuf) -> Result<(), std::io::Error> {
    println!(
        " {} data directory at {}",
        "Initializing".bold().green(),
        datadir.display()
    );
    let mut command = std::process::Command::new(format!("{}/initdb", bindir.display()));
    command
        .stdout(Stdio::piped())
        .stderr(Stdio::piped())
        .arg("-D")
        .arg(&datadir);

    let command_str = format!("{:?}", command);
    let output = command.output()?;

    if !output.status.success() {
        exit_with_error!(
            "problem running initdb: {}\n{}",
            command_str,
            String::from_utf8(output.stderr).unwrap()
        )
    }

    Ok(())
}

and I think we'd get the "no such file or directory" if initdb didn't exist at all.

eeeebbbbrrrr avatar Nov 23 '21 17:11 eeeebbbbrrrr

I think that was the case - I did not install -server package for pg14, just -devel. In my today's container, this actually worked, with initdb available:

$ ls -l /usr/pgsql-14/bin/initdb
-rwxr-xr-x. 1 root root 138248 Nov 23 12:37 /usr/pgsql-14/bin/initdb

Probably the error message could be clearer - I think I had pg_config available (as it is in -devel), but not initdb (-server).

fingon avatar Nov 24 '21 05:11 fingon

Glad you got it sorted. I’ll definitely clean up the error message. Definitely unfortunate the way it is now.

eeeebbbbrrrr avatar Nov 25 '21 18:11 eeeebbbbrrrr