Re: Converting timestamps and IP addresses

From: Jean-Michel POURE <jm(at)poure(dot)com>
To: Erwin Van de Velde <erwin(dot)vandevelde(at)ua(dot)ac(dot)be>, pgsql-general(at)postgresql(dot)org
Subject: Re: Converting timestamps and IP addresses
Date: 2004-02-11 14:41:41
Message-ID: 200402111541.41981.jm@poure.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Le Mercredi 11 Février 2004 12:12, Erwin Van de Velde a écrit :
> If anyone has built such functions already, I'd gladly accept, and you can
> win a line in my thank word ;-)

Dear Erwin,

I built a small centralised database built for Ulogd and ran into the same
questions. You can either use implicit or explicit CASTs:

SELECT '192.168.0.3'::inet AS myexplicitcast
will convert a string into an inet

Sometimes, when you do not have contol over the logging deamon sending queries
(which is the case for example of Ulogd), you may be obliged to use implicit
CASTs (a solution described in PostgreSQL bits):

CREATE OR REPLACE FUNCTION ulog_timecast(int4)
RETURNS timestamp AS
'select "timestamp"($1::abstime);'
LANGUAGE 'sql' VOLATILE;

CREATE CAST (int4 AS timestamp)
WITH FUNCTION ulog_timecast(int4)
AS IMPLICIT;

In the end, you may need to add fields to your table and compute the logs when
they are received, using triggers and procedures (better STABLE ones). But
this can slow down logging. You may also prefer to run cron jobs (my volume
is too small for such optimisations). Also, do not forget using partial
indexes.

Using PostgreSQL on a double-athlon server, I can log up to 1000 messages
every second, but I did not try to stress the server too long (it should not
be a problem with partial indexing).

If you are interested in my code, just drop me an email and I will send you
the dump (just a few functions and triggers).

Next week, I plan to use PLbash to be able to send IPTABLES scripts to my
firewall interactively. This could make PostgreSQL one of the only database
able to counter attack on the fly during data acquisition.

Also, in order to write fast server-side applications, do not hesitate to try
pgAdmin III from http://www.pgadmin.org. This will give you direct access to
the list of CASTs. pgAdmin III has a large number of very handy features to
write server-side applications.

Cheers,
Jean-Michel

In response to

Browse pgsql-general by date

  From Date Subject
Next Message scott.marlowe 2004-02-11 15:38:56 Re: DB cache size strategies
Previous Message Bill Gribble 2004-02-11 13:55:46 Re: Join query on 1M row table slow