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 1jJOyR-0002eO-LN for pgsql-hackers@arkaria.postgresql.org; Tue, 31 Mar 2020 22:03:07 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jJOyO-0005v4-U6 for pgsql-hackers@arkaria.postgresql.org; Tue, 31 Mar 2020 22:03:04 +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 1jJOyO-0005ux-Ix for pgsql-hackers@lists.postgresql.org; Tue, 31 Mar 2020 22:03:04 +0000 Received: from mail-qk1-x743.google.com ([2607:f8b0:4864:20::743]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jJOyL-0008Gt-Bw for pgsql-hackers@lists.postgresql.org; Tue, 31 Mar 2020 22:03:03 +0000 Received: by mail-qk1-x743.google.com with SMTP id u4so24857324qkj.13 for ; Tue, 31 Mar 2020 15:03:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :content-transfer-encoding:in-reply-to:user-agent; bh=11Us0+FtRO+TPsch0CjL6opUigvwwYas9OcxUsXYipc=; b=RMoV0gtlBMqnLJWSI5IzkPVGHFAjiJR7VPFzbnWfWu2GY3TZrL5ICgotB/KDN+mPz3 AHnVNxP+Cx/n7tV1UgSyjpWTbYgIqB5KTVgmiW8hbphOdteyyjNKbBIWbV7WtVCpAMko +4Viv5h5AsbH5k0XEuzccKHmaZNfOy6oO7EXOfVicL5MPc4yGYtwi2treCZdh4npx0U+ B8o+YTBLul0ijNtnEIdjX9sZBd9dhp7KBqu71GKXu+suIMo/eiK1JAYLHKPgjsCsoYZi jdMPhATVwDAolcEx7dp93H7Vu2gxGponB65ChAEm+L+/LmxZZIUY/DMsYigxFV0BSRmZ cg6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=11Us0+FtRO+TPsch0CjL6opUigvwwYas9OcxUsXYipc=; b=khqZCFIp0OTbhDoc95Sv99/t3qWi6QwxklN0uEV+E7bRIhiZqF79xL9p1JG2M96sHQ TGxSfWhS6PYm3eBXQLyq43FNIgl/zMYeHxu+2wVBpMnb84I2mTqQaJmjfvHG+F/lbqx1 lqr0Nv1++vWWtGWellkR++BHX7aC6XQ6IRAUlINv9S1X29Ps9wYogGHa79kseGdAsRXX doRUX7J2TeGymuzBnw67gpbg6AHwuOqTQD+q5O0S2YmelIRthcm8n+YuARiNQBqKWWlQ 4lZpLLx64qiUvuAUTle/acyGmE/lnOE5cKB6XPUTO9NKzrkSqRRJKlWF/DBWEe5Akri3 cuzg== X-Gm-Message-State: ANhLgQ2biQoPcnEa08dDVFNdUhN3lWXYWItV0bDf/R48B2YoByfwJXYB oBjn9YOL0PXb8LcJHwWA5YxfaA== X-Google-Smtp-Source: ADFU+vsBKDJn6N3GZRgzOz/VPfiOOX27cpNWTXF3SXIzxUl3eF0gb0iKeBRMbPA9EyLfIGzsVnFF5g== X-Received: by 2002:a37:27cf:: with SMTP id n198mr6788128qkn.97.1585692179995; Tue, 31 Mar 2020 15:02:59 -0700 (PDT) Received: from nimloth.alvh.no-ip.org ([190.95.18.252]) by smtp.gmail.com with ESMTPSA id t53sm131962qth.70.2020.03.31.15.02.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Mar 2020 15:02:59 -0700 (PDT) Received: by nimloth.alvh.no-ip.org (Postfix, from userid 1000) id 697DF3009FE; Tue, 31 Mar 2020 19:02:57 -0300 (-03) Date: Tue, 31 Mar 2020 19:02:57 -0300 From: Alvaro Herrera To: Kyotaro Horiguchi Cc: jgdr@dalibo.com, andres@anarazel.de, michael@paquier.xyz, sawada.mshk@gmail.com, peter.eisentraut@2ndquadrant.com, pgsql-hackers@lists.postgresql.org, thomas.munro@enterprisedb.com, sk@zsrv.org, michael.paquier@gmail.com Subject: Re: [HACKERS] Restricting maximum keep segments by repslots Message-ID: <20200331220257.GA9763@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20200331210136.GA6633@alvherre.pgsql> User-Agent: Mutt/1.10.1 (2018-07-13) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 2020-Mar-31, Alvaro Herrera wrote: > /* release lock before syscalls */ > foreach(l, pids_to_kill) > { > kill(SIGTERM, lfirst_int(l)); > } > > I sense some attempt to salvage slots that are reading a segment that is > "outdated" and removed, but for which the walsender has an open file > descriptor. (This appears to be the "losing" state.) This seems > dangerous, for example the segment might be recycled and is being > overwritten with different data. Trying to keep track of that seems > doomed. And even if the walsender can still read that data, it's only a > matter of time before the next segment is also removed. So keeping the > walsender alive is futile; it only delays the inevitable. I think we should kill(SIGTERM) the walsender using the slot (slot->active_pid), then acquire the slot and set it to some state indicating that it is now useless, no longer reserving WAL; so when the walsender is restarted, it will find the slot cannot be used any longer. Two ideas come to mind about doing this: 1. set the LSNs and Xmins to Invalid; keep only the slot name, database, plug_in, etc. This makes monitoring harder, I think, because as soon as the slot is gone you know nothing at all about it. 2. add a new flag to ReplicationSlotPersistentData to indicate that the slot is dead. This preserves the LSN info for forensics, and might even be easier to code. -- Álvaro Herrera https://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services