Postgresql + drbdlinks + heartbeat on Debian

Posted by marco
Fri, 16 Mar 2007 18:24:00 GMT

Problem: you have two server in a HA architecture (active/passive) with heartbeat. You want to sync a Postgresql database between the two servers, without using a SAN.

Solution:

  • install DRBD and share a partition, e. g. dev/drbd0, where you will store the data directory of postgresql. Mount this partition on the active server, e.g. under /ha;

  • create the postgresql data dir under the mountpoint, stop postgresql, and copy the whole content of /var/lib/postgresql in /ha/var/lib/postgresql:

    server1:~# mount /dev/drbd0 /ha
    server1:~# mkdir -p /ha/var/lib/postgresql
    server1:~# /etc/init.d/postgresql-7.4 stop
    server1:~# cp -R /var/lib/postgresql /ha/var/lib/postgresql
    
  • install drblinks, which creates a symbolic link of a given directory to the drbd partition. Put in /etc/drbdlinks.conf

     ...
     mountpoint('/ha')
     link('/var/lib/postgresql/')
     ...
    
  • start drblinks. Now /var/lib/postgresql should be a symbolic link to /ha/var/lib/postgresql, while the old /var/lib/postgresql has been moved to /var/lib/postgresql.drbdlinks

     server1:~# drbdlinks start
     server1:~# ls -l /var/lib
    ...
    lrwxrwxrwx 1 root     root         23 2007-03-16 16:54 postgresql -> /ha/var/lib/postgresql/
    drwxr-xr-x 3 postgres postgres   4096 2007-03-16 16:03 postgresql.drbdlinks
    ...
    
  • Start postgresql and verify that everything is working.

  • Now remove the init script of postgresql. That's because at boot the postgresql's init-script has a precedence over the init script of heartbeat, thus starting postgresql with the real /var/lib/postgresql as data directory. Then heartbeat starts, starting drbdlinks, and moves the data directory, creating the symbolic link, while postgresql is running. This creates a lot of inconsistencies in the database. Meanwhile, you want heartbeat taking care of starting or stopping postsgresql after drbdlinks.

      server1:~# mv /etc/init.d/postgresql-7.4  /etc/ha.d/resource.d/
      server1:~# update-rc.d postgresql-7.4 remove
                 Removing any system startup links for /etc/init.d/postgresql-7.4 ...
                /etc/rc0.d/K19postgresql-7.4
                /etc/rc1.d/K19postgresql-7.4
                /etc/rc2.d/S19postgresql-7.4
                /etc/rc3.d/S19postgresql-7.4
                /etc/rc4.d/S19postgresql-7.4
                /etc/rc5.d/S19postgresql-7.4
                /etc/rc6.d/K19postgresql-7.4
       server1:~# cat /etc/ha.d/haresources
       server1 drbddisk::r0 Filesystem::/dev/drbd0::/ha::ext3 ...  drbdlinks ... postgresql-7.4
    
  • Repeat the same procedure for server2. Beware that the file /etc/ha.d/haresources should be identical on both servers.

Now drbd takes care of syncronizing the partition and thus the database, while heartbeat takes care of starting and stopping the instances of postgresql on both servers.

Debian on a Sony Vaio VGN-C1S/H

Posted by marco
Mon, 13 Nov 2006 20:24:00 GMT

I recently got a Sony Vaio VGN-C1S/H. This is my experience installing Debian GNU/Linux on it.

Configuring Postfix + Sasl + Cysrus + Dspam + Clamav (Clamsmtp) on Debian

Posted by marco
Fri, 25 Aug 2006 23:19:00 GMT

I give here some hints on configuring a mail server with Postfix, Cyrus, Dspam and Clamsmtp. They serve primarily as a personal reminder, so it’s not a real howto.