Archive for February, 2009

Slony with Multiple Databases

February 26, 2009 1 comment

While implementing Slony setup for a customer we came up with a scenario where they had four databases running on one PostgreSQL instance on one machine and we had to replicate all the tables within all the databases using Slony. It was pretty simple to implement but the problem was that with all databases on one machine, which means we were going to run a Slon process for each database and that ends up having four Slon processes running on the same box.

After giving it some thought we came up with the following:

– Instead of four databases have one database with four schemas.

– Now create Slony set for each schema with all the schema specific tables in there.

– And then ALTER database users to change there search_path in a way that on login they point to there specific schema so that they dont have to change anything on the application side.

Following the above mentioned approach, we were able to configure Slony with just one Slon process for all the tables and the customer was happy as well 🙂

Shoaib Mir

Categories: PostgreSQL Tags: ,

nm-applet problems in Ubuntu

February 25, 2009 1 comment

Since I upgraded to Ubuntu 8.1 (Intrepid) I started having problems with my nm-applet not showing up in the panel, but I couldnt get time to fix it for a while.

While today I looked at solving it, saw the following problem on starting nm-applet as:

“No connections added”

After doing a few things here and there found that just editing the file /etc/network/interfaces was the solution. A simple fix to that can be remove everything from  /etc/network/ interfaces file except “lo” entries. My original file looked like:

auto lo
iface lo inet loopback
iface eth0 inet dhcp
auto eth0

Commenting out “eth0” lines and restarting nm-applet fixed the problem for me.

Shoaib Mir

Categories: Operating Systems Tags: ,

Gkeyfile and configuration files

February 20, 2009 2 comments

While looking for a configuration file parser I came across GkeyFile that is part of glib. It was very easy to use and met almost all the requirements that I wanted out of it. Here is a simple howto for GkeyFile…

Key files in GLib are more like .ini files that are mostly available on Windows. The key files data is divided into groups, where the name appears between square bracket characters, and comments are started by the # character. Key files, parsed by GKeyFile can handle strings, localized strings(internationalization support), Boolean values, integers, doubles, and arrays of each of these data types.

A simple example of a KeyFile can be:

#First Group
FirstName= Joe

Now in order to get values for FirstName and Age for the group “Student1” you can use the following code in C…

#include <glib.h>

typedef struct
gchar *FirstName;
int Age;

} Student;

int main ()
Settings *conf;
GKeyFile *keyfile;
GKeyFileFlags flags;
GError *error = NULL;
gsize length;

keyfile = g_key_file_new ();

if (!g_key_file_load_from_file (keyfile, “Students.conf”, flags, &error))
g_error (error->message);
return -1;

conf = g_slice_new (Student);

conf->FirstName = g_key_file_get_string             (keyfile, “Student1”,
“FirstName”, NULL);
conf->Age = g_key_file_get_integer (keyfile, “Student1”,
“Age”, NULL);
return 0;

You can find more help for Gekyfile in  Glib Reference Manual

Shoaib Mir

Categories: C/C++ Tags: , ,

PHP and Internationalization support

February 20, 2009 Leave a comment

For the last almost three months I have been doing some PHP programming and its been fun using it 🙂

The project I have been working on is almost complete from the features side that we needed to support but now the issue which just came in was having language support and Internationalization the whole GUI. That actually means having a “Select Language” option on the login screen and then customizing the whole GUI according to that. I have done similar kind of support before in C but at that time I was using a very nice GkyeFile parser from Glibc which had proper support for locale, but being new at PHP I had no idea where to start with and as I started looking for a solution, it ended up being a very simple one. Here is what can be done if someone wants to do the same thing simply in PHP….

– Have a global array called $language and then assign all your GUI labels and error messages like this:

$language[‘btnlbl’] = ‘Button’;
$language[‘Err001’] = ‘Error executing function’;

And put this array in a PHP file (where each language like english, french, german etc etc have a specific {langname}.php file)

– Now we need to use the above mentioned language PHP files…

We kept English as the master language so thats the default, this is how it can be handled:

//If no language is set use English
if (!isset($configuration[‘defaultlanguage’])) $configuration[‘default_language’] = ‘english’;

//Setting up the array and setting all values from the PHP file
$language = array();

And if user has select a specific language on the login screen use the following:

if (isset($_language)) {
$_SESSION[‘weblang’] = $_language;

Now all I had to do was use english.php through out the code and then send the other {language}.php to the translators… and we ended up having a proper internationalization support.

Shoaib Mir

Categories: PHP Tags: ,

Data migration using Kettle (Pentaho)

February 19, 2009 9 comments

I have been using Kettle (a Pentaho tool) for quite sometime in order to do migration of data from different kinds of data sources to PostgreSQL and I can now say that it has been just able to do all kinds of different jobs for me.

All you need to have is the JDBC driver for your target and source database and that is it. Most of the database drivers are already there with standard Kettle installation but in case you need to use a datasource that is not there you can easily configure it with Kettle by placing the JDBC driver in the classes folder for Kettle. I did the same too when I had to convert DBF files to PostgreSQL where I downloaded the DBF JDBC driver; configured it and moved the data across just in few minutes.

Kettle also provides you with a lot of options for data cleansing and all that can be done with drag and drop control in the GUI mode which is very user friendly. If those default controls do not cater for your needs then you can always add your custom logic using JavaScripts which I did as well and was able to cover almost everything from there. You can load/save you control jobs, and it gives a pretty diagram showing every step involved in the ETL tasks which are divided into transformations and jobs.

I myself have tested it with migrating data from Oracle, SQL Server, CSV, XML and DBF to PostgreSQL without much problem so I will highly recommend people looking for an open source data migrator tool that works with PostgreSQL.

Shoaib Mir