Wednesday, April 14, 2010

Using PostgreSQL

Now that PostgreSQL is installed and running on my Mac, I need to do something useful with it, like create my database and get it migrated through Rails.  The terminology and approach is a tad different from MySQL, but after a bit of googling, I found this PostgreSQL documentation page which got me rolling. This page on creating a database was actually the starting point, because it worked through the various errors which might occur.

The key difference for me was that the PostgreSQL superuser is called 'postgres', not 'root' as in MySQL. Prior to digging out this piece of information, everything I tried got the following error:

createdb: could not connect to database postgres: 
FATAL:  role "jseidel" does not exist

The other thing that was a minor roadblock was getting out of psql (PostgreSQL's interactive SQL command program). The usual MySQL/bash suspects (quit; exit; bye; {Ctrl-C}) didn't work. With psql you either type "\q" or {ctrl-D} and you're out.

Finally, since I'm using MacPorts, the location of the PostgreSQL files are different than documented in the PostgreSQL guide: my files are rooted off /opt/local/lib/postgresql84 instead of /usr/local/pgsql as is indicated in that guide.

Now I'm able to create my database and see if it connects with Rails...

No comments:

Post a Comment