Real life use case of Postgres' LISTEN/NOTIFY

A Postgres noob asked me: what's the real time (sic) use of LISTEN and NOTIFY? And here's how the conversation went:


noob:  what's the real time use of LISTEN and NOTIFY?
 
in postgresql
 
me:  Well, that is a very useful facility.
 
Say you have two applications, one inserts some data and the other reads and acts on that data..
 
In a normal setup you would have the reading application querying the DB every few seconds to see if new data has come in..
 
This incurs overhead on the dataabase.
 
In Postgres you can use LISTEN/NOTIFY to achieve the same thing without having to 'poll' the database every few seconds.
 
The reading application can register its interest in new data by saying 'LISTEN newdata'
 
And the writing application, whenever it inserts new data, can send  anotification, saying 'NOTIFY newdata'
 
At this point, Postgres will send a message to the reading application that 'newdata' has arrived, and now the reading application query the database to process newly inserted data.
 
I hope that explains it.

noob:  thank you Gurjeet, that's really good
 
Happy Weekend

How to convert MTS files to AVI

Per my comments here on a blog post [1] I finally succeeded in converting MTS files (from my Sony HD handycam) to AVI files. Here's how to convert them en'masse:

I am using Linux Mint 10, and ffmepg version 0.6-4:0.6-2ubuntu6.1

.) Put all your MTS files in a directory, and cd into that directory.
.) Use ffmepg to find out the highest bitrate used by the MTS files:
    ls *.MTS | xargs -n 1 ffmpeg -i 2>&1 | grep bitrate | cut -d : -f 6 | sort -g | tail -n 1

    I got 13039 kb/s in my case.


.) Use ffmpeg to do the conversion:

    ls *.MTS | xargs -n 1 -I XXXX ffmpeg -i XXXX -b 13000k -ac 2 -ab 256k -deinterlace XXXX.AVI

    I used the 13000k value above because in the previous step we found out that the highest value is 13039 kb/s. This will allow us to keep the quality of our videos almost unaltered.

    I think that if the actual bitrate of a video is lower than this value, say 8000 kb/s, then ffmpeg will keep that bitrate instead of creating the AVI at 13000 kb/s bitrate, so the AVI filesizes will almost be the same as the MTS files.

    This step will result in additional files to be created in the directory where you are; for eg. if you had files a.MTS and b.MTS, this step will create files a.MTS.AVI and b.MTS.AVI.

[1] http://justplainobvious.blogspot.com/2010/06/how-to-convert-mts-to-avi-in-linux.html