====== PostgreSQL & PostGIS ====== Installing/upgrading to [[https://www.postgresql.org|PostgreSQL]] version 12.x and [[http://postgis.net|PostGIS]] version 3.0.1 on MacOS > High Sierra (10.13.x and higher). This note is in draft stage and currently just a dump of snippets The reason for a manual installation is that I want to utilise the GDAL framework utilised by QGIS and GMT. This setup naturally collides with Homebrew's setup to install GDAL as part of the dependency framework when installing postgis. I also use the [[https://www.python.org|Python.org's Python Frameworks]]. ===== Preparation ===== So I am leaving the dependencies to [[http://brew.sh|homebrew]] apart from GDAL (where I still use [[http://www.kyngchaos.com/software/frameworks/|William Kyngesbury's formidable GDAL Framework]] - at v 2.4.1 at time of writing) and [[https://python.org|Python.org's Python framework]] distribution - v.3.8. ===== Compiling PostgreSQL ===== The documentation to compile from source is available [[https://www.postgresql.org/docs/11/install-requirements.html|on the Postgresql.org website]]. Here are the individual commands I use to compile/check: ./configure PYTHON=/Library/Frameworks/Python.framework/Versions/3.x/bin/python3 \\ --with-perl --with-uuid=e2fs --with-python --with-libxml --with-readline --prefix=/usr/local/pgsql/12.2 --with-libraries=/usr/local/Cellar/readline/x.x.x/ make -j24 make check make docs sudo make install -j24 The hint with specifying the Python distribution on the ''./configure'' call is from [[https://www.postgresql.org/message-id/CY1PR03MB21875AB9B40FC9E03899AF5B9CD40%40CY1PR03MB2187.namprd03.prod.outlook.com|the PostgreSQL mailing list]]. Once the configure script has completed successfully I run: After an upgrade of the OS it seems that the LaunchDaemon is broken. The issues I encounter are related to file permissions for the log file. In this case the user ''_postgresql'' does not have permissions to write to ''/var/log/Postgresql.log'' as only ''root'' as access here. This has likely changed between earlier Mac OS versions and Catalina (which is where the issue popped up). So there seems to be two options going forward: - have ''pgsql'' directly log to the ''syslog'' - use conventional ''stdout'' and ''stderr'' as log output directions, but change the logfile location and permissions. On first sight is look as if option 1 is more elegant, but there is very little information as to how this should be set up and I have very little experience with ''syslog''. Here's a few links to get started: * ''man asl.conf'' - manpage for Apple's system log tool * [[https://nozaki.me/roller/kyle/entry/articles-postgres-log|Kohei Nozaki's blog entry]] on Postgresql using ''syslog'' * [[https://superuser.com/questions/278231/how-to-disable-set-logging-level-preferences-per-mac-os-x-application| SO: log level prefs per OS X application]] * [[https://superuser.com/questions/932013/asl-conf-doesnt-take-an-effect-on-my-enviroment-os-x-yosemite]] * [[https://apple.stackexchange.com/questions/6559/setting-a-custom-log]] * [[https://www.loggly.com/ultimate-guide/linux-logging-basics/|Linux logging basics]] * [[https://apple.stackexchange.com/questions/338213/how-to-run-a-launchagent-that-runs-a-script-which-causes-failures-because-of-sys]] * [[https://apple.stackexchange.com/questions/387592/how-to-use-launchd]] * [[https://www.linuxwave.info/2018/12/send-postgresql-log-to-syslog.html|Getting postgresql write to syslog]] * [[https://apple.stackexchange.com/questions/195997/running-postgres-as-launch-daemon]] * [[https://developer.apple.com/documentation/os/logging]] * [[https://apple.stackexchange.com/questions/357179/unified-logs-macos-high-sierra?rq=1]] * [[https://apple.stackexchange.com/questions/162487/how-can-one-start-a-process-and-monitor-its-syslog-messages?rq=1]] * [[https://apple.stackexchange.com/questions/390986/can-i-have-launchctl-output-stdout-stderr-from-my-application-to-the-system-wide?rq=1]] * [[https://ilostmynotes.blogspot.com/2011/11/os-x-logging-aslconf-syslogconf-and.html]] * [[https://www.unixtutorial.org/syslog-and-asl-in-macos/]] * [[https://www.launchd.info]] * [[https://superuser.com/questions/943983/os-x-launchdaemon-not-running-service-could-not-initialize]] * [[https://stackoverflow.com/questions/27700596/homebrew-postgres-broken]] * [https://apple.stackexchange.com/questions/322078/what-are-all-the-available-acl-attributes-in-mac-os-10-13-high-sierra]] * [[https://unix.stackexchange.com/questions/479890/permission-to-write-to-log]] * [[https://stackoverflow.com/questions/32160108/os-x-launchd-script-fails-to-run-at-startup?rq=1]] * ==== Setting up the LaunchDaemon ==== On their [[http://opensource.apple.com|OpenSource pages]] Apple provides a template for one of the [[https://opensource.apple.com/source/PostgreSQL/PostgreSQL-23/|older included PostgreSQL versions (here: 9.0.4)]]. This deviates a bit from what I used previously for the LaunchDaemon file. [[https://developer.apple.com/library/archive/documentation/MacOSX/Conceptual/BPSystemStartup/Chapters/CreatingLaunchdJobs.html| Verbatim copy of [[https://opensource.apple.com/source/PostgreSQL/PostgreSQL-23/org.postgresql.postgres.plist.auto.html|of Apple's org.postgresql.postgres.plist on their opensource site]]: Disabled Label org.postgresql.postgres UserName _postgres GroupName _postgres ProgramArguments /usr/bin/postgres -D /var/pgsql -c unix_socket_directory=/var/pgsql_socket -c logging_collector=on -c log_connections=on -c log_lock_waits=on -c log_statement=ddl -c log_line_prefix=%t -c listen_addresses= -c log_directory=/Library/Logs -c log_filename=PostgreSQL.log -c unix_socket_group=_postgres -c unix_socket_permissions=0770 OnDemand Homebrew's distro uses a slightly different version - here's the excerpt from the [[https://github.com/Homebrew/homebrew-core/blob/master/Formula/postgresql@11.rb|postgresql.rb]] file: def plist; <<~EOS KeepAlive Label #{plist_name} ProgramArguments #{opt_bin}/postgres -D #{var}/#{name} RunAtLoad WorkingDirectory #{HOMEBREW_PREFIX} StandardOutPath #{var}/log/#{name}.log StandardErrorPath #{var}/log/#{name}.log EOS end ==== Starting the new PostgreSQL service ==== Once the ===== PostGIS ===== ./configure --prefix=/usr/local/pgsql/x.x/ --with-projdir=/Library/Frameworks/PROJ.framework/unix/ --with-raster --with-topology --with-pgconfig=/usr/local/pgsql/x.x/bin/pg_config --with-geosconfig=/Library/Frameworks/GEOS.framework/unix/bin/geos-config {{tag>GIS Database MacOS PostGIS PostgreSQL compilation software}}