Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lvCEu-000784-C5 for pgsql-hackers@arkaria.postgresql.org; Mon, 21 Jun 2021 05:12:52 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lvCEs-0003ZI-Kw for pgsql-hackers@arkaria.postgresql.org; Mon, 21 Jun 2021 05:12:50 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lvCEs-0003ZA-AQ for pgsql-hackers@lists.postgresql.org; Mon, 21 Jun 2021 05:12:50 +0000 Received: from mail-pg1-x534.google.com ([2607:f8b0:4864:20::534]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1lvCEp-0005XK-V4 for pgsql-hackers@lists.postgresql.org; Mon, 21 Jun 2021 05:12:49 +0000 Received: by mail-pg1-x534.google.com with SMTP id e20so13230562pgg.0 for ; Sun, 20 Jun 2021 22:12:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=enterprisedb-com.20150623.gappssmtp.com; s=20150623; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=IUKwmhPq04FrfX3JyRaiIfm6n7+3tDhFHF/2HrYwQAc=; b=Fran75DUcNzQqDGGvSnbFyO5eMcy9Jh2HHp1dxQPMomQRQ6KOuHMDKmbPKQc2hIOjs URIZcr742Vlf8DWpmXnsmg5mYdb7O5W4M2LDxZY9hPpo8IGZDgL1lCHHBj6ZChcB8qxx dg9B4XOt2IG+a7RGWdhWj5/U3/I9qx5wLTE+b6Bcue7od0bcqcQrW+sDo0VHTYzPg14R obWRoE4+G5mAKaQYxs1ApIcTyQF4w5ShxxfRzgFS7jUrwXo2lKphpE7r3F8e/y8NDfQA WVMDglNpgL7cQW97f7IIRCkSVFH/ifgEoHllEwyhOwQRzNVLbKTBN0MtlP/wPNqKkSs5 UNqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=IUKwmhPq04FrfX3JyRaiIfm6n7+3tDhFHF/2HrYwQAc=; b=uXPbNArfRB8ZMDVugU/1kN8a78U7cWRZdTroXtC2lCLQxijDJ1te/Ec/8Ha0SE/jko P29isDkUPH8LubGCPr2YT+uhXGMte9ZAbAwQ1GqXJVJ1k0TefWJqLKBwei/qAXylak8o 12l/rxkWW0RJcQ3nWCtKpD4ZgSk9qZWY4cjimhRd+0h51IInEb2kIlWKf1pIZ+R2K2zl Qq87UROkEv8b9pJu50s862E8+08uaTVv6APPZVTyo+Mx03AQPXPuoJ8d4cjn2cZcR4XR KhTl1k28XEdTnQI8E0Ipjn3awKIzUrrbXMPqaW/Yl7iEbQGaEMPJLgHvDVDi+UWYISi9 738Q== X-Gm-Message-State: AOAM532QJEyWX07xgtap9jOSM6EX5+PM9/85e/jj0LubT3ZsGep0yYhD zntcdALngt4pNkgqmjug6muQwbrAw6SDGYmsHriBKjQnTWih/eQzpfNg8JTNeeDbdFzaXaJLYET 8G+gsDpOX/cZXvGB09t0oI4JYHlJzy5q+YpEoRobpo4n6zRNzHX1hqH1jK922qx1D0/ed0OKOpu dDovIzeCj+FiEEIKap2/DyyL88N2ZFlZw+WLOfu64FdsrQC9wboKrb X-Google-Smtp-Source: ABdhPJwMd5I9ajN5dDbpN6mvhpnA6UibKjf1k3PubUUOo4RynC8GZyxvgPAWqOLOrkwiP+z7OOYahw== X-Received: by 2002:a62:87ca:0:b029:303:1dd3:572 with SMTP id i193-20020a6287ca0000b02903031dd30572mr4297368pfe.33.1624252366738; Sun, 20 Jun 2021 22:12:46 -0700 (PDT) Received: from ?IPv6:2600:6c50:157f:eb87:312a:3853:88ca:1561? ([2600:6c50:157f:eb87:312a:3853:88ca:1561]) by smtp.gmail.com with ESMTPSA id y66sm4020223pgb.4.2021.06.20.22.12.45 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 20 Jun 2021 22:12:46 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.120.23.2.6\)) Subject: Re: Optionally automatically disable logical replication subscriptions on error From: Mark Dilger In-Reply-To: Date: Sun, 20 Jun 2021 22:12:44 -0700 Cc: Masahiko Sawada , "Smith, Peter" , PostgreSQL Hackers Content-Transfer-Encoding: quoted-printable Message-Id: <0DABB861-BE21-4138-A0D4-5C561F51CD19@enterprisedb.com> References: To: Amit Kapila X-Mailer: Apple Mail (2.3608.120.23.2.6) X-CLOUD-SEC-AV-Info: enterprisedb,google_mail,monitor X-CLOUD-SEC-AV-Sent: true X-Gm-Spam: 0 X-Gm-Phishy: 0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > On Jun 20, 2021, at 8:09 PM, Amit Kapila = wrote: >=20 > (a) to define exactly what all > information is required to be logged on error, (b) where do we want to > store the information based on requirements. I'm not sure it has to be stored anywhere durable. I have a patch in = the works to do something like: create function foreign_key_insert_violation_before() returns = conflict_trigger as $$ BEGIN RAISE NOTICE 'elevel: %', TG_ELEVEL: RAISE NOTICE 'sqlerrcode: %', TG_SQLERRCODE: RAISE NOTICE 'message: %', TG_MESSAGE: RAISE NOTICE 'detail: %', TG_DETAIL: RAISE NOTICE 'detail_log: %', TG_DETAIL_LOG: RAISE NOTICE 'hint: %', TG_HINT: RAISE NOTICE 'schema: %', TG_SCHEMA_NAME: RAISE NOTICE 'table: %', TG_TABLE_NAME: RAISE NOTICE 'column: %', TG_COLUMN_NAME: RAISE NOTICE 'datatype: %', TG_DATATYPE_NAME: RAISE NOTICE 'constraint: %', TG_CONSTRAINT_NAME: -- do something useful to prepare for retry of transaction -- which raised a foreign key violation END $$ language plpgsql; create function foreign_key_insert_violation_after() returns = conflict_trigger as $$ BEGIN -- do something useful to cleanup after retry of transaction -- which raised a foreign key violation END $$ language plpgsql; create conflict trigger regress_conflict_trigger_insert on = regress_conflictsub before foreign_key_violation when tag in ('INSERT') execute procedure foreign_key_insert_violation_before(); create conflict trigger regress_conflict_trigger_insert on = regress_conflictsub after foreign_key_violation when tag in ('INSERT') execute procedure foreign_key_insert_violation_after(); The idea is that, for subscriptions that have conflict triggers defined, = the apply will be wrapped in a PG_TRY()/PG_CATCH() block. If it fails, = the ErrorData will be copied in the ConflictTriggerContext, and then the = transaction will be attempted again, but this time with any BEFORE and = AFTER triggers applied. The triggers could then return a special result = indicating whether the transaction should be permanently skipped, = applied, or whatever. None of the data needs to be stored anywhere = non-transient, as it just gets handed to the triggers. I think the other patch is a subset of this functionality, as using this = system to create triggers which query a table containing transactions to = be skipped would be enough to get the functionality you've been = discussing. But this system could also do other things, like modify = data. Admittedly, this is akin to a statement level trigger and not a = row level trigger, so a number of things you might want to do would be = hard to do from this. But perhaps the equivalent of row level triggers = could also be written? =E2=80=94 Mark Dilger EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company