我有一個關於時間字段partitoned的表。我有25個分區。現在我考慮使用對象類型字段進一步分割它。我有十個對象類型,所以它將導致250個分區。根據我所讀到的,建議的分區數量是幾十個,但在我的情況下,這個模式非常簡單,並且不包含任何聯接,所以我想知道它是否是o.k.定義多個分區。我正在使用postgres版本9.1.2Postgres的分區號
CREATE TABLE metric_store.lc_aggregated_data_master_10_minutes
(
from_time integer,
object_id integer,
object_type integer,
latencies_client_fetch_sec_sum bigint,
latencies_client_rttsec_sum bigint,
latencies_db_bci_res_sec_sum bigint,
latencies_net_infrastructure_ttlb_sec_sum bigint,
latencies_retransmissions_sec_sum bigint,
latencies_ttfbsec_sum bigint,
latencies_ttlbsec_sum bigint,
latencies_ttlbsec_sumsqr bigint,
latencies_ttlbsec_histogram_level0 integer,
latencies_ttlbsec_histogram_level1 integer,
latencies_ttlbsec_histogram_level2 integer,
latencies_ttlbsec_histogram_level3 integer,
latencies_ttlbsec_histogram_level4 integer,
latencies_ttlbsec_histogram_level5 integer,
latencies_ttlbsec_histogram_level6 integer,
latencies_ttlbsec_histogram_level7 integer,
usage_bytes_total bigint,
usage_hits_total integer,
latencies_server_net_ttlbsec_sum bigint,
latencies_server_rttsec_sum bigint,
avaiability_errors_total integer
)
WITH (
OIDS=FALSE
);
ALTER TABLE metric_store.lc_aggregated_data_master_10_minutes
OWNER TO postgres;
CREATE TABLE metric_store.lc_aggregated_data_10_minutes_from_1353070800
(
CONSTRAINT lc_aggregated_data_10_minutes_from_1353070800_pkey PRIMARY KEY (from_time , object_id),
CONSTRAINT lc_aggregated_data_10_minutes_from_1353070800_from_time_check CHECK (from_time >= 1353070800 AND from_time < 1353190800)
)
INHERITS (metric_store.lc_aggregated_data_master_10_minutes)
WITH (
OIDS=FALSE
);
ALTER TABLE metric_store.lc_aggregated_data_10_minutes_from_1353070800
OWNER TO postgres;
CREATE INDEX lc_aggregated_data_10_minutes_from_1353070800_obj_typ_idx
ON metric_store.lc_aggregated_data_10_minutes_from_1353070800
USING btree
(from_time , object_type);
有多少行?你確定未分區表的查詢是否儘可能好? (分區對於良好的索引是一個不好的替代品。)更快的硬件是更好的解決方案嗎? (分區對於一個足夠的服務器來說也是一個糟糕的替代品。) –
它大約有1000萬行。我有對象類型的索引,但對超過100個時間點的許多對象ID的查詢很慢,因爲很多隨機訪問尋找磁盤。將數據分解爲較小的分區會產生性能提升,因爲我通常在查詢中查詢相同的對象類型。 – user1817686
1000萬行不是一個巨大的表。如果我是你,我會先尋求調整未分區表的建議。此外,版本9.2只有索引掃描,但我認爲這不會對您有所幫助。 –