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 1rPoXT-00ELwE-50 for pgsql-general@arkaria.postgresql.org; Tue, 16 Jan 2024 18:51:55 +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 1rPoXR-006RbV-Ui for pgsql-general@arkaria.postgresql.org; Tue, 16 Jan 2024 18:51:53 +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 1rPoXR-006RbM-K8 for pgsql-general@lists.postgresql.org; Tue, 16 Jan 2024 18:51:53 +0000 Received: from mail-oo1-xc2d.google.com ([2607:f8b0:4864:20::c2d]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rPoXP-002A7x-0i for pgsql-general@lists.postgresql.org; Tue, 16 Jan 2024 18:51:52 +0000 Received: by mail-oo1-xc2d.google.com with SMTP id 006d021491bc7-5986cb7bb61so4403085eaf.2 for ; Tue, 16 Jan 2024 10:51:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1705431109; x=1706035909; darn=lists.postgresql.org; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=FG2Q+RI0uf4hc2hsbhGNiMMUHTclBwJuWpEEtqvCWL0=; b=RURgraDh++wXSnUZYQeWEdj7flf/9tpoqm/sePgv/UwjXyYor9eCC/8UefBlNHRkWD zA3AXnEYlDDrb+JhvJLP0tsSfDmWq/VTHXhW/KM+i5EZCTLipkTKj1WCOPZJ6IuKg03g gOJyypmOT61emCanpreLzBYlZ0+5TIfMXCOEGODtIN15zLm8cKf66a13IR8dmmb/YeVB JiZtWlLwB36k6BvXIH1bwr3QB8c/FG5kL09BylVi2Ix1BzJrHEUNP6Ji3NlfOPtXWyEY LbKDSgV1uR/Cn8Jeq2haJMDczinMPZ8egunGtNjea6g3SziKCAtPhxPrRsK5Qy9xULLF h1AA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705431109; x=1706035909; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=FG2Q+RI0uf4hc2hsbhGNiMMUHTclBwJuWpEEtqvCWL0=; b=USSvKxQYrbvXbw6AvlV1Y29TQM1LURZNS/WTz/TA9R0SIZhjbylmtJiY3+ShiGbCDM qlgTw9YZsNYhkvxLbV+De0Ofb8fvt/jnmDAnL/2ilE3gt9nkT+fNylxgpjDHu9XlOoRy F7LcBryRkI35iGGxCoiB1Du4Sm0qCyXHBXO9K6qXQ5Zatc/pFrZRnXgmzDBS12BNHjT7 7xBVWio+dNvd6BMcxVy9lCK5qFs9hY5kyP1XJaoIkhZSEvdOv9YjMIw9aBRXwYWFdsHr lmd8RmvISqAgfznGOZiepQkDQgBBQF68vstUpa8EVWco9NSCXq6nkiXDtS+8Tn7V6dWz L/UA== X-Gm-Message-State: AOJu0YyqSWCQ7fhg6ssEVREYAliKZh9Aq3UcjcV2+LjbmCddRMaE1rqa PKrdXhDGHQEU96kciCSyug== X-Google-Smtp-Source: AGHT+IEHRPTgW1t08C5PEFMo/9K4TkB2jcoLa6jInTTibNZsBWONDlkpb8gdgzJDGE0pNV0hX3JUuQ== X-Received: by 2002:a4a:dfd6:0:b0:598:8915:50ba with SMTP id p22-20020a4adfd6000000b00598891550bamr4343435ood.10.1705431108873; Tue, 16 Jan 2024 10:51:48 -0800 (PST) Received: from [192.168.2.16] (070-113-014-216.res.spectrum.com. [70.113.14.216]) by smtp.gmail.com with ESMTPSA id v8-20020a4aad88000000b00594ee4b4339sm2120040oom.28.2024.01.16.10.51.47 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 16 Jan 2024 10:51:48 -0800 (PST) Message-ID: <7e8f8a71-c7dc-4625-9d96-5e4f81540e01@gmail.com> Date: Tue, 16 Jan 2024 12:51:44 -0600 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: What should I expect when creating many logical replication slots? Content-Language: en-US To: Antonin Bas , pgsql-general@lists.postgresql.org References: From: Jim Nasby In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 1/11/24 6:17 PM, Antonin Bas wrote: > Hi all, > > I have a use case for which I am considering using Postgres Logical > Replication, but I would like to scale up to 100 or even 200 > replication slots. > > I have increased max_wal_senders and max_replication_slots to 100 (also > making sure that max_connections is large enough). Things seem to be > working pretty well so far based on some PoC code I have written. > Postgres is creating a walsender process for each replication slot, as > expected, and the memory footprint of each one is around 4MB. > > So I am quite happy with the way things are working, but I am a bit > uneasy about increasing these configuration values by 10-20x compared to > their defaults (both max_wal_senders and max_replication_slots default > to 10). > > Is there anything I should be looking out for specifically? Is it > considered an anti-pattern to use that many replication slots and > walsender processes? And, when my database comes under heavy write load, > will walsender processes start consuming a large amount of CPU / memory > (I recognize that this is a vague question, I am still working on some > empirical testing). The biggest issue with logical decoding (what drives logical replication) is that every subscriber has to completely decode everything for it's publication, which can be extremely memory intensive under certain circumstances (long running transacitons being one potential trigger). Decoders also have to read through all WAL traffic, regardless of what their publication is set to - everything runs of the single WAL stream. Note that this only applies to actually decoding - simply having a large number of slots isn't much of an issue. Even having a large number of subscribers that aren't consuming isn't a resource issue (though it IS an issue for MVCC / vacuuming!) - to test you need to have all the decoders that you expect to support. Ultimately, I'd be concerned with trying to support 100+ slots unless you know that your change rate isn't super high and that you don't have long-running transactions. -- Jim Nasby, Data Architect, Austin TX