Received: from localhost (unknown [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id 3DC942E0050 for ; Fri, 28 Mar 2008 12:43:43 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 87892-09 for ; Fri, 28 Mar 2008 12:43:39 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from mail.transas.com (mail.transas.com [82.140.75.150]) by postgresql.org (Postfix) with ESMTP id 186FF2E0038 for ; Fri, 28 Mar 2008 12:43:39 -0300 (ADT) Received: from sol.transas.com (sol.transas.com [10.10.0.20]) by mail.transas.com (Postfix) with ESMTP id A3FBD50A7D8; Fri, 28 Mar 2008 18:43:29 +0300 (MSK) Content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="koi8-r" Content-Transfer-Encoding: quoted-printable X-MimeOLE: Produced By Microsoft Exchange V6.5 Subject: Re: [DOCS] pg_total_relation_size() and CHECKPOINT Date: Fri, 28 Mar 2008 18:43:29 +0300 Message-ID: <528853D3C5ED2C4AA8990B504BA7FB850106DF2E@sol.transas.com> In-Reply-To: <47EB98EA.7020402@dunslane.net> X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: [HACKERS] [DOCS] pg_total_relation_size() and CHECKPOINT Thread-Index: AciQCbbzLig5TxtsR4e+tuhZLNe2GgA1vZYw From: "Zubkovsky, Sergey" To: "Andrew Dunstan" Cc: "Tom Lane" , "Alvaro Herrera" , "Gregory Stark" , , "Magnus Hagander" X-Transas-MailScanner: Found to be clean X-Transas-MailScanner-From: sergey.zubkovsky@transas.com X-Transas-MailScanner-To: alvherre@commandprompt.com, andrew@dunslane.net, magnus@hagander.net, pgsql-hackers@postgresql.org, stark@enterprisedb.com, tgl@sss.pgh.pa.us X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200803/1182 X-Sequence-Number: 115983 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 =C1bout 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@dunslane.net]=20 Sent: Thursday, March 27, 2008 3:54 PM To: Zubkovsky, Sergey Cc: Tom Lane; Alvaro Herrera; Gregory Stark; = pgsql-hackers@postgresql.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. > > =20 > Yes, but we immediately follow the lseek bye a write(). See=20 src/backend/storage/smgr/md.c:mdextend() . cheers andrew