pgcentralfoundation / pgrx

Build Postgres Extensions with Rust!
Other
3.68k stars 247 forks source link

`cargo pgrx package` fails in Ubuntu 22.04 for "couldn't read postmaster" #1324

Closed owenthereal closed 1 year ago

owenthereal commented 1 year ago

This is the Dockerfile to reproduce the error for pg_graphql:

FROM ubuntu:22.04

RUN set -eux; \
    apt-get update; \
    apt-get install -y --no-install-recommends \
    postgresql-common \
    gnupg2 \
    build-essential \
    curl \
    ca-certificates \
    libreadline6-dev \
    zlib1g-dev \
    pkg-config \
    ; \
    sh /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh -y; \
    apt-get update; \
    apt-get install -y --no-install-recommends \
    postgresql-server-dev-all \
    ; \
    apt-get clean

WORKDIR /home/pg_graphql
ENV PATH=/root/.cargo/bin:$PATH

RUN \
  curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --no-modify-path --profile minimal --default-toolchain nightly && \
  rustup --version && \
  rustc --version && \
  cargo --version

# PGRX
RUN cargo install cargo-pgrx --version 0.10.2 --locked
RUN cargo pgrx init --pg15 /usr/lib/postgresql/15/bin/pg_config

COPY . .
RUN cargo pgrx package --pg-config /usr/lib/postgresql/15/bin/pg_config

The error is:

...
  Installing extension
     Copying control file to target/release/pg_graphql-pg15/usr/share/postgresql/15/extension/pg_graphql.control
     Copying shared library to target/release/pg_graphql-pg15/usr/lib/postgresql/15/lib/pg_graphql.so
 Discovering SQL entities
Error:
   0: couldn't read postmaster
   1: No such file or directory (os error 2)

Location:
   /root/.cargo/registry/src/index.crates.io-6f17d22bba15001f/cargo-pgrx-0.10.2/src/command/schema.rs:484

  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ SPANTRACE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

   0: cargo_pgrx::command::schema::create_stub with postmaster_path=/usr/lib/postgresql/15/bin/postgres postmaster_stub_dir=/root/.pgrx/postmaster_stubs/usr/lib/postgresql/15/bin
      at /root/.cargo/registry/src/index.crates.io-6f17d22bba15001f/cargo-pgrx-0.10.2/src/command/schema.rs:463
   1: cargo_pgrx::command::schema::generate_schema with pg_version=15.4 profile=Release test=false path=/root/workspace/target/debian_build/debian/postgresql-15-pgxman-pg-graphsql-src/target/release/pg_graphql-pg15/usr/share/postgresql/15/extension/pg_graphql--1.4.0.sql features=["pg15"]
      at /root/.cargo/registry/src/index.crates.io-6f17d22bba15001f/cargo-pgrx-0.10.2/src/command/schema.rs:175
   2: cargo_pgrx::command::install::install_extension with pg_version=15.4 profile=Release test=false features=["pg15"]
      at /root/.cargo/registry/src/index.crates.io-6f17d22bba15001f/cargo-pgrx-0.10.2/src/command/install.rs:102
   3: cargo_pgrx::command::package::package_extension with pg_version=15.4 profile=Release test=false
      at /root/.cargo/registry/src/index.crates.io-6f17d22bba15001f/cargo-pgrx-0.10.2/src/command/package.rs:98
   4: cargo_pgrx::command::package::execute
      at /root/.cargo/registry/src/index.crates.io-6f17d22bba15001f/cargo-pgrx-0.10.2/src/command/package.rs:51

Backtrace omitted. Run with RUST_BACKTRACE=1 environment variable to display it.
Run with RUST_BACKTRACE=full to include source snippets.

This is some additional info:

$ /usr/lib/postgresql/15/bin/pg_config
BINDIR = /usr/lib/postgresql/15/bin
DOCDIR = /usr/share/doc/postgresql-doc-15
HTMLDIR = /usr/share/doc/postgresql-doc-15
INCLUDEDIR = /usr/include/postgresql
PKGINCLUDEDIR = /usr/include/postgresql
INCLUDEDIR-SERVER = /usr/include/postgresql/15/server
LIBDIR = /usr/lib/aarch64-linux-gnu
PKGLIBDIR = /usr/lib/postgresql/15/lib
LOCALEDIR = /usr/share/locale
MANDIR = /usr/share/postgresql/15/man
SHAREDIR = /usr/share/postgresql/15
SYSCONFDIR = /etc/postgresql-common
PGXS = /usr/lib/postgresql/15/lib/pgxs/src/makefiles/pgxs.mk
CONFIGURE =  '--build=aarch64-linux-gnu' '--prefix=/usr' '--includedir=${prefix}/include' '--mandir=${prefix}/share/man' '--infodir=${prefix}/share/info' '--sysconfdir=/etc' '--localstatedir=/var' '--disable-option-checking' '--disable-silent-rules' '--libdir=${prefix}/lib/aarch64-linux-gnu' '--runstatedir=/run' '--disable-maintainer-mode' '--disable-dependency-tracking' '--with-tcl' '--with-perl' '--with-python' '--with-pam' '--with-openssl' '--with-libxml' '--with-libxslt' '--mandir=/usr/share/postgresql/15/man' '--docdir=/usr/share/doc/postgresql-doc-15' '--sysconfdir=/etc/postgresql-common' '--datarootdir=/usr/share/' '--datadir=/usr/share/postgresql/15' '--bindir=/usr/lib/postgresql/15/bin' '--libdir=/usr/lib/aarch64-linux-gnu/' '--libexecdir=/usr/lib/postgresql/' '--includedir=/usr/include/postgresql/' '--with-extra-version= (Ubuntu 15.4-2.pgdg22.04+1)' '--enable-nls' '--enable-thread-safety' '--enable-debug' '--enable-dtrace' '--disable-rpath' '--with-uuid=e2fs' '--with-gnu-ld' '--with-gssapi' '--with-ldap' '--with-pgport=5432' '--with-system-tzdata=/usr/share/zoneinfo' 'AWK=mawk' 'MKDIR_P=/bin/mkdir -p' 'PROVE=/usr/bin/prove' 'PYTHON=/usr/bin/python3' 'TAR=/bin/tar' 'XSLTPROC=xsltproc --nonet' 'CFLAGS=-g -O2 -flto=auto -ffat-lto-objects -flto=auto -ffat-lto-objects -fstack-protector-strong -Wformat -Werror=format-security' 'LDFLAGS=-Wl,-Bsymbolic-functions -flto=auto -ffat-lto-objects -flto=auto -Wl,-z,relro -Wl,-z,now' '--enable-tap-tests' '--with-icu' '--with-llvm' 'LLVM_CONFIG=/usr/bin/llvm-config-14' 'CLANG=/usr/bin/clang-14' '--with-lz4' '--with-zstd' '--with-systemd' '--with-selinux' 'build_alias=aarch64-linux-gnu' 'CPPFLAGS=-Wdate-time -D_FORTIFY_SOURCE=2' 'CXXFLAGS=-g -O2 -flto=auto -ffat-lto-objects -flto=auto -ffat-lto-objects -fstack-protector-strong -Wformat -Werror=format-security'
CC = gcc
CPPFLAGS = -Wdate-time -D_FORTIFY_SOURCE=2 -D_GNU_SOURCE -I/usr/include/libxml2
CFLAGS = -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wimplicit-fallthrough=3 -Wcast-function-type -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -Wno-format-truncation -Wno-stringop-truncation -moutline-atomics -g -g -O2 -flto=auto -ffat-lto-objects -flto=auto -ffat-lto-objects -fstack-protector-strong -Wformat -Werror=format-security
CFLAGS_SL = -fPIC
LDFLAGS = -Wl,-Bsymbolic-functions -flto=auto -ffat-lto-objects -flto=auto -Wl,-z,relro -Wl,-z,now -L/usr/lib/llvm-14/lib -Wl,--as-needed
LDFLAGS_EX =
LDFLAGS_SL =
LIBS = -lpgcommon -lpgport -lselinux -lzstd -llz4 -lxslt -lxml2 -lpam -lssl -lcrypto -lgssapi_krb5 -lz -lreadline -lm
VERSION = PostgreSQL 15.4 (Ubuntu 15.4-2.pgdg22.04+1)
$ rustup --version && \
  rustc --version && \
  cargo --version
rustup 1.26.0 (5af9b9484 2023-04-05)
info: This is the version for the rustup toolchain manager, not the rustc compiler.
info: The currently active `rustc` version is `rustc 1.73.0 (cc66ad468 2023-10-03)`
rustc 1.73.0 (cc66ad468 2023-10-03)
cargo 1.73.0 (9c4383fb5 2023-08-26)

Ref: https://github.com/supabase/pg_graphql/issues/430

owenthereal commented 1 year ago

This is related to https://github.com/supabase/pg_graphql/issues/430#issuecomment-1754272744.

eeeebbbbrrrr commented 1 year ago

This is related to how we dynamically generate symbols exported by the postmaster during schema generation.

The postmaster executable is required. Maybe we need to document that somewhere.

eeeebbbbrrrr commented 1 year ago

Oh. I see you closed this already. I guess you discovered that the postmaster binary is required?

owenthereal commented 1 year ago

Maybe we need to document that somewhere.

Yup, that would be nice. What happened was that the postgresql-server-dev-all debian package doesn't include the postgres binary: postgresql-all is needed to use with pgrx.

stella3d commented 8 months ago

I don't suppose anyone knows how to fix this exact same error on macOS? i've tried installing various things via brew such as postgresql & libpq, but no luck