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 1jlO0f-000838-6s for pgsql-hackers@arkaria.postgresql.org; Wed, 17 Jun 2020 02:41:05 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jlO0d-0006pq-RC for pgsql-hackers@arkaria.postgresql.org; Wed, 17 Jun 2020 02:41:03 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jlO0d-0006pj-FS for pgsql-hackers@lists.postgresql.org; Wed, 17 Jun 2020 02:41:03 +0000 Received: from mail-qk1-x742.google.com ([2607:f8b0:4864:20::742]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jlO0a-0005QM-95 for pgsql-hackers@lists.postgresql.org; Wed, 17 Jun 2020 02:41:02 +0000 Received: by mail-qk1-x742.google.com with SMTP id b27so724711qka.4 for ; Tue, 16 Jun 2020 19:41:00 -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=pvdroGC5KvjOrR8FJHPtokfG+XyCQeyzcwh+i4uoNV4=; b=Hgv5xN/fQsgBei7OgUywkLhD0nmm7T0BHZNvXx+DpdIj0AYpa9SeqXlAi2aH2NUJ6l XlG+huh8bKgGbkyM67qT8gu2B/ynH5sAUr6mbaoJtTsZ4CkFJ8i4BUITazdi1x93OXro oRAeeWGd2lpFVUDaFzuO7M0yneWYyDkVHQaXXb30YCP/Ej4AtzsXc5O0O359laepP75u 4uIaC9B5bvai8U8DY9S3K213OXwR8lsVbGpSX2xAXt9BUWwikSlcaTdO9hVi22+7+AyO nejNEvACcTL5wAeb04KvtBggU+v2rOaKyb+7L39mRJv2jRKjChb3UH6TaTIx2itVQkty MOfw== 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=pvdroGC5KvjOrR8FJHPtokfG+XyCQeyzcwh+i4uoNV4=; b=tOh1BJyyXaa/wa+CS3WPlfwZ48ikBUAZRCklKMNwDdVFFsBNzCyN3Jl35nYwrsRvDz dsc7ojAVcXo+kijXqZC+DTxTg0V7kYAeZoIY9+Y13cloNpm58pTXoAXKS45FJquiUf4f K0tItGZRt+PRIVwHYtAIIgeB47L3F/1HhSGAcnDODH28qazVUpaCg/a7YUkk6q5rKW0B qYC5hESp9Y4C+R161laqxuJVK5xKzYXfMyLLGngUsCWsSF1JDB8Qt/pPsemVFE7znZOz BnoXs08F8ILMaIMCcB+45a1jaIJ4fYz93lS/wHufccz3UU2BJPcPp+5S6eTVHlft7y7X wyOQ== X-Gm-Message-State: AOAM532RrJLye4hBDAv2TF5wdCaBUvIT5m2ee58s4JtfLOGME9DjshNp GGKhwtfRJqFf6HnWAhxA5/f9uw== X-Google-Smtp-Source: ABdhPJxsOYemLVW2aPOFf/uTJJcdCbDAX6bdq0ZYZf1vPq2d5w9Fb2IGeuYK7DIlB8Pl+xD9sviIjw== X-Received: by 2002:a05:620a:200d:: with SMTP id c13mr23043732qka.47.1592361659377; Tue, 16 Jun 2020 19:40:59 -0700 (PDT) Received: from perhan.alvh.no-ip.org ([190.95.18.252]) by smtp.gmail.com with ESMTPSA id x41sm17880133qtb.76.2020.06.16.19.40.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Jun 2020 19:40:58 -0700 (PDT) Received: by perhan.alvh.no-ip.org (Postfix, from userid 1000) id DDABF2A3AC2; Tue, 16 Jun 2020 22:40:56 -0400 (-04) Date: Tue, 16 Jun 2020 22:40:56 -0400 From: Alvaro Herrera To: Fujii Masao Cc: Kyotaro Horiguchi , pgsql-hackers@lists.postgresql.org Subject: Re: Review for GetWALAvailability() Message-ID: <20200617024056.GA21726@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: 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-Jun-17, Fujii Masao wrote: > On 2020/06/17 3:50, Alvaro Herrera wrote: > So InvalidateObsoleteReplicationSlots() can terminate normal backends. > But do we want to do this? If we want, we should add the note about this > case into the docs? Otherwise the users would be surprised at termination > of backends by max_slot_wal_keep_size. I guess that it's basically rarely > happen, though. Well, if we could distinguish a walsender from a non-walsender process, then maybe it would make sense to leave backends alive. But do we want that? I admit I don't know what would be the reason to have a non-walsender process with an active slot, so I don't have a good opinion on what to do in this case. > > > + /* > > > + * Signal to terminate the process using the replication slot. > > > + * > > > + * Try to signal every 100ms until it succeeds. > > > + */ > > > + if (!killed && kill(active_pid, SIGTERM) == 0) > > > + killed = true; > > > + ConditionVariableTimedSleep(&slot->active_cv, 100, > > > + WAIT_EVENT_REPLICATION_SLOT_DROP); > > > + } while (ReplicationSlotIsActive(slot, NULL)); > > > > Note that here you're signalling only once and then sleeping many times > > in increments of 100ms -- you're not signalling every 100ms as the > > comment claims -- unless the signal fails, but you don't really expect > > that. On the contrary, I'd claim that the logic is reversed: if the > > signal fails, *then* you should stop signalling. > > You mean; in this code path, signaling fails only when the target process > disappears just before signaling. So if it fails, slot->active_pid is > expected to become 0 even without signaling more. Right? I guess kill() can also fail if the PID now belongs to a process owned by a different user. I think we've disregarded very quick reuse of PIDs, so we needn't concern ourselves with it. -- Álvaro Herrera https://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services