<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>Shady Project: Tag Postgres</title>
    <link>http://blog.shadyproject.net/articles/tag/postgres?tag=postgres</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>Stuff.  And Things.</description>
    <item>
      <title>Postgres Housekeeping</title>
      <description>&lt;p&gt;Previously, we installed postgresql on our OS X computers.  Now lets do a little bit of house keeping and clean up to make it more convenient for general use.&lt;/p&gt;

&lt;p&gt;We'll start with the easiest problem first - getting rid of that postgres user hanging around our login window. One simple command takes care of this:
&lt;ul&gt;
&lt;li&gt;sudo defaults write /Library/Preferences/com.apple.loginwindow HiddenUsersList -array-add postgres&lt;/li&gt;
&lt;/ul&gt;
You'll be prompted for your administrator password, and after this command executes, postgres will no longer show up in the login window. You will, however, notice an option "Other..." so you can still login as the postgres user if you wish.  This will not affect your ability to use su or sudo and execute commands as the postgres user.&lt;/p&gt;

&lt;p&gt;
Next task is to get postgres to start up on its own. For this, we will use the newfangled technology provided by apple in 10.4: Launchd.  Fortunatley, lots of smart (and not lazy) people have done the hard work for us.  You can download a functional launchd item &lt;a href="http://home.exetel.com.au/lachlandeck/blog/wp-content/downloads/org.postgresql.postmaster.plist"&gt;here&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
Note that the fine gentleman who made this Launchd item has his own &lt;a href="http://home.exetel.com.au/lachlandeck/blog/?p=7"&gt;tutorial for setting up postrgres&lt;/a&gt;.  Check if out, if you like.  There is a lot more detail to be had there, such as setting up perl and java to connect to postgres.  However, his installation direction for postgres different then the one we used previously.  As a result this we will need to change a few properties of this plist.  An aside: since launchd items are just plists (xml files) we can use the plist editor that comes bundled with xcode tools to edit the file.  And this works.  A nice alternative, however, is the nifty little tool Launchd Editor, available &lt;a href="http://www.codepoetry.net/products/launchdeditor"&gt;here&lt;/a&gt;.  Back to the action: we need to change the following properties of the plist file:
&lt;ul&gt;
&lt;li&gt; The value for -D should be /usr/local/pgsql/data (or where ever you set your data directory)&lt;/li&gt;
&lt;li&gt;The value for log_directory should be /usr/local/pgsql/logs (or, again, where ever you set your logs directory).
&lt;/ul&gt;
Once we have made the proper changes, save the plist and fire up the terminal.  We're just a few steps away from having postgresql run whenever we want it to.  The following commands will finish this job for us:
&lt;ul&gt;
&lt;li&gt;sudo cp org.postgresql.postmaster.plist /Library/LaunchDaemons&lt;/li&gt;
&lt;li&gt;sudo launchctl load /Library/LaunchDaemons/org.postgresql.postmaster.plist&lt;/li&gt;
&lt;/ul&gt;

At this point, launchd knows all about our new item, and all we have to do is tell it to start:
&lt;ul&gt;
&lt;li&gt;sudo launchctl start org.postgresql.postmaster&lt;/li&gt;
&lt;/ul&gt;

And with that, postgres should be up and running. Fire up Activity Monitor and check for the postgres process.  You should see a few. If we want to stop the service, run the same command as above, but replace start with stop.  Pretty straightforward. I like to set up two aliases in my .alias file for starting and stopping the service easily from the command line.
&lt;/p&gt;

&lt;p&gt;And there we are.  We can nicely start and stop postgres, the user is gone from our window, and all is right with the world.  If only we had some kind of GUI management tool for dealing with postgres . . . something like, oh, I dunno .  . . .&lt;a href="http://www.pgadmin.org/"&gt;this, maybe?&lt;/a&gt;.  Of course, if you're more partial to web based management solutions a la phpmysql, there is always &lt;a href="http://phppgadmin.sourceforge.net/"&gt;phpPgAdmin&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Of course, we still only have on user set up . . . we have to use postgres to log in to our database.  While I won't tell you exactly what you need to do in order to set up a new user, I will give you a hint:  check the excellent postgres documentation for create role.  With the documentation on that, and the GUI editing tool of your choice (or good ol' psql) you should have extra users up and running in no time.  The LOGIN attribtue might help too.
&lt;/p&gt;

&lt;p&gt;Tune in next time, when we (finally!) get around to installing PostGIS.&lt;/p&gt;</description>
      <pubDate>Mon, 29 Jan 2007 07:30:00 -0800</pubDate>
      <guid isPermaLink="false">urn:uuid:0f628436-c584-499a-846d-8fa8401ec917</guid>
      <author>Shady</author>
      <link>http://blog.shadyproject.net/articles/2007/01/29/postgres-housekeeping</link>
      <category>OSX</category>
      <category>Database</category>
      <category>Postgres</category>
    </item>
  </channel>
</rss>
