To test my application I need a query to run for a long time (at least a couple of minutes). Any ideas on how to create this quickly?
The application needs to query the catalog to see a list of running queries.
My application uses postgresql. I am fine with creating additional dummy tables if required.
Some of the tricks we used to speed up SELECT-s in PostgreSQL: LEFT JOIN with redundant conditions, VALUES, extended statistics, primary key type conversion, CLUSTER, pg_hint_plan + bonus. Photo by Richard Jacobs on Unsplash.
So How Do You Fix Slow Queries in PostgreSQL? To speed up this particular PostgreSQL slow query, we need to know whether we really need all rows. If not, we should only get N of them by adding a LIMIT clause. If they are, we should use a cursor.
PostgreSQL attempts to do a lot of its work in memory, and spread out writing to disk to minimize bottlenecks, but on an overloaded system with heavy writing, it's easily possible to see heavy reads and writes cause the whole system to slow as it catches up on the demands.
Typically discovered through slow response or extended increases in database CPU, the pg_stat_activity view can help to find out what query is causing issues. The pg_stat_activity view contains details of all currently running queries, including user, connection, and timing details.
this will run for 5 minutes:
select pg_sleep(5 * 60);
the parameter for pg_sleep()
is the duration in seconds.
You can also sleep until a specific timestamp using pg_sleep_until()
More details in the manual:
http://www.postgresql.org/docs/9.5/static/functions-datetime.html#FUNCTIONS-DATETIME-DELAY
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With