macdevcenter.com
oreilly.comSafari Books Online.Conferences.

advertisement

AddThis Social Bookmark Button

PostgreSQL for Mac OS X

by Michael Brewer
06/07/2002

Editor's note -- Developers of all types are testing Mac OS X as their new platform of choice. For example, this article on how to install a PostgreSQL database on Mac OS X was written by Michael Brewer, who has just switched from Windows 2000 to Mac OS X on an iBook.

In case you haven't been introduced to PostgreSQL, itís a robust open source database. For a little history take a look at How PostgreSQL Rose to Fame. Then read this article. Chances are you'll join the ranks of enthusiastic PostgreSQL fans. And the best part is you get to run it on Mac OS X.

Applying Existing Skills to a New Platform

Are you a long-time Mac user curious about working with databases in the past but scared away by prohibitive prices? Are you new to Apple and would like to put your prior database experience to use on the Mac? If you're either, read on. I'm going to walk you through installing PostgreSQL on Mac OS X 10.1.4, as well as using SQL tool with it and connecting to PostgreSQL with Java. The Java bit is at the tail end of this piece so that if programming (or Java itself) isn't your thing you can easily skip it.

I'm a new Mac user. I recently made the switch from Windows 2000 to Mac OS X, and have become comfortable enough in my new environment to flex some of my database skills on this exciting new platform -- having worked with everything from MS Access to Oracle in the past. I've kept up with some of the high level news about what is going on in the open source DBMS realm. So when I pondered what DBMS I should install on my Mac, PostgreSQL was the rather quick answer. It has good third party support from developers, and it passes the ACID (Atomicity, Consistency, Isolation, and Durability) test.

Installation

Related Reading

Practical PostgreSQL
By John C. Worsley, Joshua D. Drake

If you don't already have a current version of Apple's Developer Tools, now is the time to get them. We'll be using the compiler during installation of PostgreSQL.

All right, now let's get PostgreSQL. You can download PostgreSQL 7.2.1 via FTP or HTTP. I saved the file to my desktop, but you can save it wherever you wish. Use StuffIt Expander to extract the files.

To install PostgreSQL, open Terminal from Applications/Utilities. Inside of Terminal, go to the folder where you extracted the download to (an easy way to accomplish this is to type cd, a space, and then drag the folder onto Terminal to paste the path in place). In this folder you'll want to run the configure script.

Configure will sniff out the proper system variables to set for Mac OS X (10.1 or later is required). Several files will be created in the build tree to record these customizations. To run the configure script you must type ./configure at the command line. However, we are not ready to run the script just yet. First, let's discuss a few switches we can append to customize our configuration.

PostgreSQL will install into /usr/local/pgsql by default. Since we're installing to Mac OS, we want to change this directory to something more appropriate. You can do this by specifying the command line option --prefix=/Users/Shared/PostgreSQL.

Because I realize the audience for this article is international, we're also going to include locale support. We do this by passing the argument --enable-locale. Additionally, if you plan to use your database with an interface that expects all strings to be in Unicode, you need to add the --enable-multibyte=UNICODE option. I'm turning on multibyte support because I plan to use PostgreSQL as the DBMS for some Java applications I'll be developing. If you're going to skip the Java portion of this article, you can choose not to include this argument.

Some other interesting options are --with-openssl, --with-perl, --enable-syslog, and --enable-debug. I won't be covering these options in order to be brief, but I do recommend you look into them.

Now is the time to run configure. I typed the following (the underscore is merely a line continuation character for the purpose of fitting commands within the constraints of this Web page -- in other words, you don't want to type it):

./configure --prefix=/users/shared/PostgreSQL _
--enable-locale --enable-multibyte=UNICODE 

You'll know configure is complete when you receive a command prompt.

In order to actually begin building PostgreSQL we need to execute GNU Make from the command line by typing make (Apple has installed GNU Make as the default make mechanism).

The build process can last anywhere between 5 minutes and half an hour, according to documentation provided by PostgreSQL. The build on my 600Mhz iBook lasted 7 minutes. Once the build is completed, type make install to begin installing PostgreSQL. If you plan to do server-side program development such as creating custom functions, replace install with install-all-headers. If your install was successful, you'll see the following output:

Thank you for choosing PostgreSQL, the most advanced open source database engine.

Since we installed PostgreSQL to a location that is not searched for applications, we must add /Users/Shared/PostgreSQL/bin to our path. This can be handled by entering the following at the command prompt:

setenv PATH ${PATH}:/Users/Shared/PostgreSQL/bin

You should type the following to reference the manual pages for PostgreSQL:

setenv MANPATH ${MANPATH}:/Users/Shared/PostgreSQL/man


Pages: 1, 2

Next Pagearrow