Yesterday we received our shiny new
MacBook Pro laptops. So I've been spending a lot of time installing everything needed to make it the awesome development machine it should be! After wasting a lot of time getting
Firefox running properly (after reinstalling it about 10 times the problem turned out to be with Google Toolbar - the problem only manifested itself after the
second restart of
Firefox which made it hard to pinpoint the problem) the biggest hurdle has been
Postgres.
I used developer.apple.com's
PostgreSQL on Mac OS X instructions as a base, but because of our
NTLM proxy, and the fact the the
MacBooks are brand new, there were a few extra steps that needed to be made. The full sequence is listed below for posterity:
Install ntlmapsThe
NAA uses an
NTLM-based authenticating proxy, which cannot be used by software package managers such as fink and apt. To get around this, download the source for a python program called
ntlmaps from its
sourceforge downloads page. Unpack the contents and copy the whole directory to the mac's Applications folder. In the main
ntlmaps directory, edit the server.
cfg file to suit your proxy (I needed to edit the parent proxy address, parent
proxy port, domain name,
username and password fields. Yes, unfortunately the password is stored in this file in
plaintext - if you don't mind starting up
ntlmaps manually each time you can leave the password field blank and
ntlmaps will request the password when you start it). Finally, run the main.
py script to start the
ntlmaps proxy.
Install FinkFink is a package management system for OS X, based on apt. It's the easiest way to install
postgres as it means
postgres doesn't have to be built from source! Follow the instructions on the
fink download page to install fink.
Set the http_proxy environment variableApt needs to know about t
he ntlmaps proxy. In your system-wide configuration file, add the following lines:
http_proxy="http://localhost:5865"
export http_proxy
To find the system-wide configuration file that the mac was using, I referenced
Configuring Your OS X Unix Environment and found that I was using the bash shell, and so I added the above lines to the /etc/profile file.
Install Postgres using aptFirstly, update the apt cache of packages by executing the following command:
sudo apt-get update
Next we need to find the correct package to install. Use the following command to search for
postgres packages:
sudo apt-cache search postgres
Install the most up-to-date package in the returned list of packages. For me, it's
postgresql80. The package is installed with the following command:
sudo apt-get install postgresql80
Follow the prompts, and
postgres is installed!
Setup root userThe
postgres user is created during the
postgres installation, however the user is not informed as to its password... which is needed to do just about anything useful with
postgres. To set the
postgres user's password, we need to be root. However the
powerbook does not initially have a root password set so we need to change this first. Use the command:
su passwd root
and follow the prompts to change the root password.
Change password for postgresUse the following commands to change the password for the
postgres user:
su
passwd postgres
Create pgsql data dirCreate a directory in which the database tables will live. I chose
/usr/local/pgsql/data. Run the following commands to create the directory and give ownership of it to the postgres user:
sudo mkdir /usr/local/pgsql/data
sudo chown postgres /usr/local/pgsql/data
Fix the postgres user
The postgres user created by the postgres install process is not set up correctly - its home and shell properties are set to null. To fix this, run NetInfo Manager (I used spotlight to find it), click on "users" and then "postgres", and change the "home" property to /Users/postgres, and change the "shell" property to /bin/bash.Increase shared memoryThe first time I tried to run the
initdb command I got an error saying that there was not enough shared memory to run that command. It's probably because I had eclipse open at the time, but I decided it was probably a good idea to increase it anyway. To increase shared memory, edit (or create if it doesn't exist) the
/etc/sysctl.conf file so that it contains:
kern.sysv.shmmax=16777216
kern.sysv.shmmin=1
kern.sysv.shmmni=128
kern.sysv.shmseg=32
kern.sysv.shmall=4096
This will increase the shared memory from the default 0f 4MB to 16MB.
Run initdbRun the following command to initialise the database:
initdb -D /usr/local/pgsql/data
Start postgresNow we're ready to start
postgres! Run the following command:
pg_ctl -D /usr/local/pgsql/data -l logfile start
And we're done! It's that easy!