MySQL has a sql query to search for a word that you are looking for:
"SELECT post_id FROM messages WHERE contents LIKE '%". $_POST['search_key'] ."%'";
(Go to http://www.mysql.com/doc/en/String_comparison_functions.html)
% means that to look for words, phrases, or sentences that contain the keyword; so if you are searching for a keyword "PHP", then matches are "abcPHP", "abcPHPdef", "PHP", etc; anything that contains "PHP" within it.
Of course there are ways to do the search more accurately by adding a "keyword" column in the table so that each row can have their unique keywords and when search is performed on keyword column, they can be found based on the unique keywords, etc...
I'm not for sure if PostgreSQL has a different statement from MySQL's "LIKE" (which I doubt it, they should be the same) but both of their SQLs are slightly different (for example, LIMIT OFFSET) so you should look into the manual from PostgreSQL.
Good luck!