Just for reference in case anyone else who utilizes static linking for any reason hits upon this issue, here is a working Dockerfile for libpq / postgresql 17
COPY <<EOF ./main.cpp #include<libpq-fe.h> int main(){return PQconnectdb("")==NULL;} EOF
ARG KRB5=1.21.3 ARG KRB5MAJMIN=1.21 RUN curl -L https://kerberos.org/dist/krb5/$KRB5MAJMIN/krb5-$KRB5.tar.gz | tar xzf - RUN cd krb5-$KRB5/src && \ ./configure && make && make install && \ ./configure --disable-shared --enable-static && make && make install
ARG SASL=2.1.28 RUN curl -L https://github.com/cyrusimap/cyrus-sasl/releases/download/cyrus-sasl-$SASL/cyrus-sasl-$SASL.tar.gz | tar xzf - RUN cd cyrus-sasl-$SASL && ./configure --enable-static && make && make install