Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pN4M9-0000E5-Cg for pgsql-hackers@arkaria.postgresql.org; Wed, 01 Feb 2023 04:04:22 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pN4M7-0008Pm-PD for pgsql-hackers@arkaria.postgresql.org; Wed, 01 Feb 2023 04:04:19 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pN4M7-0008Oj-9P for pgsql-hackers@lists.postgresql.org; Wed, 01 Feb 2023 04:04:19 +0000 Received: from smtp60.i.mail.ru ([217.69.128.40]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pN4M2-0005zV-BE for pgsql-hackers@postgresql.org; Wed, 01 Feb 2023 04:04:18 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=inbox.ru; s=mail4; h=Content-Transfer-Encoding:Content-Type:In-Reply-To:From:References:Cc:To:Subject:MIME-Version:Date:Message-ID:From:Subject:Content-Type:Content-Transfer-Encoding:To:Cc; bh=otuO8LeE0PBKoD/aH9gKPgebmTxlnjG5bWRVtL47ok8=; t=1675224254;x=1675314254; b=F2A/KF/IJOmrGsZIbzGGKFdaGFTGFl115H4wCVquzAF1oBhJ52tPvbywyuGFLh6idLswoq9BDUP6qFesKIN1vNR4TrzP3HqcAzC0YMtJbb8x0g81G2xml9vbfHXG3CpO/KPCNwuGsjpSbRHpr9OJmRCRctTPbjvfQKWdvIII9gYmtf9d20erOU9CNcs+32cURMT7VvAhkZEE4llwk0E2JsjMe1GZSpxUk2dKL9zFDlK7v3UpKBOjZAnWe456eKjmiRx8jWyFyuw2BccdZzK94sAEFOO/jYbb+Jvvi1Ofcdk7dtSALCNGNv0QTbRZ2FyPmLI4nWbUo/zz1dXP8mGgXA==; Received: by smtp60.i.mail.ru with esmtpa (envelope-from ) id 1pN4Lx-0007wd-Ox; Wed, 01 Feb 2023 07:04:10 +0300 Message-ID: <2a64f915-213b-4bd0-1cdf-bd987694021e@inbox.ru> Date: Wed, 1 Feb 2023 07:04:09 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.2 Subject: Re: odd buildfarm failure - "pg_ctl: control file appears to be corrupt" Content-Language: en-US To: Thomas Munro Cc: Tom Lane , Andres Freund , pgsql-hackers@postgresql.org References: <20221123014224.xisi44byq3cf5psi@awork3.anarazel.de> <3748783.1669241103@sss.pgh.pa.us> <20d45197-80be-4984-33a9-a8d13708992a@inbox.ru> From: "Anton A. Melnikov" In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Authentication-Results: smtp60.i.mail.ru; auth=pass smtp.auth=aamelnikov@inbox.ru smtp.mailfrom=aamelnikov@inbox.ru X-Mailru-Src: smtp X-4EC0790: 10 X-7564579A: EEAE043A70213CC8 X-77F55803: 4F1203BC0FB41BD9AD83B49AC1DDA08967EC36FA2B240E0E9DA1CCEB7D38F385182A05F5380850404C228DA9ACA6FE2753DC866A5C18C84191C6F9E8876A17E1E9E8603C3947597CD1839378CFE9B764 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE77BF46084C0059042EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006371E4BC0E00C009995EA1F7E6F0F101C6723150C8DA25C47586E58E00D9D99D84E1BDDB23E98D2D38B6F1F7B995052D5CE8DC621BD7EFFB91A3EB031EEE178DD1820879F7C8C5043D14489FFFB0AA5F4BF1661749BA6B977354CF195F1528592878941B15DA834481FA18204E546F3947C0CABCCA60F52D7EBF6B57BC7E64490618DEB871D839B7333395957E7521B51C2DFABB839C843B9C08941B15DA834481F8AA50765F7900637529BE3F22733EA6E389733CBF5DBD5E9B5C8C57E37DE458BD9DD9810294C998ED8FC6C240DEA76428AA50765F7900637C1B9F0778B9FDC16D81D268191BDAD3DBD4B6F7A4D31EC0BEA7A3FFF5B025636D81D268191BDAD3D78DA827A17800CE7F8CA6C5869DFF914EC76A7562686271ED91E3A1F190DE8FD2E808ACE2090B5E14AD6D5ED66289B5259CC434672EE63711DD303D21008E298D5E8D9A59859A8B6B372FE9A2E580EFC725E5C173C3A84C369456C5265B6C55C35872C767BF85DA2F004C90652538430E4A6367B16DE6309 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D343D1F112031EF3D6215A6C6F613D2E196D4B302682F8B47FC2FCEDF220B7E7519959428D9C34F289B1D7E09C32AA3244C37153990DBC942F87044EA52F0581DD2F26BFA4C8A6946B8927AC6DF5659F194 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojUFx0YIIX6pzbG9kDwFn1VA== X-Mailru-Sender: 583F1D7ACE8F49BDEF9811C91988E44D2F3E16464940D932FCF69B3A97CBE946DFAE731DFB4681A8521832C859E33E520BF742DC56920EB040B84F0F0A031088E08AD13A84CB39455BCDE18EE81B8D342D063C67CFD4E84967EA787935ED9F1B X-Mras: Ok List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, Thomas! There are two variants of the patch now. 1) As for the first workaround: On 31.01.2023 07:09, Thomas Munro wrote: > > Maybe it's unlikely that two samples will match while running that > torture test, because it's overwriting the file as fast as it can. > But the idea is that a real system isn't writing the control file most > of the time. > ........ > Yeah, I was thinking that we should also put a limit on the loop, just > to be cautious. At first i didn’t understand that the equality condition with the previous calculated crc and the current one at the second+ attempts was intended for the case when the pg_control file is really corrupted. Indeed, by making a few debugging variables and running the tortue test, i found that there were ~4000 crc errors (~0.0003%) in ~125 million reads from the file, and there was no case when the crc error appeared twice in a row. So the second and moreover the third successive occurrence of an crc error can be neglected and for this workaround seems a simpler and maybe more clear algorithm is possible. For instance: for(try = 0 ; try < 3; try++) { open, read from and close pg_control; calculate crc; *crc_ok_p = EQ_CRC32C(crc, ControlFile->crc); if(*crc_ok_p) break; } 2) As for the second variant of the patch with POSIX locks: On 31.01.2023 14:38, Thomas Munro wrote: > On Tue, Jan 31, 2023 at 5:09 PM Thomas Munro wrote: >> Clearly there is an element of speculation or superstition here. I >> don't know what else to do if both PostgreSQL and ext4 decided not to >> add interlocking. Maybe we should rethink that. How bad would it >> really be if control file access used POSIX file locking? I mean, the >> writer is going to *fsync* the file, so it's not like one more wafer >> thin system call is going to hurt too much. > > Here's an experimental patch for that alternative. I wonder if > someone would want to be able to turn it off for some reason -- maybe > some NFS problem? It's less back-patchable, but maybe more > principled? It looks very strange to me that there may be cases where the cluster data is stored in NFS. Can't figure out how this can be useful. i think this variant of the patch is a normal solution of the problem, not workaround. Found no problems on Linux. +1 for this variant. Might add a custom error message for EDEADLK since it absent in errcode_for_file_access()? > I don't know if Windows suffers from this type of problem. > Unfortunately its equivalent functionality LockFile() looks non-ideal > for this purpose: if your program crashes, the documentation is very > vague on when exactly it is released by the OS, but it's not > immediately on process exit. That seems non-ideal for a control file > you might want to access again very soon after a crash, to be able to > recover. Unfortunately i've not had time to reproduce the problem and apply this patch on Windows yet but i'm going to do it soon on windows 10. If a crc error will occur there, then we might use the workaround from the first variant of the patch. > A thought in passing: if UpdateMinRecoveryPoint() performance is an > issue, maybe we should figure out how to use fdatasync() instead of > fsync(). May be choose it in accordance with GUC wal_sync_method? Sincerely yours, -- Anton A. Melnikov Postgres Professional: http://www.postgrespro.com The Russian Postgres Company