Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1slpSc-001R5p-6y for pgsql-general@arkaria.postgresql.org; Wed, 04 Sep 2024 12:50:10 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1slpSZ-0099UO-FK for pgsql-general@arkaria.postgresql.org; Wed, 04 Sep 2024 12:50:07 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1slpSZ-0099UG-4g for pgsql-general@lists.postgresql.org; Wed, 04 Sep 2024 12:50:07 +0000 Received: from mail-yb1-xb34.google.com ([2607:f8b0:4864:20::b34]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1slpSS-0007Ue-Qg for pgsql-general@lists.postgresql.org; Wed, 04 Sep 2024 12:50:06 +0000 Received: by mail-yb1-xb34.google.com with SMTP id 3f1490d57ef6-e1651f48c31so6856192276.0 for ; Wed, 04 Sep 2024 05:50:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725454199; x=1726058999; darn=lists.postgresql.org; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=uYeglGjejQCN05sqgg2LR5KDw4lZ2J5leWofosNZnQY=; b=CaDmJFdRoPSZ4xzj9O27dyTpbwif5SA7QLIW9svtCNvdcnxMk0ysRAoL0RQ4hiCj6p Ht6dHoHWMUX33vP4h0DU8tVFGFwpWp5iSy+sv7Kj3uyxxAVZHv5HkVsKjuQAkfa2WKGj 5G6PBIBy9aZ3wtiIggd01IJIoarjCy+vP3haRb1xNqOzgbxt7imVdyMAG7ZtsbU/y5Ea +0qxV9ljzHMZDi8Cdbzt3rj/yIpbPCHISmgujVr5M6pYHqxlKJYwP+vfVNiJs4aRtEhq AOJk7SOIjPZLCttvZkYVpHMSvndAlTPBCDxk3DjbjlWG8P9I3kltwjNTLsMTpRuaal3B aMPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725454199; x=1726058999; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=uYeglGjejQCN05sqgg2LR5KDw4lZ2J5leWofosNZnQY=; b=jOYSc3eVOGbW1kSjHabKvoucTAZEaqMkwr3cxGjEd5eARRjOpLOSWiaDzsMO5KMWW0 CJYfBzcN4Dvg3mTRIDTs7psJZvetJZ3YAZ6VwMXlZaP2SqZV+JBiBFjOJ9EP1XdcJlw7 W5M7bbRg6m3qlarkKqD+UaaliJEbbz10EO9MGiv8+V28rpZsvgZAY71btBL+dJRDiB5/ E6pW7F19n0f0/ArMuy+O5TpZrnTnvgSwRImrXOZhXXntnWzXZdtLJ2mOqnJD6ftJobGT Ww05Wd6meHqJgVL4U6ADVpIIwXlYfS1WFSKGQh14b5bF51dtW1gD6tRyLdVm2mvttR7Y 5isw== X-Gm-Message-State: AOJu0YzWLhK6/fH+bYJWOCM/457MP8C3bVzpxmR3XFjRVUr3HD57mMC/ bQNwyxZa2NV7WIkEEKDiu4i5Vb9t/Pw0+iAJxL5Pn6nQ22fOT8Elu17Tz4hAi8vQ9L+lSmfMJfz 7j3B/qup8euU16jEw8lYRlgivAdwUuIaT X-Google-Smtp-Source: AGHT+IEIxHWEbZ341XD6vBlD8dVOv88IvqvPIPgaB0WDdkDa6sgDNoETtjWkWrSuHLvmAjCHv1MQUg5bt+DsotCGZXU= X-Received: by 2002:a05:6902:2e0e:b0:e1a:a721:dd36 with SMTP id 3f1490d57ef6-e1aa721e281mr11970902276.43.1725454198996; Wed, 04 Sep 2024 05:49:58 -0700 (PDT) MIME-Version: 1.0 From: yudhi s Date: Wed, 4 Sep 2024 18:19:47 +0530 Message-ID: Subject: question on audit columns To: pgsql-general Content-Type: multipart/alternative; boundary="0000000000009b905406214a9ca4" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --0000000000009b905406214a9ca4 Content-Type: text/plain; charset="UTF-8" Hello, In postgres database , we have all the tables with audit columns like created_by_user, created_timestamp,updated_by_user, updated_timestamp. So we have these fields that were supposed to be populated by the time at which the insert/update operation happened on the database but not at the application level. So we are planning to populate the created_by_user, created_timestamp columns by setting a default value of "current_timestamp" and "current_user" for the two columns, but no such this is available to populate while we do the update of the row, so the only option seems to be through a trigger. So wanted to check with the experts here ,considering the table will be DML heavy table (300M+ transactions will be inserted daily), Is is okay to have the trigger for this table for populating all the audit columns or should we keep default for created_by_user, created_timestamp and just trigger for the update related two audit column? Basically wanted to see, if the default value does the same thing as a trigger or it does something more optimally than trigger? Regards Yudhi --0000000000009b905406214a9ca4 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hello,
In postgres database , we have all the tables w= ith audit columns like created_by_user, created_timestamp,updated_by_user, = updated_timestamp. So we have these=C2=A0fields that were supposed to be po= pulated by the time at which the insert/update operation happened on the da= tabase but not at the application level. So we are planning=C2=A0to populat= e the created_by_user, created_timestamp columns by setting a default value= of "current_timestamp" and "current_user" for the two = columns,=C2=A0 but no such this is available to populate while we do the up= date of the row, so the only option seems=C2=A0to be through a trigger.=C2= =A0

So wanted to check with the experts here=C2=A0= ,considering the table will be DML heavy table (300M+ transactions will be= inserted daily), Is is okay to have the trigger for this table for populat= ing all the audit columns=C2=A0or should=C2=A0we keep default for=C2=A0 cre= ated_by_user, created_timestamp and just trigger for the update related two= audit column? Basically wanted to see, if the default value does the same = thing as a trigger or it does something more optimally than trigger?
<= div>
Regards
Yudhi
--0000000000009b905406214a9ca4--