Skip site navigation (1) Skip section navigation (2)

Re: [DOCS] pg_total_relation_size() and CHECKPOINT

From: "Zubkovsky, Sergey" <Sergey(dot)Zubkovsky(at)transas(dot)com>
To: "Andrew Dunstan" <andrew(at)dunslane(dot)net>
Cc: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>,"Alvaro Herrera" <alvherre(at)commandprompt(dot)com>,"Gregory Stark" <stark(at)enterprisedb(dot)com>,<pgsql-hackers(at)postgresql(dot)org>,"Magnus Hagander" <magnus(at)hagander(dot)net>
Subject: Re: [DOCS] pg_total_relation_size() and CHECKPOINT
Date: 2008-03-28 15:43:29
Message-ID: 528853D3C5ED2C4AA8990B504BA7FB850106DF2E@sol.transas.com (view raw or flat)
Thread:
Lists: pgsql-docspgsql-hackers
It seems I've found the cause and the workaround of the problem.
MSVC's stat() is implemented by using FindNextFile().
MSDN contains the following suspicious paragraph Đ°bout FindNextFile():

"In rare cases, file attribute information on NTFS file systems may not be current at the time you call this function. To obtain the current NTFS file system file attributes, call GetFileInformationByHandle."

Since we generally cannot open an examined file, we need another way.

In the prepared custom build of PG 8.3.1 the native MSVC's stat() was rewrote by adding GetFileAttributesEx() to correct stat's st_size value.
I had seen that a result of MSVC's stat() and a result of GetFileAttributesEx() may be differ by the file size values at least.

The most important thing is the test in the original post
( http://archives.postgresql.org/pgsql-docs/2008-03/msg00041.php )
doesn't reproduce any inconsistence now.
All work fine.

This was tested on my WinXP SP2 platform but I suppose it will work on any NT-based OS.


Thanks,
Sergey Zubkovsky

-----Original Message-----
From: Andrew Dunstan [mailto:andrew(at)dunslane(dot)net] 
Sent: Thursday, March 27, 2008 3:54 PM
To: Zubkovsky, Sergey
Cc: Tom Lane; Alvaro Herrera; Gregory Stark; pgsql-hackers(at)postgresql(dot)org; Magnus Hagander
Subject: Re: [HACKERS] [DOCS] pg_total_relation_size() and CHECKPOINT



Zubkovsky, Sergey wrote:
> Maybe this helps:
>
> "It is not an error to set a file pointer to a position beyond the end
> of the file. The size of the file does not increase until you call the
> SetEndOfFile, WriteFile, or WriteFileEx function. A write operation
> increases the size of the file to the file pointer position plus the
> size of the buffer written, which results in the intervening bytes
> uninitialized."
>
> http://msdn2.microsoft.com/en-us/library/aa365541(VS.85).aspx
>
> According to Windows' lseek implementation (attached) SetEndOfFile()
> isn't called for this case.
>
>   
>

Yes, but we immediately follow the lseek bye a write(). See 
src/backend/storage/smgr/md.c:mdextend() .

cheers

andrew

In response to

pgsql-docs by date

Next:From: Bruce MomjianDate: 2008-04-07 00:51:33
Subject: Details for ROW IS NULL test
Previous:From: Andrew DunstanDate: 2008-03-27 14:29:20
Subject: Re: [DOCS] pg_total_relation_size() and CHECKPOINT

pgsql-hackers by date

Next:From: Bruce MomjianDate: 2008-03-28 15:45:51
Subject: Re: Commitfest patches
Previous:From: Bruce MomjianDate: 2008-03-28 15:41:58
Subject: Re: Prereading using posix_fadvise (was Re: Commitfest patches)

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group