How to check the status of long running DB2 query? - db2

I am running a db2 query that unions two very large tables. I started the query 10 hours ago, and it doesn't seem to finish yet.
However, when I check the status of the process by using top, it shows the status is 'S'. Does this mean that my query stopped running? But I couldn't find any error message.
How can I check what is happening to the query?

In DB2 for LUW 11.1 there is a text-based dsmtop utility that allows you to monitor the DB2 instance, down to individual executing statements, in real time. It's pre-11.1 equivalent is called db2top.
There is also a Web-based application, IBM Data Server Manager, which has a free edition with basic monitoring features.
Finally, you can query one of the supplied SQL monitor interfaces, for example, the SYSIBMADM.MON_CURRENT_SQL view:
SELECT session_auth_id,
application_handle,
elapsed_time_sec,
activity_state,
rows_read,
SUBSTR(stmt_text,1,200)
FROM sysibmadm.mon_current_sql
ORDER BY elapsed_time_sec DESC
FETCH FIRST 5 ROWS ONLY

You can try this command as well
db2 "SELECT agent_id,
Substr(appl_name, 1, 20) AS APPLNAME,
elapsed_time_min,
Substr(authid, 1, 10) AS AUTH_ID,
agent_id,
appl_status,
Substr(stmt_text, 1, 30) AS STATEMENT
FROM sysibmadm.long_running_sql
WHERE elapsed_time_min > 0
ORDER BY elapsed_time_min desc
FETCH first 5 ROWS only"

Related

When i run a specific query i get , ORA-00604: error occurred at recursive SQL level 1 ORA-12899: value too large for column"PLAN_TABLE"."OBJECT_NAME"

Am using Oracle 12.1 c when i run specific query ( i cant show for security reason , and because its un related); i get exception
ORA-00604: error occurred at recursive SQL
level 1 ORA-12899: value too large for column "SOME_SCHEMA"."PLAN_TABLE"."OBJECT_NAME"
(actual: 38, maximum: 30)
I cant make it work , i will try revert last changes i did because it was working before.
BTW i was doing Explain and doing index optimizations
Any idea why!
P.S i will keep trying
How i solved this:
When i was reverting and reviewing my last changes i was doing alters for adding indexes, and each time i try to run the query again to make sure it is working.
So when i reached a specific alter i noticed the name of the index is too long,
so even if the index was created successfully, but the explain plan for select
was failing not the select it self.
The solution:
I renamed the index to be shorter ( 30 maximum ) it worked
Change table/column/index names size in oracle 11g or 12c
Why are Oracle table/column/index names limited to 30 characters?
Using EXPLAIN PLAN Oracle websites docs

How to make a Cassandra connection using CQL used to create a table?

I am new to tableau, gone through the site before having this question posted, didn't found answer matching to my question.
I have connection established successfully to Cassandra using "DataStax cassandra ODBC driver 64bit windows", evrything is fine, filled all details like "keyspace name, table name as per documentation available in Datastax site".
But when I drag the available table to canvas it's keep on loading for minutes, what the database guy has told me about the data is it's more millions of data for one day, so we have 6months data and that to data gets updated for every 10 minutes, it;s for a reputed wind energy company.
My client has given me "" CQL used for creating table:
create table abc_data_test.machine_data
(machine_id text, tag text, timestamp timestamp, value double,
PRIMARY KEY((machine_id, tag), timestamp))
WITH CLUSTERING ORDER BY(timestamp DESC)
AND compression = { 'sstable_compression' : 'LZ4Compressor' };"".
Where to keep this code?
I tried to insert in connection page it's giving a error. I am getting a new custom sql error (I placed the code in "new custom sql" ) .
The time is still running, can be seen as:
processing request: connecting to datasource, Elapsed time 87:09
The error from new custom sql is
An error occured while commuicating with the datasource. [DataStax][CassandraODBC] (10) Error while executing a query in Cassandra:33562624: line 1.11 no viable alternative at input '1' (SELECT [TOP]1...)
I'm using windows 10 64bit, DataStax odbc driver 64bit-2.4.1 version,DSE is4.8 and later .
You cannot pass DDL sql into the custom sql box. If the Cassandra connection supports the Initial SQL option, you could pass it there. Then your custom sql would be some sort of select statement. Otherwise, create the table in Cassandra then connect to that table from Tableau.

How can I check a query execution?

I am working on a project where I came across on a sql query. I want see the execution flow fully. i.e how the query executed on database. what can I do for this?
can any body help me for this?
Atomic Operations
The query will be an atomic operation so that you could set table A.Description = table B.Description without having to worry about overwriting the data from either table.
A great book on sql querying -The book that you need to read is Inside Microsoft® SQL Server® 2008: T-SQL Querying. This will show you exactly how a query is processed. You can also use Display Estimated Execution Plan / Show Actual Execution Plan setting in sql server management studio to see a visual plan. You can right click the query pane to toggle them on and off. You will have to figure out how to read it first.
Actual Order of query based on Itzak Ben-Gan in the book.
1 FROM
2 ON <join_condition>
3 <join_type> JOIN <right_table>
4 WHERE <where_condition>
5 GROUP BY <group_by_list>
6 WITH { CUBE | ROLEUP }
7 HAVING <having_condition>
8 SELECT
9 DISTINCT
10 ORDER BY <order_by_list>
11 TOP

SELECT old data state with DB2

Is it possible to access old data state in an DB2 database?
Oracle has the clause select ... as of timestamp to do it. Does DB2 have something like it?
Yes, you can select a set of rows that were / will be valid in a past / future time. This is called Time Travel in DB2, but you have to configure / create the table with the extra columns in order to activate this feature. This is new in DB2 10, but I think it is not available in all editions.
For more information, take a look at this: http://www.ibm.com/developerworks/data/library/techarticle/dm-1204db2temporaldata/
Remember, there are two concepts: business time and application time, and when using both is called bi-temporal.

SQL Query to execute in a loop

I need your help with the following query.
SELECT
SQL_ID,
SNAP_ID,
EXECUTIONS_TOTAL,
EXECUTIONS_DELTA,
CPU_TIME_TOTAL,
CPU_TIME_DELTA,
ELAPSED_TIME_TOTAL,
ELAPSED_TIME_DELTA
from
WRH$_SQLSTAT
where
SQL_ID='807mzfr04qt1c' and
SNAP_ID in (19507,19508);
I have to execute the above query every hour to get the results(the snap_id value changes to 19508-19509 in next hour from 19507-19508). Let us say for an entire day the begin snap id started from 19507 and ended in 19530. I would need help in writing a script that should execute it from the start id(19507) and compare it with the next id(19508) and the next id(19508) becomes the start id and so on and thus execute until the end id(19530) is reached.
You could use DBMS_SCHEDULER. for your version of oracle 10g. I am bit confused where are u trying to implement it in SQL or ORACLE, cause ur question is tagged in oracle 10g and u have mentioned your question with SQL.
But if you are using oracle 10g u can achieve it by using DBMS_SCHEDULER, incase you are uing some other version v7.3.4 to 9i oracle, use DBMS_JOB to schedule a task.
If u are using MS SQL Server us can achieve this by creating scheduled jobs. In SQL Management Studio, navigate to the server, then expand the SQL Server Agent item, and finally the Jobs folder to view, edit, add scheduled jobs.