Postgresql query in 10 seconds

Is there a way to create a query that will work exactly ten seconds? I do not need real data to just run a query for a long time, so I can check how the system works at that time.

I would prefer not to create a huge table and make a simple choice for this. Any tricks?

+4
source share
3 answers

pg_sleep :

 SELECT pg_sleep(10); 

But this will not cause any load on the system, if this is your real goal.

+6
source
 SET statement_timeout to '10s'; SELECT 1 FROM pg_class CROSS JOIN pg_class CROSS JOIN pg_class ...; -- be careful ;-) 

Note that this will emphasize the CPU and RAM, but not necessarily the drive. If you want to emphasize the disk, you probably just have to create a very large table. To do this, you can save the query results above or from any other solution to a new table ( CREATE TABLE AS ).

+4
source

You can also run pgbench with the -T switch. So that...

pgbench -i -s 10

pgbench -c 10 -T 10

0
source

Source: https://habr.com/ru/post/1336923/


All Articles