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 1sXcwe-005EZ9-Ic for pgsql-general@arkaria.postgresql.org; Sat, 27 Jul 2024 08:38:28 +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 1sXcwd-003eyl-4L for pgsql-general@arkaria.postgresql.org; Sat, 27 Jul 2024 08:38:27 +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 1sXcwc-003eyd-Fk for pgsql-general@lists.postgresql.org; Sat, 27 Jul 2024 08:38:26 +0000 Received: from mail-qv1-xf2d.google.com ([2607:f8b0:4864:20::f2d]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1sXcwZ-001gnT-6C for pgsql-general@lists.postgresql.org; Sat, 27 Jul 2024 08:38:24 +0000 Received: by mail-qv1-xf2d.google.com with SMTP id 6a1803df08f44-6b795574f9dso8284256d6.0 for ; Sat, 27 Jul 2024 01:38:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722069502; x=1722674302; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=EK/XdSeSDHu/U6QQfyjnhJO9kULxSmM4um/BUwEgmrg=; b=RXEIIsA5m0fhc7DOJs025wGpEjG0MuPi5hg1bLkICdHJERVWC0DXJLqWsHIKCAxZQI ouDHZUf3wg8C+X/WPFo6KmZzBHNhfTRMUAMDJEulkL1uqxGbLjyjmH7zxXYSvl13muXF 3ChE7+TejThJCWvc+8kAZ0PNqEWbC4FTNwFHvV2OT1+6+VJTFjCCvVzrj1RwnLAw5odR Au4pLduOB+tOkrO1e3t1xKQRTslCP9m9Xx/tbZhJ/e4StxSSHRtuZGlPnlmClifLHkyC q4xTiRMis5KMJp7ukgvwNMOrkjiz11X+wtPNPR6z4QBMiRgzgHowSwm5zYhvmjVBdRta Xyrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722069502; x=1722674302; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=EK/XdSeSDHu/U6QQfyjnhJO9kULxSmM4um/BUwEgmrg=; b=Gvf5kxDHYwj6iLg6CQl9YybAc8t3jdri/+BUg4B1rkp08IalEWRCu+HHFhfdyyYdtK f/ClfRjx5NVZ2TjJ3y9LNLBSoCjpehejjjhg6FMjUt/AvwtczCxTAFZHKpJOHKprOAis uMrkCo9Neq8jMpT0vocysemfVwiFF8oOWUY5NMmk2q9pX5m4yAw6en8O2+SXwDs4HxMT Wma0zNZy9f9b9i1KaFUvjHZgn4VNK5F7iLPuG5kZD916LrxA7CvZ2jLdryLEV+TPbOCw 89S6ChriUlZAcluMxmvfXDRLP8HPRfMo7f6cbQtRzDmZtBZhhbOuiTa//NzWUIIsC0Vm c+GQ== X-Gm-Message-State: AOJu0YwdMdPkpj4KijORKQJAUIb1tVuJAUgvD3n3NrQWRqmnfELQiGWk Ry4HoFOCRtzeYUG0qTkyjH3iDGbJY7o9b7jE5czX5rPh7OmYjeSG4zkvy5bQwJv/u5NOG1TRN0B L46M1LlvXjMzHkghbQGoYqQ3MPx4= X-Google-Smtp-Source: AGHT+IHzT6Mrm633Bq6sKM+xVE66d3h6k5mwQAzZpA9cHpSviHSxaC+SC3PGBSYo3hEuu66XMac34EAmQNy1aDjMdFI= X-Received: by 2002:a05:6214:c21:b0:6b7:a200:8c9a with SMTP id 6a1803df08f44-6bb55a21fc9mr22038566d6.22.1722069502372; Sat, 27 Jul 2024 01:38:22 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: yudhi s Date: Sat, 27 Jul 2024 14:08:11 +0530 Message-ID: Subject: Re: Partition boundary messed up To: Lok P Cc: pgsql-general Content-Type: multipart/alternative; boundary="000000000000f7b674061e368c57" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000f7b674061e368c57 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable If you were thinking of some ALTER command which will just alter the boundaries of the incorrect partition and make it correct , I don't think there exists any such. You may have to create a whole new table and run the partman.create_parent block with the UTC time zone set so that all the subsequent partitions will be created with correct boundaries and then move the data into it from the existing table. On Thu, Jul 25, 2024 at 12:55=E2=80=AFAM Lok P wrote= : > 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. Sa= y > for example the 29th august partition in parent partition reference to 29= th > 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 th= is > 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 t= ry > 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 wa= y > 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 i= n > 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=3D'UTC'; > SELECT partman.create_parent( > p_parent_table :=3D 'schema1.tab1', > p_control :=3D 'TRAN_DATE', > p_type :=3D 'native', > p_interval :=3D '1 day', > p_premake :=3D 90, > p_start_partition =3D> '2024-02-15 00:00:00' > ); > UPDATE partman.part_config SET infinite_time_partitions =3D 'true' , > premake=3D20 WHERE parent_table =3D '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 > --000000000000f7b674061e368c57 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
If you were thinking of some ALTER command which will= just alter the boundaries=C2=A0of the incorrect=C2=A0partition and make it= correct=C2=A0,=C2=A0 I don't think there exists any such. You may have= to create a whole new table and run the partman.create_parent block with t= he UTC time zone=C2=A0set so that all the subsequent partitions will be cre= ated with correct=C2=A0boundaries and then move the data into it from the e= xisting=C2=A0table.

On Thu, Jul 25, 2024 at 12:55=E2=80=AFAM = Lok P <loknath.73@gmail.com&= gt; wrote:
Hello All,
We normally operate on UTC timezone so we normall= y 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 s= omething like below. And also that way reference partition tables are also = created in a similar way. Say for example the 29th august partition in pare= nt partition reference to 29th august child partition as FK. This was worki= ng fine even for partition maintenance(mainly while dropping historical par= titions) too without any issue.

For one of the newly introduced part= ition tables, by mistake somebody created the initial partition definition = without setting the timezone to UTC and all the partitions created are in d= ifferent time zones. And as this table refers to another partition table (w= hich is the parent and have partitions created in UTC timezone) the rows ar= e spanning across two partitions and it's breaking the partition mainte= nance process while we try to drop the historical partition.

Now the= issue is that the newly introduced table already has billions of rows pump= ed into it spanning across 40 partitions. So is there an easy way to just a= lter 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 f= oreign 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) bu= t 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 i= nto 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=3D'UTC';
SELECT partman.create_parent(
=C2=A0 =C2=A0p_parent_= 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' = , premake=3D20 WHERE parent_table =3D 'schema1.tab1';
CALL partm= an.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_p2024_0= 8_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_p2= 024_08_31 FOR VALUES FROM ('2024-08-31 00:00:00+05:30') TO ('20= 24-09-01 00:00:00+05:30')
TAB1_p2024_09_01 FOR VALUES FROM ('202= 4-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 F= OR 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')

<= font face=3D"monospace">
Rega= rds
Lok
<= /div>


=C2=A0
--000000000000f7b674061e368c57--