Skip to content

Instantly share code, notes, and snippets.

@LRagji
Created July 31, 2020 07:28
Show Gist options
  • Save LRagji/cf0aac79556e26515959e83ec2334203 to your computer and use it in GitHub Desktop.
Save LRagji/cf0aac79556e26515959e83ec2334203 to your computer and use it in GitHub Desktop.
This script is used to run a stress test on timescaleDB by inserting huge rows to find the write speed

Use crontab DBInserts.txt to start a cron job Use crontab -l to view if jobs are qued User crontab -r to remove all jobs

Use the output log files to detect timings for write/sec

24 * * * * PGPASSWORD=postgres psql -h localhost -U postgres -d Test -f /home/ubuntu/inserts.sql >> /home/ubuntu/1.txt
\timing on
CREATE SEQUENCE IF NOT EXISTS "Counter" START 1;
DO $$
DECLARE
p_application_name TEXT;
BEGIN
select ('Bulk-Worker-'||pg_backend_pid()) INTO p_application_name;
RAISE INFO 'Setting Application Name To: %', p_application_name;
EXECUTE FORMAT('SET application_name = %L', p_application_name);
END$$;
INSERT INTO "Data"."Raw"("Timestamp", "Value", "Quality","TagId")
SELECT (TO_TIMESTAMP('2020-01-01 00:00:00','YYYY-MM-DD HH24:MI:SS')+ ((g||' second')::interval+(ctr||' year')::interval)),g,(g-1),ctr
FROM (select generate_series(1, 315360000) as g,* from nextval('"Counter"') as ctr) as g;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment