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 1sWhbm-00Gogi-9w for pgsql-general@arkaria.postgresql.org; Wed, 24 Jul 2024 19:25:06 +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 1sWhbk-0080kP-67 for pgsql-general@arkaria.postgresql.org; Wed, 24 Jul 2024 19:25:04 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sWhbj-0080kH-Pv for pgsql-general@lists.postgresql.org; Wed, 24 Jul 2024 19:25:03 +0000 Received: from mail-yw1-x1131.google.com ([2607:f8b0:4864:20::1131]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1sWhbh-001HGn-Go for pgsql-general@lists.postgresql.org; Wed, 24 Jul 2024 19:25:03 +0000 Received: by mail-yw1-x1131.google.com with SMTP id 00721157ae682-651583964d8so167147b3.3 for ; Wed, 24 Jul 2024 12:25:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721849099; x=1722453899; darn=lists.postgresql.org; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=n9XQMANRmmNVm7iYfdZyJiiCqAc/fvtpSp2xDRi1Fcw=; b=hBP11Kd+kjZqMcvgrMz2mWkqJg2VPDiU5xC2n8SbE02QZC1hiMhknwp+QeEsq29ual UNk+Ryn9IiwpVc12Az4rgOOoks7axO5Vcn+GlkQElWUU1AmF29NktjpB+lff53/XC3bN zET3kbNLA310VavSwN1HYTDhyPD7IZwRn1GyNEu2UqaShCrUSZzzI+XCQD5Guy6aXf0f NYoRvwJMCTVqzxeXOAsDIHehJ8SCru8teLUgMNee+Tq+NOQjZY1EEFzhNXf57ZfpWWLo JoJ+tILI7HC1VGJkuZHkxXFfTaEsyOuwRP63Hnka5qgXKIeEFhlE1ak4Ee6RLkT5JTl/ ceAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721849099; x=1722453899; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=n9XQMANRmmNVm7iYfdZyJiiCqAc/fvtpSp2xDRi1Fcw=; b=p8wtVkzZBHrZZCUXbMZQBvslJfGrJ2jtaXz6DaYF3bXutorkD62NlRakZ8dnLyWdr7 6bB4WDhRTS/WRJx7I2VT02kfl7sVdfS6QbgF11MzgkmPv5SnWwK5h9GUqov+xz40LgCV OMtjRC3q/gec0Q+TbS/oEVk/PFXwGtY45L6QvI2iafrYN2maVi+R7G29Tw/clUHa5gft 0g3sF/PjpPwFmiJiUd7DfbWaf7weLM94kqUIDekQEbXzPTBBHoYvmE5hQXUUz81aFUuP 8HgFXu786AOTRa7rA4tsXVDdUVq7ryqPh6gq7GudLH6mvUrdx3H7JT32HJUk5vyu+ghT tTAA== X-Gm-Message-State: AOJu0YyD81nQGVXrOoJbasVm+Zbx4jRLkKMDnfNfGwi0f3PoW1CPY2Nr uPaRC2JDDgH3CkOPBbgOIN8Vl8FqpzoUP3ksGiblHTdFPE81qgLq0/NT1boAjlCtBkl6Xx802q0 7D9U6g+wdq6kf4fQgO9XeNnZthPWhCyCT X-Google-Smtp-Source: AGHT+IE6rpKa4463n8S7gkHwGureWdG+OB4hTttt2tO02TdUHB6Rr3KmnLFEwIQE7/aFfaighimiKy1A+0lg+jEhciM= X-Received: by 2002:a05:690c:dd2:b0:65f:da40:ec0 with SMTP id 00721157ae682-67521345aaamr2189827b3.3.1721849099188; Wed, 24 Jul 2024 12:24:59 -0700 (PDT) MIME-Version: 1.0 From: Lok P Date: Thu, 25 Jul 2024 00:54:47 +0530 Message-ID: Subject: Partition boundary messed up To: pgsql-general Content-Type: multipart/alternative; boundary="000000000000ea03ed061e033b78" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000ea03ed061e033b78 Content-Type: text/plain; charset="UTF-8" Hello All, We normally operate on UTC timezone so we normally create partitions in UTC timezone so that each day partition starts from today's midnight UTC to next day's midnight UTC. The script looks something like below. And also that way reference partition tables are also created in a similar way. Say for example the 29th august partition in parent partition reference to 29th august child partition as FK. This was working fine even for partition maintenance(mainly while dropping historical partitions) too without any issue. For one of the newly introduced partition tables, by mistake somebody created the initial partition definition without setting the timezone to UTC and all the partitions created are in different time zones. And as this table refers to another partition table (which is the parent and have partitions created in UTC timezone) the rows are spanning across two partitions and it's breaking the partition maintenance process while we try to drop the historical partition. Now the issue is that the newly introduced table already has billions of rows pumped into it spanning across 40 partitions. So is there an easy way to just alter the partition boundary to make it UTC midnight to midnight range? or The only way is to create a new table from scratch with the correct partition boundary in UTC timezone and then move the data and then create foreign key on that(which I believe is going to take a lot of time too)? Another thing we noticed, it shows initial partitions having boundaries in NON UTC (which we understand because of the missing timezone syntax) but then suddenly the subsequent partitions are getting created UTC too, not sure how it happened. And I believe it will create issues while rows come into the database which falls in between these ranges? Wondering if there is any easy way to correct this mess now? Note- This is postgres version 15+. Below partition creation script we use:- set timesozne='UTC'; SELECT partman.create_parent( p_parent_table := 'schema1.tab1', p_control := 'TRAN_DATE', p_type := 'native', p_interval := '1 day', p_premake := 90, p_start_partition => '2024-02-15 00:00:00' ); UPDATE partman.part_config SET infinite_time_partitions = 'true' , premake=20 WHERE parent_table = 'schema1.tab1'; CALL partman.run_maintenance_proc(); Below details i fetched from pg_class for the table which is messed up:- Partition_name Partition Expressions TAB1_p2024_08_29 FOR VALUES FROM ('2024-08-29 00:00:00+05:30') TO ('2024-08-30 00:00:00+05:30') TAB1_p2024_08_30 FOR VALUES FROM ('2024-08-30 00:00:00+05:30') TO ('2024-08-31 00:00:00+05:30') TAB1_p2024_08_31 FOR VALUES FROM ('2024-08-31 00:00:00+05:30') TO ('2024-09-01 00:00:00+05:30') TAB1_p2024_09_01 FOR VALUES FROM ('2024-09-01 00:00:00+05:30') TO ('2024-09-02 00:00:00+05:30') *TAB1_p2024_09_02 FOR VALUES FROM ('2024-09-02 00:00:00+05:30') TO ('2024-09-03 00:00:00+05:30')* *TAB1_p2024_09_03 FOR VALUES FROM ('2024-09-03 05:30:00+05:30') TO ('2024-09-04 05:30:00+05:30')*TAB1_p2024_09_04 FOR VALUES FROM ('2024-09-04 05:30:00+05:30') TO ('2024-09-05 05:30:00+05:30') TAB1_p2024_09_05 FOR VALUES FROM ('2024-09-05 05:30:00+05:30') TO ('2024-09-06 05:30:00+05:30') TAB1_p2024_09_06 FOR VALUES FROM ('2024-09-06 05:30:00+05:30') TO ('2024-09-07 05:30:00+05:30') Regards Lok --000000000000ea03ed061e033b78 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hello All,
We normally operate on UTC timezone so we no= rmally create partitions in UTC timezone so that each day partition starts = from today's midnight UTC to next day's midnight UTC. The script lo= oks something like below. And also that way reference partition tables are = also created in a similar way. Say for example the 29th august partition in= parent partition reference to 29th august child partition as FK. This was = working fine even for partition maintenance(mainly while dropping historica= l partitions) too without any issue.

For one of the newly introduced= partition tables, by mistake somebody created the initial partition defini= tion without setting the timezone to UTC and all the partitions created are= in different time zones. And as this table refers to another partition tab= le (which is the parent and have partitions created in UTC timezone) the ro= ws are spanning across two partitions and it's breaking the partition m= aintenance process while we try to drop the historical partition.

No= w the issue is that the newly introduced table already has billions of rows= pumped into it spanning across 40 partitions. So is there an easy way to j= ust alter the partition boundary to make it UTC midnight to midnight range?=
or
The only way is to create a new table from scratch with the cor= rect partition boundary in UTC timezone and then move the data and then cre= ate foreign key on that(which I believe is going to take a lot of time too)= ?

Another thing we noticed, it shows initial partitions having bound= aries in NON UTC (which we understand because of the missing timezone synta= x) but then suddenly the subsequent partitions are getting created UTC too,= not sure how it happened. And I believe it will create issues while rows c= ome into the database which falls in between these ranges? Wondering if the= re is any easy way to correct this mess now? Note- This is postgres version= 15+.

Below partition creation script we use:-
set timesozne=3D'UTC';
= SELECT partman.create_parent(
=C2=A0 =C2=A0p_pa= rent_table :=3D 'schema1.tab1',
=C2=A0 =C2=A0p_control :=3D '= ;TRAN_DATE',
=C2=A0 =C2=A0p_type :=3D 'native',
=C2=A0 = =C2=A0p_interval :=3D '1 day',
=C2=A0 =C2=A0p_premake :=3D 90,=C2=A0 =C2=A0p_start_partition =3D> '2024-02-15 00:00:00'
)= ;
UPDATE partman.part_config SET infinite_time_partitions =3D 'true&= #39; , premake=3D20 WHERE parent_table =3D 'schema1.tab1';
CALL = partman.run_maintenance_proc();


Below details i fetched from= =C2=A0 pg_class for the table which is messed up:-

Partition_name =C2=A0 =C2=A0 =C2=A0 Partition Expressions
TAB1_p= 2024_08_29 FOR VALUES FROM ('2024-08-29 00:00:00+05:30') TO ('2= 024-08-30 00:00:00+05:30')
TAB1_p2024_08_30 FOR VALUES FROM ('20= 24-08-30 00:00:00+05:30') TO ('2024-08-31 00:00:00+05:30')
T= AB1_p2024_08_31 FOR VALUES FROM ('2024-08-31 00:00:00+05:30') TO (&= #39;2024-09-01 00:00:00+05:30')
TAB1_p2024_09_01 FOR VALUES FROM (&#= 39;2024-09-01 00:00:00+05:30') TO ('2024-09-02 00:00:00+05:30')=
TAB1_p2024_09_02 FOR VALUES FROM ('2024-09-02 00:00:00+05:30'= ;) TO ('2024-09-03 00:00:00+05:30')
TAB1_p2024_09_03 FOR = VALUES FROM ('2024-09-03 05:30:00+05:30') TO ('2024-09-04 05:30= :00+05:30')
TAB1_p2024_09_04 FOR VALUES FROM ('2024-09-04 05= :30:00+05:30') TO ('2024-09-05 05:30:00+05:30')
TAB1_p2024_0= 9_05 FOR VALUES FROM ('2024-09-05 05:30:00+05:30') TO ('2024-09= -06 05:30:00+05:30')
TAB1_p2024_09_06 FOR VALUES FROM ('2024-09-= 06 05:30:00+05:30') TO ('2024-09-07 05:30:00+05:30')

=

Regards
Lok
<= /div>
--000000000000ea03ed061e033b78--