Reputation: 17932
Is there a way to programmatically check for a query's status in Redshift/PostgreSQL ? How do I know when a query has completed running ?
I have an application to run a series of SQL queries sequentially. It runs a query and waits for it to finish before executing the next query. I need to know when a query is done running.
I can't run them synchronously because sometimes, Redshift/PostgreSQL does not provide relinquish control after the query is done executing (for long queries). is there any way to do this ?
Upvotes: 2
Views: 3458
Reputation: 8647
Take a look at stv_recents table in Redshift.
For example to retrieve a list of currently running queries run:
select pid, trim(user_name), starttime, query
from stv_recents
where status = 'Running'
order by starttime ASC;
Upvotes: 4
Reputation: 14035
Redshift always relinquishes control when the query finishes. If your application is not receiving that control it means you've experienced a TCP timeout / keepalive issue.
Here are the docs for fixing this: http://docs.aws.amazon.com/redshift/latest/mgmt/connecting-firewall-guidance.html
Upvotes: 2