Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.92) (envelope-from ) id 1jIGMY-00034K-9D for pgsql-hackers@arkaria.postgresql.org; Sat, 28 Mar 2020 18:39:18 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1jIGMW-0001F9-Si for pgsql-hackers@arkaria.postgresql.org; Sat, 28 Mar 2020 18:39:16 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1jIGMW-0001E5-D0 for pgsql-hackers@lists.postgresql.org; Sat, 28 Mar 2020 18:39:16 +0000 Received: from mail-qk1-x741.google.com ([2607:f8b0:4864:20::741]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jIGMO-0001q3-7V for pgsql-hackers@postgresql.org; Sat, 28 Mar 2020 18:39:14 +0000 Received: by mail-qk1-x741.google.com with SMTP id h14so14660252qke.5 for ; Sat, 28 Mar 2020 11:39:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telsasoft-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=Q4GA1CD2Q74xu00Ghge97PXsBnmnCqsbHhbv1DHGpCE=; b=DnNaJTTjUWJMP6enuaGHmXo6kJbMMYlB5w79kH0LE2XO0/l9llftWwLYtY7Rg8cHZE jaki5g+1ODWn6AdLoh7Wk3eFHtlCRENNQp3nKsAWpNvkyPb5JcaXPPFHA/SWILWPD781 /7GN5be2e7pPW5AmfFjU5tCTxYS46vokFYChMigSYXZJtgeMJB0Ly1e92l6NfUqHNbdB fqTcqAQdAYKpSCcoSfjsuloxmqwVPkIasiUXoO5Fktwl5xZwGG02/yjAHygJckWWbhyt PWYNVr2aGSsOMpc582HokSeY7SHURGYfajTBjiIh8eWwhATJXFA906TXP004FBQbtM7I Jn+g== 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:references :mime-version:content-disposition:in-reply-to:user-agent; bh=Q4GA1CD2Q74xu00Ghge97PXsBnmnCqsbHhbv1DHGpCE=; b=GnwXSZ3qaBaiDuM6VboTk4m70YBZm+L6KNLgKKcipQpr7XGIc97s5riGmg9xHFa5cl ouxYAf/g1/QV82j2A4+kukSF7NX8Ghj+E5yGR1OOkBOkyZU+lmyACPd+jMoeo0WYlbmk 358GiatWyaKjMc+eP46vTPWB8rLNWLiNngTgL58Vg4jzUqiEc51v8P5WHWh02qfGrFj7 KcHy9x6U8McxOEfh/3WQ/CN18w/PSqStLj9ngE2Y4nnewotn1G7i1S2+oRg30iFz8O5j 1NMknWnylP6yTtW52xLxyOzq+2C9mveLW+Bg1DL9EwFiFTsKZrGdgEJ0Vbtn7B2Y0U6S WTig== X-Gm-Message-State: ANhLgQ1yB5SesW61HfUjsokeN3mfoT8DCIIa4dBXWNVMR0ozFAAMvz4y u+N+OCK7o0BiUlIQQF2aWmzYTA== X-Google-Smtp-Source: ADFU+vvHJFE61gH3IAhOq7ViAwfH4EtsCLQaCT7U5HaI1vRfe4BawgtodTfYF+b+vubrZ01vt3XRqA== X-Received: by 2002:a37:b041:: with SMTP id z62mr4877785qke.487.1585420746971; Sat, 28 Mar 2020 11:39:06 -0700 (PDT) Received: from pryzbyj (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id 85sm6388295qke.128.2020.03.28.11.39.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 28 Mar 2020 11:39:05 -0700 (PDT) Received: by pryzbyj (Postfix, from userid 1000) id 90BAA80096B; Sat, 28 Mar 2020 13:39:04 -0500 (CDT) Date: Sat, 28 Mar 2020 13:39:04 -0500 From: Justin Pryzby To: Tom Lane Cc: pgsql-hackers@postgresql.org, Fabien COELHO , Alvaro Herrera , David Steele , "Bossart, Nathan" , Thomas Munro Subject: Re: pg11+: pg_ls_*dir LIMIT 1: temporary files .. not closed at end-of-transaction Message-ID: <20200328183904.GI20103@telsasoft.com> References: <27334.1583692669@sss.pgh.pa.us> <20200308191456.GD1357@telsasoft.com> <5679.1583696409@sss.pgh.pa.us> <20200311111921.GQ29065@telsasoft.com> <21724.1583955158@sss.pgh.pa.us> <20200312121156.GB29065@telsasoft.com> <20200316155306.GM26184@telsasoft.com> <3061.1584409130@sss.pgh.pa.us> <20200317020017.GT26184@telsasoft.com> <24244.1585415634@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <24244.1585415634@sss.pgh.pa.us> User-Agent: Mutt/1.9.4 (2018-02-28) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Sat, Mar 28, 2020 at 01:13:54PM -0400, Tom Lane wrote: > The buildfarm just showed up another instability in the test cases > we added: Yea, as you said, this is an issue with the *testcase*. The function behavior didn't change, we just weren't previously exercising it. > select (w).size = :segsize as ok > from (select pg_ls_waldir() w) ss where length((w).name) = 24 limit 1; > - ok > ----- > - t > -(1 row) > - > +ERROR: could not stat file "pg_wal/000000010000000000000078": No such file or directory > select count(*) >= 0 as ok from pg_ls_archive_statusdir(); > ok > ---- > > It's pretty obvious what happened here: concurrent activity renamed or > removed the WAL segment between when we saw it in the directory and > when we tried to stat() it. > > This seems like it would be just as much of a hazard for field usage > as it is for regression testing, That's clearly true for pg_ls_waldir(), which call pg_ls_dir_files, and includes some metadata columns. > so I propose that we fix these directory-scanning functions to silently > ignore ENOENT failures from stat(). Are there any for which we should not do > that? I think it's reasonable to ignore transient ENOENT for tmpdir, logdir, and probably archive_statusdir. That doesn't currently affect pg_ls_dir(), which lists file but not metadata for an arbitrary dir, so doesn't call stat(). Note that dangling links in the other functions currently cause (wrong [0]) error. I guess it should be documented if broken link is will be ignored due to ENOENT. Maybe we should lstat() the file to determine if it's a dangling link; if lstat() fails, then skip it. Currently, we use stat(), which shows metdata of a link's *target*. Maybe we'd change that. Note that I have a patch which generalizes pg_ls_dir_files and makes pg_ls_dir() a simple wrapper, so if that's pursued, they would behave the same unless I add another flag to do otherwise (but behaving the same has its merits). It already uses lstat() to show links to dirs as isdir=no, which was needed to avoid recursing into links-to-dirs in the new helper function pg_ls_dir_recurse(). https://commitfest.postgresql.org/26/2377/ [0] Which you fixed in 085b6b667 and I previously fixed at: https://www.postgresql.org/message-id/attachment/106478/v2-0001-BUG-in-errmsg.patch |$ sudo ln -s foo /var/log/postgresql/bar |ts=# SELECT * FROM pg_ls_logdir() ORDER BY 3; |ERROR: could not stat directory "/var/log/postgresql": No such file or directory