Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sFud4-007IK2-DH for pgsql-bugs@arkaria.postgresql.org; Sat, 08 Jun 2024 11:53:03 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1sFud2-00Gmd5-Os for pgsql-bugs@arkaria.postgresql.org; Sat, 08 Jun 2024 11:53:01 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sFud2-00Gmc9-F3 for pgsql-bugs@lists.postgresql.org; Sat, 08 Jun 2024 11:53:01 +0000 Received: from mx0b-00134001.pphosted.com ([205.220.172.129]) by makus.postgresql.org with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sFud0-000J0H-B0 for pgsql-bugs@lists.postgresql.org; Sat, 08 Jun 2024 11:53:00 +0000 Received: from pps.filterd (m0267962.ppops.net [127.0.0.1]) by mx0a-00134001.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 458Bk1QM024613; Sat, 8 Jun 2024 11:52:54 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=optiver.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=mail; bh=ggLGt v4/UPQWvgY8ni4F1OjJlBO5JdyXnlVeHfDyuRQ=; b=Oixrww81/Ikb674KjIQR/ UloR3w81DVFXXOKTfj+/3ZRc4VDjYyepV5nM2hMOZ0kun+T1LdRU8R+ScrSmXafI Ss5nnRIByH5js/64RrQSLSu/QtfRetEwqaO0TEurWL8Ow10TwHEVzGh1ZCIW9A/t zwPylWiB3EccW/nuFMNcV999N3sQbslEt6vGAtsj2fIm5oEOcBGDXse2GEpbaBLs TlhACX+AU5HHOSbGsjBK7AefwUMoUUwji4DlTBuOwP1wS6B7jDQjvfg98/BUUeq9 MR2AmLv3qz5HcRWiMyHgkdHWHmYVqcHJPwUOOU4jfhTGukig7gqbSJDgra++6LTT g== Received: from opammb1270.comp.optiver.com ([195.246.114.78]) by mx0a-00134001.pphosted.com (PPS) with ESMTPS id 3ymd5n07bm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sat, 08 Jun 2024 11:52:54 +0000 (GMT) Received: from opammb1267.comp.optiver.com (100.68.11.12) by opammb1270.comp.optiver.com (100.68.11.18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.26; Sat, 8 Jun 2024 13:52:43 +0200 Received: from opammb1267.comp.optiver.com ([fe80::5b6f:1976:98cd:68a7]) by opammb1267.comp.optiver.com ([fe80::5b6f:1976:98cd:68a7%13]) with mapi id 15.02.1118.026; Sat, 8 Jun 2024 13:52:43 +0200 From: Floris Van Nee To: Michael Paquier , Bertrand Drouvot CC: Andres Freund , Kyotaro Horiguchi , "tgl@sss.pgh.pa.us" , "pgsql-bugs@lists.postgresql.org" Thread-Topic: [External] Re: error "can only drop stats once" brings down database [External] Thread-Index: AQHaZC2BJX3cZ68Gf0SnR3ukCGL5orGGQZEwgALhs4CAAGv+AIAsEUZQgAHuzgCAAg6I8IABEKoAgAAWkICAAUFxAIAAGUIAgAAHhACAAGn2gIAABMQAgAHQRtA= Date: Sat, 8 Jun 2024 11:52:43 +0000 Message-ID: <2cb577e176774caca28c724898768a38@Optiver.com> References: <68430b1b76d44558b7b07ae8c69151f6@Optiver.com> <20240607.101540.1972690976596948719.horikyota.ntt@gmail.com> <20240607031258.l4fcpvulo3uee5g6@awork3.anarazel.de> In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [100.68.31.122] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: RE: error "can only drop stats once" brings down database X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-06-08_05,2024-06-06_02,2024-05-17_01 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > Okay, I've just applied the elog() version down to 15 then. Now, about t= he > entry getting dropped twice.. Thanks Michael. I've got an update about the bug. I managed to reproduce it locally after a= lot of digging. How to repro: - Setup primary + replica - Open a psql session on both - On primary session: create table t (a int); select 't'::regclass::oid; - On replica session: select * from t; - On primary session: drop table t; vacuum pg_class; checkpoint; - Gdb attach to the backend for your primary, set a breakpoint for=20 catalog.c:GetNewOidWithIndex, just before it calls GetNewObjectId() - On primary session: create table t (a int); - When it hits breakpoint, simulate oid wraparound by setting: ShmemVariableCache->nextOid =3D This will make pg create the new table with the same oid as the previous on= e. - On primary session: drop table t; -- this triggers the replica to go down The reason it crashes on replica is that the recovery process is responsibl= e for dropping stats on commit, but it's not creating them on table creation. Thus, on the= second create table call, the old shared stats entry still exists (due to a backend still= have a ref to it), but it is never reinitialized by the logic in pgstat_reinit_entry(). On pri= mary it's not possible to reach this state, because heap_create() creates the stats entry immediat= ely when the table is created. I wonder what's the best way to fix this though. Should redo process call pgstat_create_relation somewhere, just like heap_c= reate does? Should we just ignore this 'drop stats twice' error on standby? -Floris