2. Why?
•Building a mapping website!
•Wanted Postgres 9.2 to go pure
Javascript: client, server (node.js), &
database!!
•And wanted latest & greatest mapping
Installing Postgres & PostGIS on a Mac - November 20th, 2012
http://www.ashmeadsoftware.com
3. Objective
•Postgres 9.2!
•Postgis 2.0 http://www.postgis.org/!
•psql, pgAdmin3, & phpPgAdmin!
•Node.js!
•PL/Javascript
Installing Postgres & PostGIS on a Mac - November 20th, 2012
http://www.ashmeadsoftware.com
5. Strategies
•EnterpriseDB - provides Stack Builder
not currently current, but good starting
point!
•DMGs - not always current, but good
intel!
•Open source: fink, homebrew,
macports - can be hacked, instructive
Installing Postgres & PostGIS on a Mac - November 20th, 2012
http://www.ashmeadsoftware.com
6. EnterpriseDB
% sudo vi /etc/sysctl.conf
!
On a MacBook Pro with 2GB of RAM, the author's sysctl.conf contains:
!
kern.sysv.shmmax=1610612736
kern.sysv.shmall=393216
kern.sysv.shmmin=1
kern.sysv.shmmni=32
kern.sysv.shmseg=8
kern.maxprocperuid=512
kern.maxproc=2048
Installing Postgres & PostGIS on a Mac - November 20th, 2012
http://www.ashmeadsoftware.com
7. Kyngchaos
•Stackbuilder!
•Not quite current: when did first, was
Postgres 9.1, PostGIS 1.5. (Now is 9.1,
but 2.0.0)!
•But lots of good information, i.e.
PostGIS has lots of dependencies: geos,
proj4, some others
Installing Postgres & PostGIS on a Mac - November 20th, 2012
http://www.ashmeadsoftware.com
9. Open source
packagers
•Fink - precompiled binaries preferred. Not
as up to date. Not current enough.!
•Homebrew - easier to use. On github. Uses
ruby. Less intrusive. Assumes single user.!
•Macports - tends to pull a lot of stuff down.
Possibly more general. Used here. http://
www.macports.org/
Installing Postgres & PostGIS on a Mac - November 20th, 2012
http://www.ashmeadsoftware.com
10. Portfiles
https://trac.macports.org/browser/trunk/dports/databases/
postgis2/Portfile
variant postgresql92
description {Builds with postgresql
9.2}
conflicts postgresql90 postgresql91 {
depends_lib-append
port:postgresql92
archcheck.files-append lib/postgresql92/libpq.dylib
configure.args-append
--libdir=${prefix}/lib/postgresql92
--with-pgconfig=${prefix}/lib/
postgresql92/bin/pg_config
build.args-append
PGSQL_DOCDIR=${destroot}${prefix}/
share/doc/postgresql91
PGSQL_MANDIR=${destroot}${prefix}/
share/man
}
!
Installing Postgres & PostGIS on a Mac - November 20th, 2012
http://www.ashmeadsoftware.com
11. Port commands
port list > /dev/null
Warning: port definitions are more than two weeks old, consider
using selfupdate
port selfupdate
[ port upgrade postgresql92 skipped ]
port -v install postgresql91 +perl +tcl +python
port -v install postgresql91-doc
port install pgAdmin3 +postgresql91 +with_postgresql91
port install postgis2 +postgresql91 +raster +gui +topology
Installing Postgres & PostGIS on a Mac - November 20th, 2012
http://www.ashmeadsoftware.com
14. Processes
507 7714
1
0 5:22PM ??
0:00.04 /Library/
PostgreSQL/9.2/bin/postmaster -D/Library/PostgreSQL/9.2/data
507 7715 7714
0 5:22PM ??
0:00.00 postgres: logger
process
507 7717 7714
0 5:22PM ??
0:00.01 postgres:
checkpointer process
507 7718 7714
0 5:22PM ??
0:00.05 postgres: writer
process
507 7719 7714
0 5:22PM ??
0:00.03 postgres: wal
writer process
507 7720 7714
0 5:22PM ??
0:00.05 postgres:
autovacuum launcher process
507 7721 7714
0 5:22PM ??
0:00.07 postgres: stats
collector process
~
Installing Postgres & PostGIS on a Mac - November 20th, 2012
http://www.ashmeadsoftware.com
15. Profile variables
vi .profile
# to change back to Postgres 9.1, fix path & set PGPORT to 5432,
export PATH=".:/opt/local/lib/postgresql92/bin:/Library/
PostgreSQL/9.2/bin:$PATH”
!
export PGDATABASE=talkinvite
export PGUSER=talkinvite
export PGPORT=5433
vi apache/conf/httpd.conf
#
ServerRoot "/Library/PostgreSQL/EnterpriseDB-ApachePHP/apache"
# Listen: Allows you to bind Apache to specific IP addresses and/
#
Listen 8081
vi phpPgAdmin/conf/config.inc.php
# to change back to Postgres 9.1, fix path & set PGPORT to 5432,
// Database port on server (5432 is the PostgreSQL default)
// Using 5433 for Postgres 9.2
$conf['servers'][0]['port'] = 5433;
Installing Postgres & PostGIS on a Mac - November 20th, 2012
http://www.ashmeadsoftware.com
16. Verify
•Check psql, pgAgent3, pgPhpAdmin
(using apache)!
•Bounce box, make sure it comes back!
•Hand save some simple maps, then
recover
Installing Postgres & PostGIS on a Mac - November 20th, 2012
http://www.ashmeadsoftware.com
18. Pre-Requisites
for PostGIS
•Obvious ones (database, compiler, …)!
•PROJ4 - makes round things flat!
•GEOS - “fairly safe to upgrade”!
•LibXML2 - what may have broken!
•JSON-C - JSON support for GEO!
•GDAL - raster support
Installing Postgres & PostGIS on a Mac - November 20th, 2012
http://www.ashmeadsoftware.com
19. Of the 36 strategies,
running away is the best
•Loaded in Postgres 9.1, PostGIS 1.5!
•Tried upgrade to postGIS 2.0 using
various tricks on web. Kept hitting
failures, missing bits & so on, dead
parrots from previous runs, !
•Ask Bruce & Jim
Installing Postgres & PostGIS on a Mac - November 20th, 2012
http://www.ashmeadsoftware.com
21. Download latest
Fixed www/phppgadmin/conf/config.inc.php to use port 5433
Ran “select
version()”
to get:
select postgis_full_version()
->
POSTGIS="2.0.1 r9979" GEOS="3.3.5-CAPI-1.7.5" PROJ="Rel.
4.8.0, 6 March 2012" GDAL="GDAL 1.9.1, released 2012/05/15"
LIBXML="2.7.8" LIBJSON="UNKNOWN" RASTER
Installing Postgres & PostGIS on a Mac - November 20th, 2012
http://www.ashmeadsoftware.com
23. Fun with maps
•
•
•
MVC & mapping libraries
•
A plan, ney, a map
•
PostGIS
Javascript & node
Open source maps - MapServer, PostGIS
Installing Postgres & PostGIS on a Mac - November 20th, 2012
http://www.ashmeadsoftware.com
24. Installing Postgres & PostGIS on a Mac - November 20th, 2012
http://www.ashmeadsoftware.com
25. Installing Postgres & PostGIS on a Mac - November 20th, 2012
http://www.ashmeadsoftware.com
26. Checklist
•Software downloads: node, npm, express, … !
•Setup hackable app: my what lovely stack traces
we are showing today…!
•Verify hackable’s access to postgres!
•Find & load in initial spatial data!
•Manage spatial data (leaflet)!
•Create MVC wrappers for all this GIS goodness
Installing Postgres & PostGIS on a Mac - November 20th, 2012
http://www.ashmeadsoftware.com
27. Recommendations
(your mileage may vary)
•Go with packages,
defaults when you can!
•If you can’t, build up in
layers.!
•Trust but verify!
•Learn a bit more than
you need to; ask around!
Installing Postgres & PostGIS on a Mac - November 20th, 2012
•Keep a log
http://www.ashmeadsoftware.com
Editor's Notes
\n
\n
\n
Had a first pass, spent quite a few hours working this out, got up to 9.1 + 2.0.1\n\nFor this talk, walked up to 9.2, checked what status is now\n\nExpert on UNIX sysadm & databases, but not on postgres\n
As to databases, have used a lot. \nFor open source, have like violins: SQLite, MySQL, Postgres\nPostgres 9.2 has JS internally, so with node.js can run js on client, server, & database. Sweet.\n20\nHad previously installed 9.1. On an iMac with 20GB memory.\n
No postgis extension!\nTried copying the postgis-2.0 to /Library/PostgreSQL/9.2/lib, didn’t help\nUsed pg_config to figure out that $libdir was /Library/PostgreSQL/9.2/lib\nIs server needed for 9.2?\nWhy can’t it find postgis-2.0 in $libdir when it is there\n\n\n\n
\n
\n
There are lots postGIS dependences listed there:\n\n
\n
http://tedwise.com/2010/08/28/homebrew-vs-macports/\n\nFink puts stuff in /sw; have used a lot; didn't want to talk to me just now: pdb.finkproject.org\n\nthere is also http://www.pkgsrc.org/\n\n\n\n\n\n\n\n
\n
Problem is that it doesn’t hook stuff up, so have to have apache setup, launchd, and so on.\nFortunately enterprisedb does all this\n\n7412 lines later on the postgis2 upgrade! :)\n\nInstalls files in /opt/local/var/macports and various sub directories of this\n\nNow at 9.1 + 2.0.1, want to go to 9.2 + 2.0.1!\n-- so we have javascript!\n\n \n\n\n\n\n
\n
Port installs a program called daemondo wrappers the package in a way that works well with mac's launchd.\n\nNot needed for postgres since there is only one command, portmaster, to be run\n\nnot needed for postgis, since that installs as an extension within postgres\n\nso replaced call to daemondo with direct call on postmaster, less kruft\n\non first install, use port install package name, on subsequent should use port upgrade package name(s)\n\n\n\n\n\n\n
\n
\n
\n
Ubuntu software center & postgres\n\napparnetly you have to sudo to run a run command, using own passowrd!\n\nadding in apache & also phpPgAdmin\n\ndownloaded postgres & sudo'd & ran the .run file\n\ndid apt-get postgis\n\nrebuild from source ran into lots of missing pieces, i.e. xml-config\n\nhttp://linfiniti.com/2012/05/installing-postgis-2-0-on-ubuntu\n\nTrick was to go back to 9.1, then load in\nThen, load in tricks for 9.1\npushed to 9.2, but wroking on Mac\n\n
\n\n\n
A lot, ran into a series of fails on the compile, finally just gave up\nOne problem is that some tools not careful about where they litter: copies of “createdb" in /usr/local a major problem: always check tools & fix in the .profile\nThe configure broke: \n\nhad trouble with the createdb -- but still seems to have worked! as a postgis_template database had come into existence\nused scripts/launchpgadmin.sh to kick off a pgAdmin shell; preferred sudo\nbrought parallls up to rev\nfixed PGPORT using variable (& pgpass) to 5432 (had been thinking it was 5433 -- this was all the low level tools, as psql)\nadded show_system =- true to get phpPgAdmin to work\nahd a lot of trouble with wronge createdb, until realize had to fix paths: see pg_env.sh & . include that\nselect postgis_full_version(); - in a database to check\n\n\nselect oid, datname, datistemplate from pg_database;\ndrop database template_postgis2\n\nattempt to recompile from source died on some error messages about xml config, some more in the works\n-- tried various sources, but got things like createdb failures\n-- instructions basically require two things: 1) build from source all the way up 2) know what you are doing. Don't mind one, but two is a killer\n\nfigured I'd just ask Jim & Bruce\n\nCould have used a "these are the big pieces" cheat sheet; may even exist\n\nA lot of libraries have to be compiled into the tree; could walk up from ground but just poking at the problem is an issue.\n\n\n\n\n\n
\n
Downloaded 9.1 & installed\nFound 9.2 already had postgis 2.0! Great -- one strategy is just to wait!\nBecause had already installed 9.1, was using port 5433 for postgres 9.2\nSo had to fix the phppgadmin/conf/config.inc.php file, to have it go to port 5433\nAfter a bit of futzing with the permissions, was up\nRan select version()\n\n\n\n
\n
PostGIS+JSON+Maps+Open+source\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
And if you are prepping a demo for others:\n1) make it standalone\n2) test soup to nuts\n