pg_ls_dir_files issue with concurrent file unlink

From: Sergei Kornilov <sk(at)zsrv(dot)org>
To: PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>
Subject: pg_ls_dir_files issue with concurrent file unlink
Date: 2018-11-02 09:25:10
Message-ID: 52030281541150710@myt6-27270b78ac4f.qloud-c.yandex.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hello
We have some functions for directory listing, e.g. pg_ls_dir, pg_ls_logdir, pg_ls_waldir. All of them call pg_ls_dir_files function (src/backend/utils/adt/genfile.c) and i have question about per file error in this function.

> /* Get the file info */
> snprintf(path, sizeof(path), "%s/%s", fctx->location, de->d_name);
> if (stat(path, &attrib) < 0)
> ereport(ERROR,
> (errcode_for_file_access(),
> errmsg("could not stat directory \"%s\": %m", dir)));

We tried stat file in direectory, but error say only about directory. For example it is possible have very unexpected (and fearful) error for pg_ls_dir during checkpoint:

> postgres=# SELECT sum(size) AS size_bytes FROM pg_ls_waldir();
> ERROR: could not stat directory "pg_wal": No such file or directory

It is expected? Maybe it is better skip ENOENT files during directory listing? Or change error to "could not stat file in directory \"%s\"" if we do not want report filename for some reason. Or report error for file path instead of dir.

regards, Sergei

Browse pgsql-hackers by date

  From Date Subject
Next Message Masahiko Sawada 2018-11-02 09:26:02 Re: [HACKERS] Block level parallel vacuum
Previous Message Fabien COELHO 2018-11-02 09:24:24 Re: CF app feature request