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

From Jeff Frost
Subject Re: Proposed doc-patch: Identifying the Current WAL file
Date
Msg-id Pine.LNX.4.64.0604151029490.9581@discord.dyndns.org
Whole thread Raw
In response to Re: Proposed doc-patch: Identifying the Current WAL file  (Bruce Momjian <pgman@candle.pha.pa.us>)
Responses Re: Proposed doc-patch: Identifying the Current WAL file  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-docs
On Sat, 15 Apr 2006, Bruce Momjian wrote:

>> ls -tp /pg_xlog/ | grep -v "backup\|/" | head -1
>>
>> which seems to work fairly well.  Looks like that thread is here:
>>
>> http://archives.postgresql.org/pgsql-admin/2005-10/msg00173.php
>
> What does the -p and \| pipe check do?  We don't have named pipes in
> that directory, do we?
>
> Also, what happens if the log switch happens, and some data change is
> written to the new WAL file in the first second, but nothing happens to
> the database after that for a minute?  Your test would still show the
> old log file.

The -p shows forward slashes after directories and the \| acts as an or and
the / following that just lets us filter directories out.  I added that
because I used to find the archive_status directory winning the ls -t from
time to time.

Now about your what if question.  I don't know if there is a way to get past
the mtime granularity.  If I understand your scenario correctly, you indicate
that the previous log is written to and the new log is switched in during the
same mtime second.  I did a quick test on linux to see how that operates:

touch AA AB

This yields both files with the same mtime.

ls -tp |head -1

yields AA as you suggested it would.

The following seems to do the trick if we can rely on alphabetizing to
properly decide the winner of a tie:

ls -tp | head -2 | sort -r | head -1

So, with my previous example, it would look like:

ls -tp /pg_xlog/ | grep -v "backup\|/" | head -2 | sort -r | head -1



--
Jeff Frost, Owner     <jeff@frostconsultingllc.com>
Frost Consulting, LLC     http://www.frostconsultingllc.com/
Phone: 650-780-7908    FAX: 650-649-1954

pgsql-docs by date:

Previous
From: Bruce Momjian
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