006.PGSQL-資料傾斜、資料各節點分佈情況;建立序列、建立分散式表
阿新 • • 發佈:2020-08-03
資料傾斜、資料各節點分佈情況、建立分散式表
查看錶的分佈節點
-- 查看錶是否資料傾斜
select table_skewness('b_st_yz_aj_cgajfj');
-- 在哪個節點分佈
-- 查看錶是否資料傾斜 select table_skewness('b_st_yz_aj_cgajfj'); -- 在哪個節點分佈 select xc_node_id, count(1) from tablename group by xc_node_id order by xc_node_id desc;
建立序列、建立分散式表
建立序列
CREATE SEQUENCE "ioc_theme"."m_ss_qyqy_move_warn_success_rid_seq" INCREMENT1 MINVALUE 1 MAXVALUE 9223372036854775807 START 1 CACHE 1 CYCLE ; SELECT setval('"ioc_theme"."m_ss_qyqy_move_warn_success_rid_seq"', -1, false); ALTER SEQUENCE "ioc_theme"."m_ss_qyqy_move_warn_success_rid_seq" OWNER TO "zsj_qh";
刪除序列 修改序列
----刪除前先解除 id 對該序列的依賴 ALTER TABLE tablename ALTER COLUMN id SETDEFAULT null; DROP SEQUENCE IF EXISTS sequence_name; 修改自增序列開始值 ---- id_max 即 id 目前的最大值,可寫為1,可通過 “SELECT MAX(id) FROM tablename” 得到 CREATE SEQUENCE sequence_name START WITH id_max; 修改自增序列所屬的表和欄位 ALTER TABLE ioc_theme.m_ss_yqjc_sbryxxb_51_af ALTER COLUMN rid SET DEFAULT nextval('ioc_theme.m_ss_yqjc_sbryxxb_51_af_rid_seq'::regclass);
查詢表的序列
select table_schema, table_name, column_name, data_type, column_default, is_nullable from information_schema.columns where table_name = 'm_gd_yqjc_sbryxxb_0501_0520';
建立分散式表
CREATE TABLE "ioc_theme"."m_hz_cyrk_rk_education" ( "rid" int4 NOT NULL DEFAULT nextval('"ioc_theme".m_hz_cyrk_rk_education_rid_seq'::regclass), "occur_period" int4, "occur_period_year" int4, "occur_period_month" int4, "area_code_abode" varchar(20) COLLATE "pg_catalog"."default", "area_code_work" varchar(20) COLLATE "pg_catalog"."default", "degree" varchar(40) COLLATE "pg_catalog"."default", "employ_num" int4, "employ_ratio" numeric(20,2), "create_time" timestamp(6) DEFAULT pg_systimestamp(), "update_time" timestamp(6) DEFAULT pg_systimestamp(), CONSTRAINT "m_hz_cyrk_rk_education_pkey" PRIMARY KEY ("rid") ) ; ALTER TABLE "ioc_theme"."m_hz_cyrk_rk_education" OWNER TO "zsj_qh"; COMMENT ON COLUMN "ioc_theme"."m_hz_cyrk_rk_education"."rid" IS '行ID'; COMMENT ON COLUMN "ioc_theme"."m_hz_cyrk_rk_education"."occur_period" IS '報告期'; COMMENT ON COLUMN "ioc_theme"."m_hz_cyrk_rk_education"."occur_period_year" IS '報告期(年)'; COMMENT ON COLUMN "ioc_theme"."m_hz_cyrk_rk_education"."occur_period_month" IS '報告期(月)'; COMMENT ON COLUMN "ioc_theme"."m_hz_cyrk_rk_education"."area_code_abode" IS '居住地行政區劃程式碼(社群)'; COMMENT ON COLUMN "ioc_theme"."m_hz_cyrk_rk_education"."area_code_work" IS '工作地行政區劃程式碼'; COMMENT ON COLUMN "ioc_theme"."m_hz_cyrk_rk_education"."degree" IS '學歷'; COMMENT ON COLUMN "ioc_theme"."m_hz_cyrk_rk_education"."employ_num" IS '人數'; COMMENT ON COLUMN "ioc_theme"."m_hz_cyrk_rk_education"."employ_ratio" IS '佔比'; COMMENT ON COLUMN "ioc_theme"."m_hz_cyrk_rk_education"."create_time" IS '資料建立時間'; COMMENT ON COLUMN "ioc_theme"."m_hz_cyrk_rk_education"."update_time" IS '更新時間'; COMMENT ON TABLE "ioc_theme"."m_hz_cyrk_rk_education" IS '人才專題介面';