class PostgresqlAT14 < Formula desc "Object-relational database system" homepage "https://www.postgresql.org/" url "https://ftp.postgresql.org/pub/source/v14.5/postgresql-14.5.tar.bz2" sha256 "d4f72cb5fb857c9a9f75ec8cf091a1771272802f2178f0b2e65b7b6ff64f4a30" license "PostgreSQL" revision 4 livecheck do url "https://ftp.postgresql.org/pub/source/" regex(%r{href=["']?v?(14+(?:\.\d+)+)/?["' >]}i) end bottle do sha256 arm64_monterey: "f9ea0997791362d3fee0114c1c6a366f4ccefcd3e99ab28704a607a1c6cc5702" sha256 arm64_big_sur: "391a76997501936d5ffca50922c44cb03ace3a6162c535632305654b251b7c44" sha256 monterey: "69bbcbe31ff4371615f20d2ffd323183a1c552092ef9dd74110dca0341e2b9ac" sha256 big_sur: "45cdb37e2824d2e6139e6b2126d37e4e574d1bb3079c839b787acba743cc122a" sha256 catalina: "7ae0a0b65d13cca805119d896e0d158d00b5e240ba30cc4388b5e1b96e9c1bd8" sha256 x86_64_linux: "beb7fa3979b810efcec5d1d305898c4c25ba87139af7fdbe99f0e6181c3d8328" end # https://www.postgresql.org/support/versioning/ deprecate! date: "2026-11-12", because: :unsupported depends_on "pkg-config" => :build depends_on "icu4c" # GSSAPI provided by Kerberos.framework crashes when forked. # See https://github.com/Homebrew/homebrew-core/issues/47494. depends_on "krb5" depends_on "lz4" depends_on "openssl@1.1" depends_on "readline" uses_from_macos "libxml2" uses_from_macos "libxslt" uses_from_macos "openldap" uses_from_macos "perl" on_linux do depends_on "linux-pam" depends_on "util-linux" end def install ENV.prepend "LDFLAGS", "-L#{Formula["openssl@1.1"].opt_lib} -L#{Formula["readline"].opt_lib}" ENV.prepend "CPPFLAGS", "-I#{Formula["openssl@1.1"].opt_include} -I#{Formula["readline"].opt_include}" args = %W[ --disable-debug --prefix=#{prefix} --datadir=#{HOMEBREW_PREFIX}/share/#{name} --libdir=#{HOMEBREW_PREFIX}/lib/#{name} --includedir=#{HOMEBREW_PREFIX}/include/#{name} --enable-thread-safety --with-gssapi --with-icu --with-ldap --with-libxml --with-libxslt --with-lz4 --with-openssl --with-pam --with-perl --with-uuid=e2fs --with-extra-version=\ (#{tap.user}) ] if OS.mac? args += %w[ --with-bonjour --with-tcl ] end # PostgreSQL by default uses xcodebuild internally to determine this, # which does not work on CLT-only installs. args << "PG_SYSROOT=#{MacOS.sdk_path}" if MacOS.sdk_root_needed? system "./configure", *args system "make" system "make", "install-world", "datadir=#{pkgshare}", "libdir=#{lib}/#{name}", "pkglibdir=#{lib}/#{name}", "includedir=#{include}/#{name}", "pkgincludedir=#{include}/#{name}", "includedir_server=#{include}/#{name}/server", "includedir_internal=#{include}/#{name}/internal" if OS.linux? inreplace lib/name/"pgxs/src/Makefile.global", "LD = #{HOMEBREW_PREFIX}/Homebrew/Library/Homebrew/shims/linux/super/ld", "LD = #{HOMEBREW_PREFIX}/bin/ld" end end def post_install (var/"log").mkpath postgresql_datadir.mkpath # Don't initialize database, it clashes when testing other PostgreSQL versions. return if ENV["HOMEBREW_GITHUB_ACTIONS"] system "#{bin}/initdb", "--locale=C", "-E", "UTF-8", postgresql_datadir unless pg_version_exists? end def postgresql_datadir if old_postgres_data_dir.exist? old_postgres_data_dir else var/name end end def postgresql_log_path var/"log/#{name}.log" end def pg_version_exists? (postgresql_datadir/"PG_VERSION").exist? end def old_postgres_data_dir var/"postgres" end # Figure out what version of PostgreSQL the old data dir is # using def old_postgresql_datadir_version pg_version = old_postgres_data_dir/"PG_VERSION" pg_version.exist? && pg_version.read.chomp end def caveats caveats = "" # Extract the version from the formula name pg_formula_version = version.major.to_s # ... and check it against the old data dir postgres version number # to see if we need to print a warning re: data dir if old_postgresql_datadir_version == pg_formula_version caveats += <<~EOS Previous versions of postgresql shared the same data directory. You can migrate to a versioned data directory by running: mv -v "#{old_postgres_data_dir}" "#{var/name}" (Make sure PostgreSQL is stopped before executing this command) EOS end caveats += <<~EOS This formula has created a default database cluster with: initdb --locale=C -E UTF-8 #{postgresql_datadir} For more details, read: https://www.postgresql.org/docs/#{version.major}/app-initdb.html EOS caveats end service do run [opt_bin/"postgres", "-D", f.postgresql_datadir] keep_alive true log_path f.postgresql_log_path error_log_path f.postgresql_log_path working_dir HOMEBREW_PREFIX end test do system bin/"initdb", testpath/"test" unless ENV["HOMEBREW_GITHUB_ACTIONS"] assert_equal "#{HOMEBREW_PREFIX}/share/#{name}", shell_output("#{bin}/pg_config --sharedir").chomp assert_equal "#{HOMEBREW_PREFIX}/lib/#{name}", shell_output("#{bin}/pg_config --libdir").chomp assert_equal "#{HOMEBREW_PREFIX}/lib/#{name}", shell_output("#{bin}/pg_config --pkglibdir").chomp assert_equal "#{HOMEBREW_PREFIX}/include/#{name}", shell_output("#{bin}/pg_config --includedir").chomp end end