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 1p7zZF-0007Sv-DU for pgsql-hackers@arkaria.postgresql.org; Wed, 21 Dec 2022 13:55:33 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1p7zZC-0003fW-Er for pgsql-hackers@arkaria.postgresql.org; Wed, 21 Dec 2022 13:55:30 +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 1p7zZC-0003fN-32 for pgsql-hackers@lists.postgresql.org; Wed, 21 Dec 2022 13:55:30 +0000 Received: from mail-oa1-x31.google.com ([2001:4860:4864:20::31]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1p7zZ4-0000LY-MF for pgsql-hackers@lists.postgresql.org; Wed, 21 Dec 2022 13:55:29 +0000 Received: by mail-oa1-x31.google.com with SMTP id 586e51a60fabf-142b72a728fso19217931fac.9 for ; Wed, 21 Dec 2022 05:55:22 -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=t10lG3dTvOTSbisnfGsKWLP4flM+KacX1aXPlanLQsE=; b=aod+SPcBa3ERUaGD222mgnw66zOp18DEkt+6FDzNwsSntZR2qHKaQN+tRGE4GhESxL 4f4k2VbKBVSgNuaJE70Go8J+S+HAgKZgujBiwcikfhrksJLXxo+/1Nx1sY35vzVOiaUi IFad9FQyfT4idLhUAAk6Ww5oz3EpBuwI1DST4Ud/adkPHYe7KxgqAhtX8QQC3h2UDp8I STwKpepzs4uPdo1sgKHQMYqepwypWsfcILALMXQAmMRHGBGyUmIavPOnfH/6EEH7y6Nx WB3XQnKnUSgU3XcDO5zWBPPb3uyDc5E8dA4MhfsvHVtRF6x4NntGB1GM4dRuk0dWqTEu A81g== 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=t10lG3dTvOTSbisnfGsKWLP4flM+KacX1aXPlanLQsE=; b=ag+1ZTgvhTNm2UPcwuAgOZRH2GLjUHdy6rdwTOUqdZy+c7iYDCKIoI7K8UMEwtF5xc hMpt0DpY+hu8vmRvMAfwtETI5VOyxmdDTzef/0Ro0EHCsNPV+1TzQ6CIKSYTQnPuWG75 Yh11aIJLJ5WBon1UdnZ6JgY3BVNRVHjycm87F6xLD5LPyecOC9le0Aq9fYhQJ3R/D4JN lcuHVqvPoZed7PreCOyyQvaJuR9DqbVyhMe2/PXOC4VR/sdViGtHvi4dfv68pnhYazU/ iEFQML+ACeAwPYqIOIszocegT8kTTHcwxcbS4gzJ+njSStR9TPY+TzfRpAjfm1cFVpap Sxcg== X-Gm-Message-State: AFqh2kqZWhYHjF4lm2sYCJDjOv/JLef2r2s1TtsqwtsVjH3mgBSrNmuc u+lF/Czp8ADwQySyUncvy4aCTLVEfqcIgggpwbk= X-Google-Smtp-Source: AMrXdXte41wMdI7sUt1Chv9GedbDO9pdArOt009EuVDt0OcCjhJ2x5nlSZhn2ErI77jn0/fSgBYvyopmLwFGXZ+u3tI= X-Received: by 2002:a05:6870:c4b:b0:143:74c2:f928 with SMTP id lf11-20020a0568700c4b00b0014374c2f928mr135886oab.64.1671630920277; Wed, 21 Dec 2022 05:55:20 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Masahiko Sawada Date: Wed, 21 Dec 2022 22:54:44 +0900 Message-ID: Subject: Re: Force streaming every change in logical decoding To: "shiy.fnst@fujitsu.com" Cc: Amit Kapila , Peter Smith , "Hayato Kuroda (Fujitsu)" , Dilip Kumar , PostgreSQL Hackers Content-Type: text/plain; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Wed, Dec 21, 2022 at 10:14 PM shiy.fnst@fujitsu.com wrote: > > On Wed, Dec 21, 2022 4:54 PM Amit Kapila wrote: > > > > On Wed, Dec 21, 2022 at 1:55 PM Peter Smith > > wrote: > > > > > > On Wed, Dec 21, 2022 at 6:22 PM Masahiko Sawada > > wrote: > > > > > > > > On Tue, Dec 20, 2022 at 7:49 PM Amit Kapila > > wrote: > > > > > > > > > > On Tue, Dec 20, 2022 at 2:46 PM Hayato Kuroda (Fujitsu) > > > > > wrote: > > > > > > > > > > > > Dear hackers, > > > > > > > > > > > > > We have discussed three different ways to provide GUC for these > > > > > > > features. (1) Have separate GUCs like force_server_stream_mode, > > > > > > > force_server_serialize_mode, force_client_serialize_mode (we can > > use > > > > > > > different names for these) for each of these; (2) Have two sets of > > > > > > > GUCs for server and client. We can have logical_decoding_mode with > > > > > > > values as 'stream' and 'serialize' for the server and then > > > > > > > logical_apply_serialize = true/false for the client. (3) Have one GUC > > > > > > > like logical_replication_mode with values as 'server_stream', > > > > > > > 'server_serialize', 'client_serialize'. > > > > > > > > > > > > I also agreed for adding new GUC parameters (and I have already done > > partially > > > > > > in parallel apply[1]), and basically options 2 made sense for me. But is > > it OK > > > > > > that we can choose "serialize" mode even if subscribers require > > streaming? > > > > > > > > > > > > Currently the reorder buffer transactions are serialized on publisher > > only when > > > > > > the there are no streamable transaction. So what happen if the > > > > > > logical_decoding_mode = "serialize" but streaming option streaming is > > on? If we > > > > > > break the first one and serialize changes on publisher anyway, it may > > be not > > > > > > suitable for testing the normal operation. > > > > > > > > > > > > > > > > I think the change will be streamed as soon as the next change is > > > > > processed even if we serialize based on this option. See > > > > > ReorderBufferProcessPartialChange. However, I see your point that > > when > > > > > the streaming option is given, the value 'serialize' for this GUC may > > > > > not make much sense. > > > > > > > > > > > Therefore, I came up with the variant of (2): logical_decoding_mode > > can be > > > > > > "normal" or "immediate". > > > > > > > > > > > > "normal" is a default value, which is same as current HEAD. Changes > > are streamed > > > > > > or serialized when the buffered size exceeds > > logical_decoding_work_mem. > > > > > > > > > > > > When users set to "immediate", the walsenders starts to stream or > > serialize all > > > > > > changes. The choice is depends on the subscription option. > > > > > > > > > > > > > > > > The other possibility to achieve what you are saying is that we allow > > > > > a minimum value of logical_decoding_work_mem as 0 which would > > mean > > > > > stream or serialize each change depending on whether the streaming > > > > > option is enabled. I think we normally don't allow a minimum value > > > > > below a certain threshold for other *_work_mem parameters (like > > > > > maintenance_work_mem, work_mem), so we have followed the same > > here. > > > > > And, I think it makes sense from the user's perspective because below > > > > > a certain threshold it will just add overhead by either writing small > > > > > changes to the disk or by sending those over the network. However, it > > > > > can be quite useful for testing/debugging. So, not sure, if we should > > > > > restrict setting logical_decoding_work_mem below a certain threshold. > > > > > What do you think? > > > > > > > > I agree with (2), having separate GUCs for publisher side and > > > > subscriber side. Also, on the publisher side, Amit's idea, controlling > > > > the logical decoding behavior by changing logical_decoding_work_mem, > > > > seems like a good idea. > > > > > > > > But I'm not sure it's a good idea if we lower the minimum value of > > > > logical_decoding_work_mem to 0. I agree it's helpful for testing and > > > > debugging but setting logical_decoding_work_mem = 0 doesn't benefit > > > > users at all, rather brings risks. > > > > > > > > I prefer the idea Kuroda-san previously proposed; setting > > > > logical_decoding_mode = 'immediate' means setting > > > > logical_decoding_work_mem = 0. We might not need to have it as an > > enum > > > > parameter since it has only two values, though. > > > > > > Did you mean one GUC (logical_decoding_mode) will cause a side-effect > > > implicit value change on another GUC value > > > (logical_decoding_work_mem)? > > > > > > > I don't think that is required. The only value that can be allowed for > > logical_decoding_mode will be "immediate", something like we do for > > recovery_target. The default will be "". The "immediate" value will > > mean that stream each change if the "streaming" option is enabled > > ("on" of "parallel") or if "streaming" is not enabled then that would > > mean serializing each change. > > > > I agreed and updated the patch as Amit suggested. > Please see the attached patch. > The patch looks good to me. Some minor comments are: - * limit, but we might also adapt a more elaborate eviction strategy - for example - * evicting enough transactions to free certain fraction (e.g. 50%) of the memory - * limit. + * limit, but we might also adapt a more elaborate eviction strategy - for + * example evicting enough transactions to free certain fraction (e.g. 50%) of + * the memory limit. This change is not relevant with this feature. --- + if (logical_decoding_mode == LOGICAL_DECODING_MODE_DEFAULT + && rb->size < logical_decoding_work_mem * 1024L) Since we put '&&' before the new line in all other places in reorderbuffer.c, I think it's better to make it consistent. The same is true for the change for while loop in the patch. Regards, -- Masahiko Sawada Amazon Web Services: https://aws.amazon.com