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 1jJO14-0002rf-BQ for pgsql-hackers@arkaria.postgresql.org; Tue, 31 Mar 2020 21:01:46 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jJO13-0000sM-8u for pgsql-hackers@arkaria.postgresql.org; Tue, 31 Mar 2020 21:01:45 +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 1jJO12-0000qR-Sw for pgsql-hackers@lists.postgresql.org; Tue, 31 Mar 2020 21:01:45 +0000 Received: from mail-qt1-x844.google.com ([2607:f8b0:4864:20::844]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jJO0z-0007jR-Ss for pgsql-hackers@lists.postgresql.org; Tue, 31 Mar 2020 21:01:44 +0000 Received: by mail-qt1-x844.google.com with SMTP id a5so19706399qtw.10 for ; Tue, 31 Mar 2020 14:01:41 -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=iQ6yG1HgUWMZFuoFeCUz3Z6zM+QrQn90ou6vW06uv24=; b=PUQEJY8brUyZUkIpa0Qm2avQ8icooUgmQgDLFQvF1QCKminhngLIuCbeOvlmLIMgyu F43SPISqhoTDPUPQEb/QLfgXqncIWSGD9NXydZtcw5nCa2Ao9bRO5JY8F3w0agyaqQEA CR91LHhRVADYhJgKIbtYE3CVS7Gq26Lc3MEJm6Tv+f/qFWc0lKeYztYFhvW9iw+oxHBa OM5mrhzwb4mjb1/MpJQOsS3obL199B16ppew92R7fs5Alyp2JPkPkX9ZXlap9kjwZrlq 5YOshPrHtiRwmkh9iJCulu5WOw2FwoqKb0UBrvJuPApWdsokrVGh8Hs02kHDVCY8ZJR/ /eIg== 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=iQ6yG1HgUWMZFuoFeCUz3Z6zM+QrQn90ou6vW06uv24=; b=Z68Fd2qkDK+MFvVqLgYEEKrpr0cwz4ORwRWYi6c/NbiiDAHmcH56h5gYMd1lfDozFB L+9Z81/1mu4oa5WaPA/HsFospqluwoTTRlRsPRU8SxJT8Pi/8IbRqr3OFup2bLT2TbUf BNMswz+oKXdj2MwMDg+gob71rJnPq3jVP5U2bJra8GWRkLWqvWmFO35uRMI4j8spC4yc FojDFFERCBPi1+YX0I6oRCocBdQd4mNSCqLGwvbb4WJL+O8IFl86zDylp78kozAAl9Gd FTZDifOdkWXJy5cEy8ryCZt0MqoHsKMS8o/6UatLApqAatjAvNJnZM6iyjnI408rCwjl 1qaQ== X-Gm-Message-State: ANhLgQ2hyqqdQuPDn72f6zkd3XsQDqOidysm86xlc+KVhClz+TlaQMT/ lQyfSLS8CnIEmC9Hsdt9nGfx/A== X-Google-Smtp-Source: ADFU+vuy3IKCgphBqkSe4aNT6PHZI5YrNlghiB4JHCKGNo3gpv1uRdgMDSDn+IgnhWERu1Zk/TBIAA== X-Received: by 2002:ac8:38cc:: with SMTP id g12mr7395638qtc.186.1585688499612; Tue, 31 Mar 2020 14:01:39 -0700 (PDT) Received: from nimloth.alvh.no-ip.org ([190.95.18.252]) by smtp.gmail.com with ESMTPSA id c12sm40057qtb.49.2020.03.31.14.01.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Mar 2020 14:01:39 -0700 (PDT) Received: by nimloth.alvh.no-ip.org (Postfix, from userid 1000) id D08313009FE; Tue, 31 Mar 2020 18:01:36 -0300 (-03) Date: Tue, 31 Mar 2020 18:01:36 -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: <20200331210136.GA6633@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20200331195905.GA20488@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 I noticed some other things: 1. KeepLogSeg sends a warning message when slots fall behind. To do this, it searches for "the most affected slot", that is, the slot that lost the most data. But it seems to me that that's a bit pointless; if a slot data, it's now useless and anything that was using that slot must be recreated. If you only know what's the most affected slot, it's not possible to see which *other* slots are affected. It doesn't matter if the slot missed one segment or twenty segments or 9999 segments -- the slot is now useless, or it is not useless. I think we should list the slot that was *least* affected, i.e., the slot that lost the minimum amount of segments; then the user knows that all slots that are older than that one are *also* affected. 2. KeepLogSeg ignores slots that are active. I guess the logic here is that if a slot is active, then it'll keep going until it catches up and we don't need to do anything about the used disk space. But that seems a false premise, because if a standby is so slow that it cannot keep up, it will eventually run the master out of diskspace even if it's active all the time. So I'm not seeing the reasoning that makes it useful to skip checking active slots. (BTW I don't think you need to keep that many static variables in that function. Just the slot name should be sufficient, I think ... or maybe even the *pointer* to the slot that was last reported. I think if a slot is behind and it lost segments, we should kill the walsender that's using it, and unreserve the segments. So maybe something like LWLockAcquire( ... ); for (i = 0 ; i < max_replication_slots; i++) { ReplicationSlot *s = &ReplicationSlotCtl->replication_slots[i]; XLogSegNo slotSegNo; XLByteToSeg(s->data.restart_lsn, slotSegNo, wal_segment_size); if (s->in_use) { if (s->active_pid) pids_to_kill = lappend(pids_to_kill, s->active_pid); nslots_affected++; ... ; /* other stuff */ } } LWLockRelease( ... ) /* 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. -- Álvaro Herrera https://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services