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 1nriMz-00032B-O5 for pgsql-general@arkaria.postgresql.org; Thu, 19 May 2022 15:47:21 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nriMy-000367-JI for pgsql-general@arkaria.postgresql.org; Thu, 19 May 2022 15:47:20 +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 1nriMy-00035x-8z for pgsql-general@lists.postgresql.org; Thu, 19 May 2022 15:47:20 +0000 Received: from mail-ed1-x52c.google.com ([2a00:1450:4864:20::52c]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1nriMu-0001FZ-69 for pgsql-general@lists.postgresql.org; Thu, 19 May 2022 15:47:19 +0000 Received: by mail-ed1-x52c.google.com with SMTP id j28so7455239eda.13 for ; Thu, 19 May 2022 08:47:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec-at.20210112.gappssmtp.com; s=20210112; h=message-id:subject:from:to:cc:date:in-reply-to:references :user-agent:mime-version:content-transfer-encoding; bh=Dwg4RSD8uAeUSh8hHPJwiIBqbM50Gxb5iAoxjBCas5U=; b=ApY3rQGe6nvoqmM6zxpxBca73IJqOTe/F6QaQ2dXANwootZoWPPTDWONgVP9XejMQG KvwqpXAw6pYucqKEbbikuUeMfHrBqSMWwygjIt+5VfxOa4iQDb3xkVSfFJyE2sp4IEHI goauzsZaxsJ4wNuDCQBQW0xiomKdYlG57ptec60SfNhVT2+LdD1NYR6OJ6KBmatKOzkO 6S0cTP8XlwM25vD3X3J5/TDcHzYWTwpPtH3S8vXH6A5KTXgbJah9vITtr2edxZhGF1sT ZazsEEY5BtHoHmwGVA1h2X1Z/a/+E5PSqoBP8OrWy7clpc7uIUenM2l7n5opz/1Dp4J+ M1zg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:subject:from:to:cc:date:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=Dwg4RSD8uAeUSh8hHPJwiIBqbM50Gxb5iAoxjBCas5U=; b=6A3DXPfEj+CWjnZ4wSyCkLQUTHBkwSFZp5P8U3cmwMuwvpwLt5G6+gIH3doFRJ1J6j UsGDTXiI4TszugQ9olW4qHHLWH1erJWUTcwQkBJUgm4SbDk7pn6MjITMQKC0pduyHGz0 Oe4oJ0MKjnWdrXygLdhE0DQKRSJuErj1hGnWzscVFkZWorMi2hN0jsZffkcO5MSO6D05 8ppfSnE9W5WI+TW25EBo8/67wHfeqm9sOA+6c7XQ872DjMHG6zrtkmehx2ZKRt6JKevy EMyUfh1D1lLOGnjUhYjnJUz1g7HatClJ8LSQcoBpr16T6NZMWRtHD0CR5wjBExYERp13 adxw== X-Gm-Message-State: AOAM530yWUUHOFXvEjxw+s7XvA0A7uLZTz584I6psRZrggTHaqZ1CSxk ZoZM6cLo3O+dWIQ8dEsjYnWb5g== X-Google-Smtp-Source: ABdhPJxQCQFup2Tcg4kFWHE2ikWzmi5HXdUgRB/TJ8CJEREOag9EI1jwQ5YB/1j5OiXlRedS8vZyrQ== X-Received: by 2002:a05:6402:783:b0:42a:b251:6a9d with SMTP id d3-20020a056402078300b0042ab2516a9dmr5931550edy.315.1652975234028; Thu, 19 May 2022 08:47:14 -0700 (PDT) Received: from dynamic-pd01.res.v6.highway.a1.net ([2001:871:5e:1f41:c34f:9eb1:7394:db5a]) by smtp.gmail.com with ESMTPSA id ej23-20020a056402369700b0042a2d9af0f8sm2950873edb.79.2022.05.19.08.47.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 May 2022 08:47:13 -0700 (PDT) Message-ID: Subject: Re: In case of network issues, how long before archive_command does retries From: Laurenz Albe To: Koen De Groote Cc: PostgreSQL General Date: Thu, 19 May 2022 17:47:12 +0200 In-Reply-To: References: <83b1f99e797754fa8f5589d458c5d3aa674479c8.camel@cybertec.at> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.42.4 (3.42.4-2.fc35) MIME-Version: 1.0 Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Thu, 2022-05-19 at 15:43 +0200, Koen De Groote wrote: > On Thu, May 19, 2022 at 9:10 AM Laurenz Albe wrote: > > On Wed, 2022-05-18 at 22:51 +0200, Koen De Groote wrote: > > > When connection is gone or blocked, archive_command fails after the timeout specified > > > by the NFS mount, as expected. (for a soft mount. hard mount hangs, as expected) > > > > > > However, on restoring connection, it's not clear to me how long it takes before the command is retried. > > > > > > Experience says "a few minutes", but I can't find documentation on an exact algorithm. > > > > > > To be clear, the question is: if archive_command fails, what are the specifics of retrying? > > > Is there a timeout? How is that timeout defined? > > > > > > Is this detailed somewhere? Perhaps in the source code? I couldn't find it in the documentation. > > > > > > For detail, I'm using postgres 11, running on Ubuntu 20. > > > > You can find the details in "src/backend/postmaster/pgarch.c". > > > > The archiver will try to archive three times (NUM_ARCHIVE_RETRIES) in an interval > > of one second, then back off until it receives a signal, PostgreSQL shutd down > > or a minute has passed. > > Thanks for the reply. That would mean the source code is here: > https://github.com/postgres/postgres/blob/REL_11_0/src/backend/postmaster/pgarch.c For release 11.0, yes. > Just to be sure, the "signal" you speak of, this is the result of the command executed by archive_command? No, that is an operating system signal. PostgreSQL processes communicate by sending signals to each other, and if anybody wakes up the archiver, it will try again. > If my understanding of the code is right, if no SIGTERM or other signal arrives, it won't ever happen > that a walarchive is skipped if the archive_command fails too many times or takes too long? It > will simply check again every 60 seconds(PGARCH_AUTOWAKE_INTERVAL) ? Or is the 60 seconds the point > where it stops trying, waiting for the next time archive_command is invoked? Even if a signal arrives, PostgreSQL will keep trying to archive that same WAL segment that failed until it is done. This is a potential sequence of events: try to archive -> fail sleep 1 second try to archive -> fail sleep 1 second try to archive -> fail sleep 60 seconds try to archive -> fail sleep 1 second try to archive -> fail sleep 1 second try to archive -> fail sleep 60 seconds -> get woken up by a signal after 30 seconds try to archive -> fail sleep 1 second try to archive -> fail get shutdown request -> exit When PostgreSQL restarts, it will continue trying to archive the same segment. > I'm assuming that as long as the file is still in the pg_wal directory and as long as there is no > ".done" file for that walarchive under pg_wal/archive_status, it will keep trying forever(or until > someone forcefully switches the timeline with for instance a basebackup)? Yes, it will keep trying, and a timeline switch won't change that. Yours, Laurenz Albe -- Cybertec | https://www.cybertec-postgresql.com