How do you stop a running query in SnowSQL - snowflake-cloud-data-platform

Is it possible to stop a running query in the SnowSQL command line tool? Let's say I made a mistake and I tried to run a heavy query.
Control-C, Esc, Q... nothing seems to stop it. The only way seems to be to send a kill command.
I also tried to stop a query when I'm paging but it seems like I'm forced to go through all pages before being able to stop.
Is there any way to stop queries in any of these two situations?

ctrl+c is working fine for me, I executed a simple query
select * from <HUGE TABLE>;
While the results are getting displayed on the command window I fired the ctrl+c
SnowSQL verion : v1.2.5
Operating System : Windows

This cancels the query.
SELECT SYSTEM$CANCEL_QUERY( 'query_id' )
The query ID can be obtained from the Account->History. Many companies do not allow access to account for developers, but can add permissions to allow access to query history.

Related

Why am I getting this Error with Apex/Oracle?

It is saying
ORA-00933: SQL command not properly ended
But I have no idea what I'm doing wrong. Each of these queries run on their own, but not together. What am I doing incorrectly?
In Apex SQL Workshop, you can run only one query at a time. How?
either by keeping only one query in the window and running it alone; then removing it and running another one (also alone)
or, select one query (with a mouse - paint the whole query "blue") and run it (you can click the "Run" button, or press "CTRL + ENTER"). When you have one query selected, you can keep as many other queried there as you want. That's probably a better option. See the screenshot:
If i have understood clearly then do you want get two different report from the SQL quires. I am afraid , is this functionality (running two different quires) separately in the same region would be possible in oracle apex. That could be the reason the apex is throwing error.

Can not cancel Queries

Ok Not sure what is going on here. I have runaway queries that won't cancel. I have one query to select all rows from a table that only has 250 rows and is 1.5KB in size. It's been running for 30 minutes right now and it should only take a few ms.
I've tried canceling by hitting the abort button on the worksheet, going into history and selecting the query and hitting abort, aborting based on the query ID via SQL, and aborting based on the session ID via SQL.
Ironically whenever I try to abort via SQL it shows that the queries have been terminated and then they still show as running, I wait a few minutes and re run the query and it again shows as terminated but they still are running.
I also tried loggin out and logging back in again and am seeing all kinds of weird errors:
Internal Error: Unable to retrieve the current roles.
Error
Problem with your MFA Enrollment: There was an issue with your enrollment
process. Please try again.
Worksheet Not Loaded
I have no idea what is going on but it seems like everywhere I turn there is an issue. Any assistance would be greatly appreciated.
Try logging completely out, close the browser, reboot your machine, and start from there. Here my guess:
Sometimes the query history (which I assume is where you were seeing things still running), needs a browser refresh, but based on MFA errors, refreshing your browser appears to have you logged out of your SAML/MFA process.
Once you successfully login, you'll likely see that the query had completed already before you even tried to cancel it.
If that isn't the case, and you are still seeing issues, then we'd probably need more information, or a quick call to Snowflake Support will walk you through things. My guess is this is all a display issue on your browser/UI, rather than something going wonky with Snowflake.

Performing the synchronization with ExecuteOfflineCommand more effectively

I'm wondering is there a way to recognize the OfflineComamd is being executed or internal flag or something to represent this command has been passed or mark it has been executed successfully. I have issue in recognizing the command is passed or not with unstable internet. I keep retrieve the records from database and comparing each and every time to see this has been passed or not. But due to the flow of my application, I'm finding it very difficult to avoid duplicates.IS there any automatic process to make sure commands executed automatically or something else?
2nd question, I can use UITimer to check isOffline() to make sure internet is connected or not on the forms. Is there something equivalent on server page or where queries is written to see internet is disconnected or not. When the control moved to queries and internet is disconnected I see the dialog open from form page being frozen for unlimited time and will not end. I have to close and re-open the app to continue the synchronization process.At the same time I cannot set a timeout for dialog because I'm not sure how long it will take the complete the Synchronization process. Please advise.
Extending on the same topic but I have created a new issue just to give more clarity on my questions.
executeOfflineCommand skips a command while executing from storage on Android
There is no way to know if a connection will stay stable as it requires knowledge of the future. You can work like transaction services do where the server side processes an offline command as a transaction using the approach of 2-phase commit.
In this approach you have an algorithm similar to this:
Client sends command to server
Server returns a special unique ID for the command
Client asks server to perform the unique id
Server acknowledges that the command was performed
If the first 2 stages didn't complete you just do that again. The worst thing that could happen is some orphan commands on the server.
If the 3rd option didn't complete you just do it again. The server knows whether it processed the command and will just acknowledge it if it was already processed.

Monitor that a website is active from SQL Agent

I want to test a portion of my website to see if it is running by executing a SQL server agent job. my site logs every time someone loads the login page. What I would like to do is launch:
https://www.example.com/Main/main_dir.wp1
after a few seconds run
SELECT * FROM dbo.TR_Weblog where DATEDIFF(MINUTE, date_time, getdate()) < 1
If there are no entries the site is down.
How do I launch a URL from inside agent?
IMO, this isn't an appropriate use of SQL Agent; it's not a general purpose task scheduler.
If you're going use Agent though...
I would advise against doing it the way #TheGameiswar suggests, as it will leave orphaned iexplore.exe processes on your SQL Server box, and there are situations where it won't even start properly - causing the process to stall out.
Instead, make your first step one of type PowerShell, and run the following command from it:
invoke-restmethod -URL YOURURLHERE
However, this will not parse/execute any JavaScript on the page, nor load any images. It'll just pull the raw HTML returned by the page when loaded.
But even this is a bit of a Rube Goldberg method of monitoring your website's availability when there are purpose-built applications/tools and services to do exactly that.
You can just select command type as cmd type and then use below url..
#START http://bing.com/
further ,you don't have any control after launch.So I think the best way is to do a periodic check of iis logs using log parser and see status

Is it possible to get a history of queries made in postgres

Is it possible to get a history of queries made in postgres? and is it be possible to get the time it took for each query? I'm currently trying to identify slow queries in the application I'm working on.
I'm using Postgres 8.3.5
There's no history in the database itself, if you're using psql you can use "\s" to see your command history there.
You can get future queries or other types of operations into the log files by setting log_statement in the postgresql.conf file. What you probably want instead is log_min_duration_statement, which if you set it to 0 will log all queries and their durations in the logs. That can be helpful once your apps goes live, if you set that to a higher value you'll only see the long running queries which can be helpful for optimization (you can run EXPLAIN ANALYZE on the queries you find there to figure out why they're slow).
Another handy thing to know in this area is that if you run psql and tell it "\timing", it will show how long every statement after that takes. So if you have a sql file that looks like this:
\timing
select 1;
You can run it with the right flags and see each statement interleaved with how long it took. Here's how and what the result looks like:
$ psql -ef test.sql
Timing is on.
select 1;
?column?
----------
1
(1 row)
Time: 1.196 ms
This is handy because you don't need to be database superuser to use it, unlike changing the config file, and it's easier to use if you're developing new code and want to test it out.
You can use like
\s
it will fetch you all command history of the terminal, to export it to file using
\s filename
If you want to identify slow queries, than the method is to use log_min_duration_statement setting (in postgresql.conf or set per-database with ALTER DATABASE SET).
When you logged the data, you can then use grep or some specialized tools - like pgFouine or my own analyzer - which lacks proper docs, but despite this - runs quite well.
If The question is the see the history of queries executed in the Command line. Answer is
As per Postgresql 9.3, Try \? in your command line, you will find all possible commands, in that search for history,
\s [FILE] display history or save it to file
in your command line, try \s. This will list the history of queries, you have executed in the current session. you can also save to the file, as shown below.
hms=# \s /tmp/save_queries.sql
Wrote history to file ".//tmp/save_queries.sql".
hms=#
FYI for those using the UI Navicat:
You MUST set your preferences to utilize a file as to where to store the history.
If this is blank your Navicat will be blank.
PS: I have no affiliation with or in association to Navicat or it's affiliates. Just looking to help.
There's no history in the database itself,but if you are using DataGrip data management tool then you can check the history thats your run in the datagrip.
pgBadger is another option - also listed here: https://github.com/dhamaniasad/awesome-postgres#utilities
Requires some additional setup in advance to capture the necessary data in the postgres logs though, see the official website.
Not logging but if you're troubleshooting slow running queries in realtime, you can query the pg_stat_activity view to see which queries are active, the user/connection they came from, when they started, etc. Eg...
SELECT *
FROM pg_stat_activity
WHERE state = 'active'
See the pg_stat_activity view docs.

Resources