X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 8CF7A53691 for ; Wed, 4 May 2005 01:45:06 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 81402-05 for ; Wed, 4 May 2005 04:44:56 +0000 (GMT) Received: from ausimss.pervasive.com (ausimss.pervasive.com [66.45.103.246]) by svr1.postgresql.org (Postfix) with ESMTP id 4B6305355E for ; Wed, 4 May 2005 01:44:54 -0300 (ADT) Received: from ausbayes1.aus.pervasive.com ([172.16.8.6]) by ausimss.pervasive.com with InterScan Messaging Security Suite; Tue, 03 May 2005 23:44:53 -0500 Received: from BLRMAIL1.aus.pervasive.com ([10.3.16.60]) by ausbayes1.aus.pervasive.com with Microsoft SMTPSVC(5.0.2195.6713); Tue, 3 May 2005 23:44:50 -0500 content-class: urn:content-classes:message Subject: Re: Record Log Trigger Date: Wed, 4 May 2005 10:14:38 +0530 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Message-ID: <02767D4600E59A4487233B23AEF5C5992A4084@blrmail1.aus.pervasive.com> X-MS-Has-Attach: X-MimeOLE: Produced By Microsoft Exchange V6.0.6603.0 X-MS-TNEF-Correlator: Thread-Topic: [SQL] Record Log Trigger Thread-Index: AcVP3FHkNccTG6gBSEi+Qj+CbgHEoAAhkm1A From: "Ramakrishnan Muralidharan" To: , "CHRIS HOOVER" Cc: X-OriginalArrivalTime: 04 May 2005 04:44:52.0913 (UTC) FILETIME=[031D4A10:01C55064] X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.083 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200505/69 X-Sequence-Number: 21382 Hi, I do not think there is a performance issue due trigger on a larger = database. For improving performance, it is better to write triggers for = Insert, update, delete separately rather than combining them on a single = trigger. Periodic VACCUM and RE-INDEX the table will improve the performance.=20 Regards, R.Muralidharan -----Original Message----- From: pgsql-sql-owner@postgresql.org [mailto:pgsql-sql-owner@postgresql.org]On Behalf Of lucas@presserv.org Sent: Tuesday, May 03, 2005 5:45 PM To: CHRIS HOOVER Cc: pgsql-sql@postgresql.org Subject: Re: [SQL] Record Log Trigger Well... Right, I will use to_timestamp() function instead of now() function. But, what is the performance for those Triggers??? Considering that all = tables will have this Trigger and will check for each update or insert. Thanks Quoting CHRIS HOOVER : > One change you might want to look at is not using the now() function. > According to the docs, the now() function always returns the start of = the > transaction time. So, if your code is using transaction blocks, the = time may > not be what you are expecting. > > This is what I had do to in my trigger to get the current clock time: > to_char(to_timestamp(timeofday(),\'Dy Mon DD HH24:MI:SS.US YYYY\') > > > HTH, > > Chris > ------------------( Forwarded letter 1 follows )--------------------- > Date: Mon, 02 May 2005 16:10:46 -0300 > To: pgsql-sql@postgresql.org.comp > From: lucas@presserv.org.comp > Sender: pgsql-sql-owner+m21335@postgresql.org.comp > Subject: [SQL] Record Log Trigger > > Hi all, > I am building a database in postgresql and I made a function that = returns the > system time and the current user... like this: > > CREATE OR REPLACE FUNCTION generate_idx() returns text as > $$ > select to_char(now(),'YYYYMMDDHHMISSUSTZ')||CURRENT_USER; > $$ language 'SQL'; > > CREATE OR REPLACE FUNCTION TG_idxm() RETURNS trigger AS > $$ > BEGIN > NEW.idxm =3D generate_idx(); > RETURN NEW; > END; > $$ LANGUAGE plpgsql; > > And my all tables have the "idxm" field, its something like a log for = the > record, to know Who and When the record have changed. I.e: > > CREATE TABLE products( > id serial primary key, > description varchar(50), > ... > idxm varchar(100) > ); > CREATE TRIGGER TG_products_idxm BEFORE INSERT or UPDATE on products=20 > FOR EACH ROW > EXECUTE PROCEDURE TG_idxm(); > > Okay, it runs fine... but my question is: > Is it right??? In the future (when the database will be bigger with = many of > millions records) this functions for each table will depreceate my = database > performance??? > Is there any other way to build it??? > > Thank you > > ---------------------------(end of = broadcast)--------------------------- > TIP 5: Have you checked our extensive FAQ? > > http://www.postgresql.org/docs/faq > ---------------------------(end of broadcast)--------------------------- TIP 2: you can get off all lists at once with the unregister command (send "unregister YourEmailAddressHere" to majordomo@postgresql.org)