Installing postgres on OSX 08 / 04 / 2013

Installing a project from a friend made with Rails I figured out that was using postgres and I didn’t have it installed on my OSX. I found a couple of problems that I’ll describe here (and how to solve them of course).

First of all, to install postgres using brew:

brew install postgres

After the installation, is a good idea to create the first database

initdb /usr/local/var/postgres

Usually on default installations of OSX the following error appears:

creating template1 database in /usr/local/var/postgres ...
FATAL: could not create shared memory segment: Cannot allocate memory
DETAIL: Failed system call was shmget(key=1, size=1318912, 03600).
HINT: This error usually means that PostgreSQL's request for a shared memory segment exceeded 
    available memory or swap space. To reduce the request size (currently 1318912 bytes), reduce
    PostgreSQL's shared_buffers parameter (currently 50) and/or its max_connections parameter (currently 10).
The PostgreSQL documentation contains more information about shared memory configuration.
child process exited with exit code 1
initdb: removing contents of data directory "data"

This happens because the desktop installation of OSX is not configured to have enough shared memory to run postgres.

Try executing this command to check your settings:

sysctl -a

You can configure this by modifying kernel parameters, running the following as root:

sysctl -w kern.sysv.shmmax=1610612736
sysctl -w kern.sysv.shmmin=1
sysctl -w kern.sysv.shmmni=32
sysctl -w kern.sysv.shmseg=8
sysctl -w kern.sysv.shmall=393216
sysctl -w kern.maxprocperuid=512
sysctl -w kern.maxproc=2048

Or adding the kern.* parameters to /etc/sysctrl.conf permanently. You can find some related information in the apple knowledge base.

You need to reboot to reflect the changes.

Now after executing again the database creation command everything should be ok. Nice moment then to create a new user.

createuser --interactive postgres

Another alternative command to create a databse could be the following:

createdb -Opostgres -Eutf8 db_development

More on postgres on the following posts…

The Pragmatic Programmer 02 / 04 / 2013

One of the last books that I read for my profession is The Pragmatic Programmer: From Journeyman to Master. I feel the necessity of share a couple of good quotations.

What happens when we are proactive and we find a lot of obstacles, excuses or “yes but” arguments?

It’s easier to ask forgiveness than it is to get permission.

About the benefits of discussing ideas…

Nothing is more dangerous than an idea if it’s the only one you have.

Agile development is good, but under certain boundaries.

Who made changes in this line of code? What’s the difference between the current version and last week’s? How many lines of code did we change in this release? Which files get changed most often? This kind of information is invaluable for bug-tracking, audit, performance, and quality purposes.

About writing specifications like APIs, functional requeriments and the importance of those documents.

Dealing with computer systems is hard. Dealing with people is even harder. But as a species, we’ve had longer to figure out issues of human interactions. Some of the solutions we’ve come up with during the last few millennia can be applied to writing software as well. One of the best solutions for ensuring plain dealing is the contract.

Writing a specification is quite a responsibility.

Always make questions to yourself.

So next time something seems to work, but you don’t know why, make sure it isn’t just a coincidence.

One of the reasons of this blog…

The palest ink is better than the best memory. Chinese Proverb.

I usually try to read one technical book and then a non-technical one. If you have suggestions please feel free to leave a comment.

Hello World! 24 / 03 / 2013

First post using Jekyll and github pages!