PageRenderTime 26ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 0ms

/Library/Formula/postgres-xc.rb

https://github.com/bakotaco/homebrew
Ruby | 304 lines | 265 code | 30 blank | 9 comment | 8 complexity | 56753b059e0e64e96bce8c0767a00b6a MD5 | raw file
  1. require 'formula'
  2. class PostgresXc < Formula
  3. homepage 'http://postgres-xc.sourceforge.net/'
  4. url 'https://downloads.sourceforge.net/project/postgres-xc/Version_1.0/pgxc-v1.0.3.tar.gz'
  5. sha1 '76774cf32810dfa14b2174f2e939d3b28eb211a9'
  6. depends_on :arch => :x86_64
  7. depends_on :python => :recommended
  8. depends_on 'readline'
  9. depends_on 'libxml2' if MacOS.version <= :leopard # Leopard libxml is too old
  10. depends_on 'ossp-uuid' => :recommended
  11. conflicts_with 'postgresql',
  12. :because => 'postgres-xc and postgresql install the same binaries.'
  13. option 'no-perl', 'Build without Perl support'
  14. option 'enable-dtrace', 'Build with DTrace support'
  15. fails_with :clang do
  16. build 211
  17. cause 'Miscompilation resulting in segfault on queries'
  18. end
  19. # Fix PL/Python build: https://github.com/Homebrew/homebrew/issues/11162
  20. # Fix uuid-ossp build issues: http://archives.postgresql.org/pgsql-general/2012-07/msg00654.php
  21. patch :DATA
  22. def install
  23. ENV.libxml2 if MacOS.version >= :snow_leopard
  24. # See http://sourceforge.net/mailarchive/forum.php?thread_name=82E44F89-543A-44F2-8AF8-F6909B5DC561%40uniud.it&forum_name=postgres-xc-bugs
  25. ENV.append 'CFLAGS', '-D_FORTIFY_SOURCE=0 -O2' if MacOS.version >= :mavericks
  26. args = ["--disable-debug",
  27. "--prefix=#{prefix}",
  28. "--datadir=#{share}/#{name}",
  29. "--docdir=#{doc}",
  30. "--enable-thread-safety",
  31. "--with-bonjour",
  32. "--with-gssapi",
  33. "--with-krb5",
  34. "--with-openssl",
  35. "--with-libxml",
  36. "--with-libxslt"]
  37. args << "--with-ossp-uuid" if build.with? 'ossp-uuid'
  38. args << "--with-python" if build.with? 'python'
  39. args << "--with-perl" unless build.include? 'no-perl'
  40. args << "--enable-dtrace" if build.include? 'enable-dtrace'
  41. args << "ARCHFLAGS='-arch x86_64'"
  42. if build.with? 'ossp-uuid'
  43. ENV.append 'CFLAGS', `uuid-config --cflags`.strip
  44. ENV.append 'LDFLAGS', `uuid-config --ldflags`.strip
  45. ENV.append 'LIBS', `uuid-config --libs`.strip
  46. end
  47. check_python_arch if build.with? 'python'
  48. system "./configure", *args
  49. system "make install-world"
  50. plist_path('gtm').write gtm_startup_plist('gtm')
  51. plist_path('gtm').chmod 0644
  52. plist_path('gtm_proxy').write gtm_proxy_startup_plist('gtm_proxy')
  53. plist_path('gtm_proxy').chmod 0644
  54. plist_path('coord').write coordinator_startup_plist('coord')
  55. plist_path('coord').chmod 0644
  56. plist_path('datanode').write datanode_startup_plist('datanode')
  57. plist_path('datanode').chmod 0644
  58. mkpath var+'postgres-xc' # Create data directory
  59. end
  60. def check_python_arch
  61. # On 64-bit systems, we need to look for a 32-bit Framework Python.
  62. # The configure script prefers this Python version, and if it doesn't
  63. # have 64-bit support then linking will fail.
  64. framework_python = Pathname.new "/Library/Frameworks/Python.framework/Versions/Current/Python"
  65. return unless framework_python.exist?
  66. unless (archs_for_command framework_python).include? :x86_64
  67. opoo "Detected a framework Python that does not have 64-bit support in:"
  68. puts <<-EOS.undent
  69. #{framework_python}
  70. The configure script seems to prefer this version of Python over any others,
  71. so you may experience linker problems as described in:
  72. http://osdir.com/ml/pgsql-general/2009-09/msg00160.html
  73. To fix this issue, you may need to either delete the version of Python
  74. shown above, or move it out of the way before brewing PostgreSQL.
  75. Note that a framework Python in /Library/Frameworks/Python.framework is
  76. the "MacPython" version, and not the system-provided version which is in:
  77. /System/Library/Frameworks/Python.framework
  78. EOS
  79. end
  80. end
  81. def caveats; <<-EOS.undent
  82. To get started with Postgres-XC, read the documents at
  83. http://sourceforge.net/projects/postgres-xc/files/Publication/
  84. http://postgres-xc.sourceforge.net/docs/1_0/tutorial-start.html
  85. For a first cluster, you may start with a single GTM (Global Transaction Manager),
  86. a pair of Data Nodes and a single Coordinator, all on the same machine:
  87. initgtm -Z gtm -D #{var}/postgres-xc/gtm
  88. initdb -D #{var}/postgres-xc/datanode1 --nodename datanode1
  89. initdb -D #{var}/postgres-xc/datanode2 --nodename datanode2
  90. initdb -D #{var}/postgres-xc/coord --nodename coord
  91. Then edit:
  92. #{var}/postgres-xc/datanode1/postgresql.conf
  93. #{var}/postgres-xc/datanode2/postgresql.conf
  94. and change the port to 15432 and 15433, respectively.
  95. Then, launch the nodes and connect to the coordinator:
  96. gtm -D #{var}/postgres-xc/gtm -l #{var}/postgres-xc/gtm/server.log &
  97. postgres -i -X -D #{var}/postgres-xc/datanode1 -r #{var}/postgres-xc/datanode1/server.log &
  98. postgres -i -X -D #{var}/postgres-xc/datanode2 -r #{var}/postgres-xc/datanode2/server.log &
  99. postgres -i -C -D #{var}/postgres-xc/coord -r #{var}/postgres-xc/coord/server.log &
  100. psql postgres
  101. create node datanode1 with (type='datanode', port=15432);
  102. create node datanode2 with (type='datanode', port=15433);
  103. select * from pgxc_node;
  104. select pgxc_pool_reload();
  105. To shutdown everything, kill the processes in reverse order:
  106. kill -SIGTERM `head -1 #{var}/postgres-xc/coord/postmaster.pid`
  107. kill -SIGTERM `head -1 #{var}/postgres-xc/datanode1/postmaster.pid`
  108. kill -SIGTERM `head -1 #{var}/postgres-xc/datanode2/postmaster.pid`
  109. kill -SIGTERM `head -1 #{var}/postgres-xc/gtm/gtm.pid`
  110. If you get the following error:
  111. FATAL: could not create shared memory segment: Cannot allocate memory
  112. then you need to tweak your system's shared memory parameters:
  113. http://www.postgresql.org/docs/current/static/kernel-resources.html#SYSVIPC
  114. EOS
  115. end
  116. # Override Formula#plist_name
  117. def plist_name(extra = nil)
  118. (extra) ? super()+'-'+extra : super()+'-gtm'
  119. end
  120. # Override Formula#plist_path
  121. def plist_path(extra = nil)
  122. (extra) ? super().dirname+(plist_name(extra)+'.plist') : super()
  123. end
  124. def gtm_startup_plist(name); <<-EOPLIST.undent
  125. <?xml version="1.0" encoding="UTF-8"?>
  126. <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
  127. <plist version="1.0">
  128. <dict>
  129. <key>KeepAlive</key>
  130. <true/>
  131. <key>Label</key>
  132. <string>#{plist_name(name)}</string>
  133. <key>ProgramArguments</key>
  134. <array>
  135. <string>#{opt_bin}/gtm</string>
  136. <string>-D</string>
  137. <string>#{var}/postgres-xc/#{name}</string>
  138. <string>-l</string>
  139. <string>#{var}/postgres-xc/#{name}/server.log</string>
  140. </array>
  141. <key>RunAtLoad</key>
  142. <true/>
  143. <key>WorkingDirectory</key>
  144. <string>#{HOMEBREW_PREFIX}</string>
  145. <key>StandardErrorPath</key>
  146. <string>#{var}/postgres-xc/#{name}/server.log</string>
  147. </dict>
  148. </plist>
  149. EOPLIST
  150. end
  151. def gtm_proxy_startup_plist(name); <<-EOPLIST.undent
  152. <?xml version="1.0" encoding="UTF-8"?>
  153. <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
  154. <plist version="1.0">
  155. <dict>
  156. <key>KeepAlive</key>
  157. <true/>
  158. <key>Label</key>
  159. <string>#{plist_name(name)}</string>
  160. <key>ProgramArguments</key>
  161. <array>
  162. <string>#{opt_bin}/gtm_proxy</string>
  163. <string>-D</string>
  164. <string>#{var}/postgres-xc/#{name}</string>
  165. <string>-n</string>
  166. <string>2</string>
  167. <string>-s</string>
  168. <string>localhost</string>
  169. <string>-t</string>
  170. <string>6666</string>
  171. <string>-l</string>
  172. <string>#{var}/postgres-xc/#{name}/server.log</string>
  173. </array>
  174. <key>RunAtLoad</key>
  175. <true/>
  176. <key>WorkingDirectory</key>
  177. <string>#{HOMEBREW_PREFIX}</string>
  178. <key>StandardErrorPath</key>
  179. <string>#{var}/postgres-xc/#{name}/server.log</string>
  180. </dict>
  181. </plist>
  182. EOPLIST
  183. end
  184. def coordinator_startup_plist(name); <<-EOPLIST.undent
  185. <?xml version="1.0" encoding="UTF-8"?>
  186. <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
  187. <plist version="1.0">
  188. <dict>
  189. <key>KeepAlive</key>
  190. <true/>
  191. <key>Label</key>
  192. <string>#{plist_name(name)}</string>
  193. <key>ProgramArguments</key>
  194. <array>
  195. <string>#{opt_bin}/postgres</string>
  196. <string>-i</string>
  197. <string>-C</string>
  198. <string>-D</string>
  199. <string>#{var}/postgres-xc/#{name}</string>
  200. <string>-r</string>
  201. <string>#{var}/postgres-xc/#{name}/server.log</string>
  202. </array>
  203. <key>RunAtLoad</key>
  204. <true/>
  205. <key>WorkingDirectory</key>
  206. <string>#{HOMEBREW_PREFIX}</string>
  207. <key>StandardErrorPath</key>
  208. <string>#{var}/postgres-xc/#{name}/server.log</string>
  209. </dict>
  210. </plist>
  211. EOPLIST
  212. end
  213. def datanode_startup_plist(name); <<-EOPLIST.undent
  214. <?xml version="1.0" encoding="UTF-8"?>
  215. <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
  216. <plist version="1.0">
  217. <dict>
  218. <key>KeepAlive</key>
  219. <true/>
  220. <key>Label</key>
  221. <string>#{plist_name(name)}</string>
  222. <key>ProgramArguments</key>
  223. <array>
  224. <string>#{opt_bin}/postgres</string>
  225. <string>-i</string>
  226. <string>-X</string>
  227. <string>-D</string>
  228. <string>#{var}/postgres-xc/#{name}</string>
  229. <string>-r</string>
  230. <string>#{var}/postgres-xc/#{name}/server.log</string>
  231. </array>
  232. <key>RunAtLoad</key>
  233. <true/>
  234. <key>WorkingDirectory</key>
  235. <string>#{HOMEBREW_PREFIX}</string>
  236. <key>StandardErrorPath</key>
  237. <string>#{var}/postgres-xc/#{name}/server.log</string>
  238. </dict>
  239. </plist>
  240. EOPLIST
  241. end
  242. end
  243. __END__
  244. --- a/src/pl/plpython/Makefile 2011-09-23 08:03:52.000000000 +1000
  245. +++ b/src/pl/plpython/Makefile 2011-10-26 21:43:40.000000000 +1100
  246. @@ -24,8 +24,6 @@
  247. # Darwin (OS X) has its own ideas about how to do this.
  248. ifeq ($(PORTNAME), darwin)
  249. shared_libpython = yes
  250. -override python_libspec = -framework Python
  251. -override python_additional_libs =
  252. endif
  253. # If we don't have a shared library and the platform doesn't allow it
  254. --- a/contrib/uuid-ossp/uuid-ossp.c 2012-07-30 18:34:53.000000000 -0700
  255. +++ b/contrib/uuid-ossp/uuid-ossp.c 2012-07-30 18:35:03.000000000 -0700
  256. @@ -9,6 +9,8 @@
  257. *-------------------------------------------------------------------------
  258. */
  259. +#define _XOPEN_SOURCE
  260. +
  261. #include "postgres.h"
  262. #include "fmgr.h"
  263. #include "utils/builtins.h"