On Sat, 15 Apr 2006, Tom Lane wrote:
> Bruce Momjian <pgman@candle.pha.pa.us> writes:
>> 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.
>
> You seem to be assuming that ls will sort on the basis of the truncated
> mtime that it displays, which is not the actual behavior of ls AFAIK.
I believe you're correct, at least with the ls I have here on my linux system.
I created two files quickly with touch. Here is the stat output:
File: `AA'
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Device: 802h/2050d Inode: 2736263 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 26/postgres) Gid: ( 26/postgres)
Access: 2006-04-15 11:02:46.000000000 -0700
Modify: 2006-04-15 11:02:46.000000000 -0700
Change: 2006-04-15 11:02:46.000000000 -0700
File: `AB'
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Device: 802h/2050d Inode: 2736264 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 26/postgres) Gid: ( 26/postgres)
Access: 2006-04-15 11:02:48.000000000 -0700
Modify: 2006-04-15 11:02:48.000000000 -0700
Change: 2006-04-15 11:02:48.000000000 -0700
ls -t | head -1
AB
So it looks like the original was correct all along, but with Tom's regex it's
much cleaner. Too bad grep's regex engine doesn't support {24}.
I'll change all my scripts to use the following:
ls -t /pg_xlog/ | grep
'^[0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F]$'
|head -1
Thanks Tom!
--
Jeff Frost, Owner <jeff@frostconsultingllc.com>
Frost Consulting, LLC http://www.frostconsultingllc.com/
Phone: 650-780-7908 FAX: 650-649-1954