Re: Proposed doc-patch: Identifying the Current WAL file - Mailing list pgsql-docs

From Bruce Momjian
Subject Re: Proposed doc-patch: Identifying the Current WAL file
Date
Msg-id 200604151624.k3FGOj525540@candle.pha.pa.us
Whole thread Raw
In response to Re: Proposed doc-patch: Identifying the Current WAL file  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: Proposed doc-patch: Identifying the Current WAL file
Re: Proposed doc-patch: Identifying the Current WAL file
Re: Proposed doc-patch: Identifying the Current WAL file
List pgsql-docs
Tom Lane wrote:
> Bruce Momjian <pgman@candle.pha.pa.us> writes:
> > Richard Huxton wrote:
> >> To identify the current, partially-filled WAL segment, sort first by
> >> mtime and second by file name. That is, take the latest mtime among the
> >> properly-named files, breaking ties by taking the higher filename.
>
> > I am confused by this.  Why do both mtime and file name need to be
> > checked?
>
> Because recycled WAL segments are renamed to have higher file names than
> the currently-in-use segment.  So you can't depend on file name first.
> However, shortly after a segment switch two WAL segments could have the
> same mtime (to within whatever the mtime granularity is, typ. 1 second).
>
> The proposed rule should be OK as long as checkpoints (and ensuing
> renames) can't occur oftener than the mtime granularity.  If you're
> checkpointing more than once a second, well, you need help ...

I am trying to figure out how this could even be done in a shell script.
'ls -lt' is going to show:

    -rw-r--r--  1 root  postgres  0 Apr 15 11:56 x1
    -rw-r--r--  1 root  postgres  0 Apr 15 11:56 x2
    -rw-r--r--  1 root  postgres  0 Apr 15 11:56 x3

but this might be with second resolution:

    -rw-r--r--  1 root  postgres  0 Apr 15 11:56:47 x1
    -rw-r--r--  1 root  postgres  0 Apr 15 11:56:47 x2
    -rw-r--r--  1 root  postgres  0 Apr 15 11:56:34 x3

or it might be:

    -rw-r--r--  1 root  postgres  0 Apr 15 11:56:47 x1
    -rw-r--r--  1 root  postgres  0 Apr 15 11:56:34 x2
    -rw-r--r--  1 root  postgres  0 Apr 15 11:56:25 x3

In the first case, x2 is current, having be just switched to from x1,
while in the second case, x1 is current.  In BSD, you can use ls -ltT to
see the seconds, but in Linux it is something different, and I am sure
there are some operating systems that don't allow you to see the seconds
at all.  What general command-line solution can we propose for this
process?  And if we can't provide one, should we supply an SQL function
to return the current WAL name?

--
  Bruce Momjian   http://candle.pha.pa.us
  EnterpriseDB    http://www.enterprisedb.com

  + If your life is a hard drive, Christ can be your backup. +

pgsql-docs by date:

Previous
From: Tom Lane
Date:
Subject: Re: Proposed doc-patch: Identifying the Current WAL file
Next
From: Tom Lane
Date:
Subject: Re: Proposed doc-patch: Identifying the Current WAL file