postgresql_16:4.2.7.3 macOS
PostgreSQL 16 > Server Administration > Installation from Source Code > Platform-Specific Notes > macOS
To build PostgreSQL from source on macOS, you will need to install Apple's command line developer tools, which can be done by issuing xcode-select --install (note that this will pop up a GUI dialog window for confirmation). You may or may not wish to also install Xcode.
On recent macOS releases, it's necessary to embed the “sysroot” path in the include switches used to find some system header files. This results in the outputs of the configure script varying depending on which SDK version was used during configure. That shouldn't pose any problem in simple scenarios, but if you are trying to do something like building an extension on a different machine than the server code was built on, you may need to force use of a different sysroot path. To do that, set PG_SYSROOT, for example make PG_SYSROOT=*/desired/path* all To find out the appropriate path on your machine, run xcrun --show-sdk-path Note that building an extension using a different sysroot version than was used to build the core server is not really recommended; in the worst case it could result in hard-to-debug ABI inconsistencies.
You can also select a non-default sysroot path when configuring, by specifying PG_SYSROOT to configure: ./configure ... PG_SYSROOT=*/desired/path* This would primarily be useful to cross-compile for some other macOS version. There is no guarantee that the resulting executables will run on the current host.
To suppress the -isysroot options altogether, use ./configure ... PG_SYSROOT=none (any nonexistent pathname will work). This might be useful if you wish to build with a non-Apple compiler, but beware that that case is not tested or supported by the PostgreSQL developers.
macOS's “System Integrity Protection” (SIP) feature breaks make check, because it prevents passing the needed setting of DYLD_LIBRARY_PATH down to the executables being tested. You can work around that by doing make install before make check. Most PostgreSQL developers just turn off SIP, though.