如果不知道该怎么在PostgreSQL中做表分区,请学习分区表在PostgreSQL(创建分区)
在这里,我将提供一个简单的函数来演示如何将数据插入百万数据到分区表。
--create sequence for testing CREATE SEQUENCE hashvalue_PT_serial START 1; --Generate Dynamic data for testing CREATE OR REPLACE FUNCTION hashvalue_PT_InsertRandomRecords(in a_no_of_records integer) RETURNS integer AS $$ DECLARE v_counter integer; vhash varchar(255); v_date varchar(15); BEGIN v_counter := 1; RAISE NOTICE 'No of records insert : %', a_no_of_records; WHILE (v_counter <= a_no_of_records) LOOP IF( v_counter % 10000 =0) THEN RAISE NOTICE 'Counter here is %', v_counter; END IF; v_date := trunc(random() * 27) +1; vhash := '00' || nextval('hashvalue_PT_serial'); --insert into partiton table INSERT INTO hashvalue_pt( hash, hashtime) VALUES (E'\\003\\002\\001\\0151'::bytea || vhash::bytea , date ('2008-01-' || v_date)); INSERT INTO hashvalue_pt( hash, hashtime) VALUES (E'\\003\\002\\001\\0151'::bytea || vhash::bytea, date ('2008-02-' || v_date)); INSERT INTO hashvalue_pt( hash, hashtime) VALUES (E'\\003\\002\\001\\0151'::bytea || vhash::bytea, date ('2008-03-' || v_date)); INSERT INTO hashvalue_pt( hash, hashtime) VALUES (E'\\003\\002\\001\\0151'::bytea || vhash::bytea, date ('2008-04-' || v_date)); INSERT INTO hashvalue_pt( hash, hashtime) VALUES (E'\\003\\002\\001\\0151'::bytea || vhash::bytea, date ('2008-05-' || v_date)); INSERT INTO hashvalue_pt( hash, hashtime) VALUES (E'\\003\\002\\001\\0151'::bytea || vhash::bytea , date ('2008-06-' || v_date)); INSERT INTO hashvalue_pt( hash, hashtime) VALUES (E'\\003\\002\\001\\0151'::bytea || vhash::bytea, date ('2008-07-' || v_date)); INSERT INTO hashvalue_pt( hash, hashtime) VALUES (E'\\003\\002\\001\\0151'::bytea || vhash::bytea, date ('2008-08-' || v_date)); INSERT INTO hashvalue_pt( hash, hashtime) VALUES (E'\\003\\002\\001\\0151'::bytea || vhash::bytea, date ('2008-09-' || v_date)); INSERT INTO hashvalue_pt( hash, hashtime) VALUES (E'\\003\\002\\001\\0151'::bytea || vhash::bytea, date ('2008-10-' || v_date)); v_counter := v_counter + 1; END LOOP; RETURN 0; END; $$ LANGUAGE plpgsql;
这里创建了一个简单的“hashvalue_PT_InsertRandomRecords”函数来模拟对分区表的性能测试数据。
select * from hashvalue_PT_InsertRandomRecords(20000000);
一下子插入200百万的数据。下一个小节,将开始做分区和非分区表,测试分区表在PostgreSQL之间的一些性能测试
易百教程移动端:请扫描本页面底部(右侧)二维码并关注微信公众号,回复:"教程" 选择相关教程阅读或直接访问:http://m.yiibai.com 。
加QQ群啦,易百教程官方技术学习群
注意:建议每个人选自己的技术方向加群,同一个QQ最多限加 3 个群。
- Java技术群: 227270512 (人数:2000,免费:否)
- MySQL/SQL群: 418407075 (人数:2000,免费:否)
- 大数据开发群: 655154550 (人数:2000,免费:否)
- Python技术群: 287904175 (人数:2000,免费:否)
- 人工智能深度学习: 456236082 (人数:2000,免费:否)
- 测试工程师(新群): 415553199 (人数:1000,免费:否)
- 前端技术群(新群): 410430016 (人数:1000,免费:是)
- C/C++技术(新群): 629264796 (人数:1000,免费:是)
- Node.js技术(新群): 621549808 (人数:1000,免费:是)
- PostgreSQL数据库(新群): 539504187 (人数:1000,免费:是)
- Linux技术: 479429477 (人数:2000,免费:否)
- PHP开发者: 460153241 (人数:2000,免费:否)
- Oracle数据库: 175248146 (人数:2000,免费:否)
- C#/ASP.Net开发者: 579821706 (人数:2000,免费:是)
- 数据分析师: 397883996 (人数:2000,免费:是)R语言,Matlab语言等技术