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 1pISZZ-0006hK-4r for pgsql-hackers@arkaria.postgresql.org; Thu, 19 Jan 2023 10:55:09 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pISZX-0002N7-Mc for pgsql-hackers@arkaria.postgresql.org; Thu, 19 Jan 2023 10:55:07 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pISZX-0002Mo-B7 for pgsql-hackers@lists.postgresql.org; Thu, 19 Jan 2023 10:55:07 +0000 Received: from mail-oa1-x34.google.com ([2001:4860:4864:20::34]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1pISZU-0000GJ-Cq for pgsql-hackers@postgresql.org; Thu, 19 Jan 2023 10:55:06 +0000 Received: by mail-oa1-x34.google.com with SMTP id 586e51a60fabf-15b9c93848dso2119118fac.1 for ; Thu, 19 Jan 2023 02:55:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=YtJ50lzyK0W/A/4vV/FtYjBeXLiTznSy+Zt4tgFXbTo=; b=PI/kz8zMSJyXuBqaKP9Ei36nNheJz0TUjbIDaMsQHhLGCscvCGjOVluZUO+8dK05JO iBDaEmPYx9r8CRTX3rARHTPhekAZDBNbvIKe0BS8jWjm3k3NzWGebwRlfOxCKk4p+Pv3 8ZBiBkIvvLHV54eiaw/2b/0o2gDtMVBP2nNNNP9yMJ5Qemsl84BBQoKBBrhhsc5IVpQT fQRHo63Dsb3CMrqLzmWx6dOaC6jNFsMv7H3EQWCFzQAL9e6XZc9MjjuXYtuhSy4gSyZB BvzC+j+9GY7WHEqzDIBY3i7G8aGdmyx5tQ+WgyqOOzrVmKAfUbl3Zl7CpnWVimsg/DWy q0Lg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=YtJ50lzyK0W/A/4vV/FtYjBeXLiTznSy+Zt4tgFXbTo=; b=KScOjANl0mU/MGA79lS0pc9z4TtWomCA4e6KhX9ZJyMT5Ml7AZAI6vWAbsmDqNFU24 VtEbglrJy6OV6b94TV1kiFJk+q2OK9lLmvmam+pSDTcgwlr7EvHbmdizPV61LfYyhdB2 w6KeDYiZuRPJNhpH3VNQO5HUHZqvwrHh/AyPptIK0fbPorlBhkBaQSkbOfMXB8tegcvH WTuFshsdGLvXvJyvUQ8/hIIbwDjXrTiuz96gY9I4IcQ8Fki7nUCHIGMQ+on6LpFviQ7R 2f0GJvG3x1kgDuAvHZ5icicQyj9X6PRUMMXJKpr2fFkDGA5ht85oQg+jqz3d0Xb3YvLK BeAg== X-Gm-Message-State: AFqh2kpK9hkBLtk2QkBm0S2n7TUWTf3w9GK4xu9UcwZkUnSqXnlkdHHz E7nr9SmGOGed1uiJqpSuk8YCthCTvb8BghGD0bY= X-Google-Smtp-Source: AMrXdXuqH26uJAsSc8WHP5ekl0ofyx355dsO2QocXJW4MChRbC39sI4L9n5h0JMtjc7Bl1KLHfgjG4SVo4s0UNFPELA= X-Received: by 2002:a05:6870:5154:b0:153:b199:10a with SMTP id z20-20020a056870515400b00153b199010amr1057123oak.160.1674125702219; Thu, 19 Jan 2023 02:55:02 -0800 (PST) MIME-Version: 1.0 References: <20230112.120338.534662300633460797.horikyota.ntt@gmail.com> In-Reply-To: From: vignesh C Date: Thu, 19 Jan 2023 16:24:50 +0530 Message-ID: Subject: Re: Time delayed LR (WAS Re: logical replication restrictions) To: "Takamichi Osumi (Fujitsu)" Cc: Peter Smith , Kyotaro Horiguchi , "Hayato Kuroda (Fujitsu)" , "shveta.malik@gmail.com" , "dilipbalaut@gmail.com" , "amit.kapila16@gmail.com" , "euler@eulerto.com" , "m.melihmutlu@gmail.com" , "andres@anarazel.de" , "marcos@f10.com.br" , "pgsql-hackers@postgresql.org" Content-Type: text/plain; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Thu, 19 Jan 2023 at 12:06, Takamichi Osumi (Fujitsu) wrote: > > Updated the comment and the function call. > > Kindly have a look at the updated patch v17. Thanks for the updated patch, few comments: 1) min_apply_delay was accepting values like '600 m s h', I was not sure if we should allow this: alter subscription sub1 set (min_apply_delay = ' 600 m s h'); + /* + * If no unit was specified, then explicitly add 'ms' otherwise + * the interval_in function would assume 'seconds'. + */ + if (strspn(tmp, "-0123456789 ") == strlen(tmp)) + val = psprintf("%sms", tmp); + else + val = tmp; + + interval = DatumGetIntervalP(DirectFunctionCall3(interval_in, + CStringGetDatum(val), + ObjectIdGetDatum(InvalidOid), + Int32GetDatum(-1))); 2) How about adding current_txn_wait_time in pg_stat_subscription_stats, we can update the current_txn_wait_time periodically, this will help the user to check approximately how much time is left(min_apply_delay - stat value) before this transaction will be applied in the subscription. If you agree this can be 0002 patch. 3) There is one check at parse_subscription_options and another check in AlterSubscription, this looks like a redundant check in case of alter subscription, can we try to merge and keep in one place: /* * The combination of parallel streaming mode and min_apply_delay is not * allowed. */ if (IsSet(supported_opts, SUBOPT_MIN_APPLY_DELAY) && opts->min_apply_delay > 0) { if (opts->streaming == LOGICALREP_STREAM_PARALLEL) ereport(ERROR, errcode(ERRCODE_SYNTAX_ERROR), errmsg("%s and %s are mutually exclusive options", "min_apply_delay > 0", "streaming = parallel")); } if (IsSet(opts.specified_opts, SUBOPT_MIN_APPLY_DELAY)) { /* * The combination of parallel streaming mode and * min_apply_delay is not allowed. */ if (opts.min_apply_delay > 0) if ((IsSet(opts.specified_opts, SUBOPT_STREAMING) && opts.streaming == LOGICALREP_STREAM_PARALLEL) || (!IsSet(opts.specified_opts, SUBOPT_STREAMING) && sub->stream == LOGICALREP_STREAM_PARALLEL)) ereport(ERROR, errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("cannot enable %s for subscription in %s mode", "min_apply_delay", "streaming = parallel")); values[Anum_pg_subscription_subminapplydelay - 1] = Int64GetDatum(opts.min_apply_delay); replaces[Anum_pg_subscription_subminapplydelay - 1] = true; } 4) typo "execeeds" should be "exceeds" + time on the subscriber. Any overhead of time spent in logical decoding + and in transferring the transaction may reduce the actual wait time. + It is also possible that the overhead already execeeds the requested + min_apply_delay value, in which case no additional + wait is necessary. If the system clocks on publisher and subscriber + are not synchronized, this may lead to apply changes earlier than Regards, Vignesh