{"id":390,"date":"2015-12-11T09:25:48","date_gmt":"2015-12-11T09:25:48","guid":{"rendered":"http:\/\/www.reades.com\/?p=390"},"modified":"2015-12-11T09:25:48","modified_gmt":"2015-12-11T09:25:48","slug":"installing-postgresql-extensions-on-mac-os-x","status":"publish","type":"post","link":"http:\/\/www.reades.com\/wp\/?p=390","title":{"rendered":"Installing PostgreSQL Extensions on Mac OS X"},"content":{"rendered":"<p>\t\t\t\tI&#8217;ve been making a lot of use of PostgreSQL and PostGIS for working with geo-data over the past year and, having finally gotten over my hatred of the non-standard administrative commands, I am seriously impressed with what this setup makes possible. Even on a MacBook Air with just 8GB of RAM! However, one area where I&#8217;ve run into problems is the use of extensions on OS X so this post is intended as a handy reference for how to install them.<\/p>\n<p><!--more--><\/p>\n<h3>The Quantile Extension<\/h3>\n<p>One particularly useful extension is the quantile function that allows Postgres to work out arbitrary quantiles (including, of course, the median) as part of a <code>SELECT<\/code> call.<\/p>\n<p>You can get more information about the extension\u00a0from <a href=\"http:\/\/pgxn.org\/dist\/quantile\" target=\"_blank\" rel=\"noopener\">pgxn.org<\/a>.<\/p>\n<p>And, of course, there are a host of other extensions available from pgxn.\u00a0<em>Note:<\/em> you don&#8217;t need to download the extension as the extension manager\u00a0should\u00a0determine and download the right version automatically.<\/p>\n<h4>Install pgxn<\/h4>\n<p>PGXN&#8217;s client is installed via Python&#8217;s <code>easy_install<\/code> process:<\/p>\n<pre>sudo easy_install pgxnclient\n<\/pre>\n<h4>Configure Xcode<\/h4>\n<p>You will also, alas, need to have some part of Xcode installed (probably the <a href=\"http:\/\/stackoverflow.com\/questions\/32893412\/command-line-tools-not-working-os-x-el-capitan\" target=\"_blank\" rel=\"noopener\">Command Line tools<\/a>), and as far as I can tell, the set of &#8216;activities&#8217; below is only necessary because of something in Postgres that insists on a particular version of the Xcode SDK when compiling extensions.<\/p>\n<p>It is <em>possible<\/em> that you won&#8217;t need to worry about this step, but if you try to install the extension and get an error about <code>stdio.h<\/code> not being found then look closely at the Xcode error to determine exactly what you need to change in the symbolic linking command below:<\/p>\n<pre>cd \/Applications\/Xcode.app\/Contents\/Developer\/Platforms\/MacOSX.platform\/Developer\/SDKs\/\nsudo ln -s MacOSX10.9.sdk MacOSX10.6.sdk\n<\/pre>\n<p>In this case, I had 10.9 installed on my computer and the process reported that it couldn&#8217;t find the 10.6 SDK. Update the OSX version numbers as necessary.<\/p>\n<h4>Install the extension<\/h4>\n<p>And to get the extension installed:<\/p>\n<pre>sudo pgxn install quantile\npgxn load -d XXX\u00a0-U YYY\u00a0-p ZZZ\u00a0quantile\n<\/pre>\n<p>Where XXX is the database in which you want the extension available, YYY is the username, and ZZZ is the port on which postgres is running. Depending on how you&#8217;ve set things up you may not need to specify any of this.<\/p>\n<p>If all has gone well then after some compilation messages you should see some output like:<\/p>\n<pre>INFO: best version: quantile 1.1.5\nCREATE EXTENSION\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve been making a lot of use of PostgreSQL and PostGIS for working with geo-data over the past year and, having finally gotten over my hatred of the non-standard administrative commands, I am seriously impressed with what this setup makes possible. Even on a MacBook Air with just 8GB of RAM! However, one area where [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-390","post","type-post","status-publish","format-standard","hentry","category-postgis"],"_links":{"self":[{"href":"http:\/\/www.reades.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/390","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.reades.com\/wp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.reades.com\/wp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.reades.com\/wp\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.reades.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=390"}],"version-history":[{"count":0,"href":"http:\/\/www.reades.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/390\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.reades.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=390"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.reades.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=390"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.reades.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=390"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}