From: | Shay Patel <Shital(dot)Modi(at)microsoft(dot)com> |
---|---|
To: | "pgsql-sql(at)postgresql(dot)org" <pgsql-sql(at)postgresql(dot)org> |
Subject: | Detached partitioning tables with RF keys in latest minor version is changed |
Date: | 2025-04-14 19:25:38 |
Message-ID: | CH3PR21MB444484FF4ED0A83E17E97FC5EBB32@CH3PR21MB4444.namprd21.prod.outlook.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
Hello PostgreSQL SQL DEV team,
Prior to PostgreSQL version 15.7 AND 16.2, we were able to detach the partitioning table with RF keys without dropping the keys ,handled automatically.
Afterwards version must drop the RF keys to detach the partition, why it's not automatically handled like it's handled while attaching the partitioning tables with rf keys?
Now , our automation script stopped working and there is no single catalog table can give this information. Is there any catalog table which can query RF keys and it can list the it's tables?
It's frustrating that script stopped working due to minor version upgrade made those changes of dropping rf keys before detaching the partitioning tables.
Example :
--Create and set schema for the session
CREATE SCHEMA test_part;
SET SEARCH_PATH=test_part;
--Create a partitioned table
CREATE TABLE logs (
id integer not null,
log_date date not null,
message text
) PARTITION BY RANGE (log_date);
--Add primary key constraints in parent partition table
ALTER TABLE ONLY logs ADD primary key (id,log_date);
--Define partition for each month
CREATE TABLE logs_2024_01 PARTITION OF logs FOR VALUES FROM ('2024-01-01') TO ('2024-02-01');
CREATE TABLE logs_2024_02 PARTITION OF logs FOR VALUES FROM ('2024-02-01') TO ('2024-03-01');
--Create a Child partition table
CREATE TABLE logs_child (
id integer,
log_date date,
message text,
logs_parent_id integer
) PARTITION BY RANGE (log_date);
--Add constraints
ALTER TABLE ONLY logs_child ADD primary key (id,log_date);
ALTER TABLE logs_child add constraint logs_child_fk foreign key(logs_parent_id,log_date) references logs(id,log_date) ON DELETE CASCADE;
--Define a partition for each month
CREATE TABLE logs_child_2024_01 PARTITION OF logs_child FOR VALUES FROM ('2024-01-01') TO ('2024-02-01');
CREATE TABLE logs_child_2024_02 PARTITION OF logs_child FOR VALUES FROM ('2024-02-01') TO ('2024-03-01');
--Insert data into the parent partition table :
INSERT INTO logs (id,log_date, message) VALUES (1,'2024-01-15', 'Log message 1');
INSERT INTO logs (id,log_date, message) VALUES (11,'2024-01-15', 'Log message 1');
INSERT INTO logs (id,log_date, message) VALUES (2,'2024-02-15', 'Log message 2');
INSERT INTO logs (id,log_date, message) VALUES (22,'2024-02-15', 'Log message 2');
--Insert data into child partition table:
INSERT INTO logs_child values (1,'2024-01-15', 'Log message 1',1);
INSERT INTO logs_child values (2,'2024-01-15', 'Log message 1',1);
INSERT INTO logs_child values (5,'2024-02-15', 'Log message 2',22);
INSERT INTO logs_child values (6,'2024-02-15', 'Log message 2',2);
--Review data using Select
SELECT * FROM logs;
SELECT * FROM logs_2024_01;
SELECT * FROM logs_2024_02;
SELECT * FROM logs_child_2024_01;
SELECT * FROM logs_child_2024_02;
To find the keys there is no single catalog table can list the keys and tables the key belongs to. Can use distinct but it's not reliable, also can't find the partitioned table name where it belongs to.
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
[cid:image001(dot)png(at)01DBAD48(dot)68961B40]
--Detach partitioning table
ALTER TABLE logs_child DETACH PARTITION logs_child_2024_02;
ALTER TABLE logs_child_2024_02 DROP CONSTRAINT logs_child_fk;
ALTER TABLE logs DETACH PARTITION logs_2024_02;
Best,
Shay Patel
From | Date | Subject | |
---|---|---|---|
Previous Message | David G. Johnston | 2025-04-07 16:22:45 | Re: Re: Re: Revoke Connect Privilege from Database not working |