0

我有一个名为 datapoint 的分区表,它有像 datapoint_s1、datapoint_s2 等子表...

我有另一个名为 device 的表,它具有数据点表的外键。

这是故事;

包含所有分区表的数据点表大约为 100GB。我截断了 datapoint_s2 表。之后,我想删除属于 datapoints_s2 表的设备。此外,与我要删除的设备相关的其他分区表中没有数据。虽然datapoint_s2表是空的,COMMIT;正在等待一个多小时才能完成过程。

编辑:当我取消查询时,发生了这个错误。

ERROR:  canceling statement due to user request
CONTEXT:  SQL statement "SELECT 1 FROM "public"."datapoint" x WHERE $1 OPERATOR(pg_catalog.=) "device_id" FOR KEY SHARE OF x"

如何使分区表中的设备删除过程更快?

编辑:

父表说明:

                                                      Table "public.datapoint"
   Column   |           Type           | Collation | Nullable |                Default                | Storage  | Stats target | Description
------------+--------------------------+-----------+----------+---------------------------------------+----------+--------------+-------------
 id         | bigint                   |           | not null | nextval('datapoint_id_seq'::regclass) | plain    |              |
 station_id | integer                  |           | not null |                                       | plain    |              |
 device_id  | integer                  |           | not null |                                       | plain    |              |
 data       | jsonb                    |           |          |                                       | extended |              |
 created_at | timestamp with time zone |           | not null |                                       | plain    |              |
Partition key: LIST (station_id)
Indexes:
    "datapoint_uniq" UNIQUE CONSTRAINT, btree (station_id, device_id, created_at)
Foreign-key constraints:
    "datapoint_device_id_fk" FOREIGN KEY (device_id) REFERENCES device(id) DEFERRABLE INITIALLY DEFERRED
    "datapoint_station_id_fk" FOREIGN KEY (station_id) REFERENCES station(id) DEFERRABLE INITIALLY DEFERRED
Partitions: datapoint_s2 FOR VALUES IN (10),
            datapoint_s3 FOR VALUES IN (11),
            ....

子表说明:

                                                    Table "public.datapoint_s2"
   Column   |           Type           | Collation | Nullable |                Default                | Storage  | Stats target | Description
------------+--------------------------+-----------+----------+---------------------------------------+----------+--------------+-------------
 id         | bigint                   |           | not null | nextval('datapoint_id_seq'::regclass) | plain    |              |
 station_id | integer                  |           | not null |                                       | plain    |              |
 device_id  | integer                  |           | not null |                                       | plain    |              |
 data       | jsonb                    |           |          |                                       | extended |              |
 created_at | timestamp with time zone |           | not null |                                       | plain    |              |
Partition of: solarify_datapoint FOR VALUES IN (2)
Partition constraint: ((station_id IS NOT NULL) AND (station_id = 2))
Indexes:
    "datapoint_s2_station_id_device_id_created_at_key" UNIQUE CONSTRAINT, btree (station_id, device_id, created_at)
Foreign-key constraints:
    "datapoint_device_id_fk" FOREIGN KEY (device_id) REFERENCES device(id) DEFERRABLE INITIALLY DEFERRED
    "datapoint_station_id_fk" FOREIGN KEY (station_id) REFERENCES station(id) DEFERRABLE INITIALLY DEFERRED
4

0 回答 0