« April 2007 | Main | June 2007 »

May 31, 2007

Email, Templates, and Perl

I have been meaning to talk about one of my new favorite Perl modules, MIME::Lite::TT::HTML , for quite a while now.  As I mentioned in a previous post, there are a bazillion different ways to send an Email message from Perl.  This one is just my new favorite.

Here is a short list as to why:

  • Can be used for complex multi-part messages and handles attachments easily
  • Built upon the equally great MIME::Lite module
  • Allows you to easily template your messages using the familiar Template Toolkit package

The templating part is, in my opinion, the important part.  How many times have you had to go edit some source code just to change the text or subject of a message?  Isn't that just terribly annoying. We use configuration files, MVC with HTML templates, etc, etc. to not hard code things into our apps, but for some reason many people ( myself included for years ) have neglected Email.

Not any longer, I've switched to using this module as my standard way of sending Email these days.  If you are interested in learning more about MIME::Lite::TT::HTML, check out my short howto Sending Email with Perl Best Practice on the subject.

May 23, 2007

PostgreSQL error messages confusing to new users

In the spirit of my blog post last week, I've created a new page that shows a couple of the more common error messages that confuse newer PostgreSQL users. It is my intention to expand this over time as I see people having trouble.

If you have any error messages you feel should be included or you find any technical inaccuracies please post a comment and I'll include it on the page.   

May 19, 2007

Dumb Server Policies

I was chatting with someone recently about what may truly be the dumbest server policy I've ever heard of. He indicated that the company required that:

"All company servers were required to be rebooted each day at noon and midnight".

At first you might be thinking this is an old vestige of a Windows shop policy from days long gone, but no this included their *BSD and Linux servers AND all of their desktop PCs.  He also mentioned a couple of choice quotes from the policy:

"The policy has been considered to save the company thousands of dollars in fewer crashes. And synergizes with our risk management initiatives".

This just screams of a policy created by someone who doesn't understand the real underlying problem. While their heart is in the right place, I seriously doubt this saves the company money.  In fact, I'm quite sure it costs them much more in early hardware failures and lost productivity when systems are offline. 

The policy is almost as bad as someone instituting a mandate that requires everyone to change their password twice a day at noon and midnight in an effort to "strengthen our security". ( For the record, all that does is weaken your security as EVERYONE just has to write it down ).

The moral of the story is to handle the problem at hand with the proper solution. Restarting might be good for Windows based systems, but it is completely unnecessary in a Linux/Unix/*BSD system.

May 16, 2007

Common PostgreSQL problem

I see this problem pop up in the #postgresql IRC channel so often I felt it was necessary to blog about it. This problem trips up so many new users it might even be worth changing the default error message to indicate what is going on. The error message happens when the user tries to run psql for the first time:

psql: FATAL: database "root" does not exist

Where "root" is the current Unix username of the operator.  By default PostgreSQL attempts to log you into a database that is the same as your username.  However, it does not setup this database for you because it would be silly to setup 500 databases for all of the Unix users on your system, if only two of them are going to be using PostgreSQL. 

When setting up PostgreSQL for the first time you need to do the following:

  1. su ( or otherwise ) become your root user
  2. su ( or otherwise ) become your PostgreSQL user, typically 'postgres'
  3. Create your first database

The ultimate goal here is to become your PostgreSQL user, typically this involves becoming root and then switching to user postgres.  Upon setup this is the only user that is allowed to create users and databases.

Your "first" database can be created in one of two ways:

  1. Run the command 'psql template1' followed by a 'CREATE DATABASE' SQL call
  2. Run the command 'createdb <dbname>'

While you're still the postgres user it is probably best to also create a user with 'createuser <username>' or a 'CREATE USER' SQL call. See this section of the PostgreSQL documentation for more information on creating users and roles. You'll also want to read up on managing databases.

NOTE: The programs createdb and createuser may not be, by default, in your PATH so it may be necessary to use locate or type in the full path to your PostgreSQL bin/ directory.

Hope this helps!