Hi hackers,

While trying to build PostgreSQL from source (master branch, 95c3a195) on a
MacBook I discovered that `make check` fails:

```
============== removing existing temp instance ==============
============== creating temporary instance ==============
============== initializing database system ==============
============== starting postmaster ==============
sh: line 1: 33559 Abort trap: 6           "psql" -X postgres < /dev/null 2>
/dev/null
sh: line 1: 33562 Abort trap: 6           "psql" -X postgres < /dev/null 2>
/dev/null
...
sh: line 1: 33742 Abort trap: 6           "psql" -X postgres < /dev/null 2>
/dev/null

pg_regress: postmaster did not respond within 60 seconds
Examine
/Users/eax/projects/c/postgresql/src/test/regress/log/postmaster.log for
the reason
make[1]: *** [check] Error 2
make: *** [check] Error 2
```

A little investigation revealed that pg_regres executes postgres like this:

```
PATH="/Users/eax/projects/c/postgresql/tmp_install/Users/eax/pginstall/bin:$PATH"
DYLD_LIBRARY_PATH="/Users/eax/projects/c/postgresql/tmp_install/Users/eax/pginstall/lib"
"postgres" -D
"/Users/eax/projects/c/postgresql/src/test/regress/./tmp_check/data" -F -c
"listen_addresses=" -k "/Users/eax/pgtmp/pg_regress-S34sXM" >
"/Users/eax/projects/c/postgresql/src/test/regress/log/postmaster.log"
```

... and checks that it's online by executing:

```
PATH="/Users/eax/projects/c/postgresql/tmp_install/Users/eax/pginstall/bin:$PATH"
DYLD_LIBRARY_PATH="/Users/eax/projects/c/postgresql/tmp_install/Users/eax/pginstall/lib"
psql -X postgres
```

The last command fails with:

```
psql: error: connection to server on socket "/tmp/.s.PGSQL.5432" failed: No
such file or directory. Is the server running locally and accepting
connections on that socket?
```

This is because the actual path to the socket is:

```
~/pgtmp/pg_regress-S34sXM/.s.PGSQL.5432
```

While debugging this I also discovered that psql uses
/usr/lib/libpq.5.dylib library, according to the `image list` command in
LLDB. The library is provided with the system and can't be moved or
deleted. In other words, it seems to ignore DYLD_LIBRARY_PATH. I've found
an instruction [1] that suggests that this is a behavior of MacOS integrity
protection and describes how it can be disabled. Sadly it made no
difference in my case, psql still ignores DYLD_LIBRARY_PATH.

While I'm still in the progress of investigating this I just wanted to ask
if anyone is developing on MacOS and observes anything similar and had any
luck solving the problem? I tried to search through the mailing list but
didn't find anything relevant. The complete script that reproduces the
issue is attached. I'm using the same script on Ubuntu VM, where it works
just fine.

[1]: https://github.com/rbenv/rbenv/issues/962#issuecomment-275858404

-- 
Best regards,
Aleksander Alekseev
#!/usr/bin/env bash

set -e

if [[ -z $PGINSTALL ]]; then
  echo "ERROR: \$PGINSTALL environment variable is empty"
  exit 1
fi

make distclean || true

export PYTHON=/usr/bin/python

CFLAGS="-O0" ./configure --prefix=$PGINSTALL \
    --with-python --enable-tap-tests --enable-cassert --enable-debug \
    --with-perl --with-tcl

# This works but generates a lot of warnings on MacOS:
# --with-gssapi --with-ldap

echo '-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-'

make -s -j4

echo '-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-'

make check

Reply via email to