PostgreSQLのパーティションテーブル(Simulate Millions Data) – 第2部
PostgreSQLでテーブルパーティションを実行する方法がわからない場合は、
PostgreSQL(パーティションの作成)のパーティションテーブル – 第1部
ここでは、パーティションテーブルに何百万というデータを挿入する方法を示す簡単な関数を提供します。
--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百万のデータを挿入します。さて、私は10ヶ月で200万のデータを持っています。次のセッションでは、パーティションと非パーティションテーブル間のパフォーマンステストを開始します。リンク://database/performance-testing-on-partition-table-inをご覧ください。 -postgresql-part-3/[PostgreSQLのパーティションテーブルのパフォーマンステスト – 第3部]