Is there any way to find out the duration of store procedure respond in last 30 day or more ?
i have a program that running store procedure on server and some days this sp stops responding or takes too long to respond(need Instance to restart).
now i need to find out why and when this happen.
my guess is there is a some Concurrent sp that locks the table and stop this sp from running.
Related
I've built several stored procedures in MySQL. I would like to run them in a specific order to ensure that tables are updated properly and efficiently. What would be the best way to call the procedures to run in a specific order? I would like to have them run once every 30 minutes or so.
Thanks
After some research, I found that a recurring event for each procedure is a good way to go. Creating each event about 10 seconds apart ensures they run in sequence every 30 minutes.
CREATE EVENT `[Event_Name]`
ON SCHEDULE EVERY 30 MINUTE
DO
CALL `[Stored_Procedure_Name]`();
I have a table on an AS400 server (DB2) that I need monitor from SQL Server. If a record is written, I will take the data, do some stuff and then delete the record.
Currently, I wrote a C# windows services that runs the stored procedure every 500 ms and that works fine. But I want to run this store procedure completely from SQL if possible
I can't run from SQL Server Agent because 5 minutes is too long.
What is the best way to do this and furthermore, is there any issues with running int from a continual loop within the server?
This is my solution:
create a stored procedure that will loop using wait time and a while loop which will exit at a midnight and will run the stored procedure, wait 500 msec and then run it again
Run the looping stored procedure from SQL Server Agent daily at midnight
I will tweak the interval by maybe running the looping sp several times a day.
Thank you for your attention
I am building a monitoring application for a machine, position must be read and stored every second for a period of a month. I wrote a procedure to fill a table with initial 0 value.
CREATE DEFINER=`root`#`localhost` PROCEDURE `new_procedure`(start_date datetime, end_date datetime)
BEGIN
DECLARE interval_var INT DEFAULT 1;
WHILE end_date >= start_date DO
INSERT INTO table1(datetime, value) VALUES(start_date, 0);
SET start_date = DATE_ADD(start_date, INTERVAL interval_var SECOND);
END WHILE;
END
This process is very slow, and most of the time the connection with the sql database is lost. For example, when I try to fill the table from "2016-01-14 07:00:00" to "2016-01-15 07:00:00" the procedure reached 2016-01-14 07:16:39 and crashed due to lost connection with database.
Is there a more efficient way to create a template table for a month with second increments and 0 values? My monitoring application is built on vb.net and I have tried to create a code on vb to create this template table, but it was slower and more likely to crash than direct procedure on mysql workstation.
I would recommend looking at the application architecture first. Expecting the whole system to run without failing for even 1 second for an entire month is asking an awful lot. Also, try to think about if you really need this much data.
1 record/sec*3600 sec/hr*24 hr/day*30 day/mo is more than 3.1 million records. Trying to process that much information will cause a lot of software to choke.
If the measurement is discrete, you may be able to cut this dramatically by only recording changes in the database. If it's analog, you may have no choice.
I would recommend creating two separate applications: a local monitor that stores local data, and then reports to the mysql server application every hour or so. That way, if the database is unavailable, it keeps right on collecting data, and when the database is available again, it can transfer everything that has been recorded since the last connection. Then the mysql application can store the data in the database in one shot. If that fails, it can retry, and keep it's own copy of the data until it gets stored into the database.
Ex:
machine => monitoring station app => mysql app => mysql database
It's a little more work, but each application will be pretty small, and they may even be reusable. And it will make troubleshooting much easier, and dramatically increase the fault tolerance in the system.
Due to performance issues arising from row locking and a long running query in a trigger, I've opted to instead run the query as a stored procedure from a cron job every five minutes.
My problem is that I need to prevent the situation where the query takes longer than 5 minutes and collides with the next scheduled run of the stored procedure. Since I do run this query in transaction, ideally I'd just execute a rollback somewhere in the stored procedure once the five minutes were up. Is this possible?
Thanks.
The 'brute force' method would be to have a table with 'jobs'. Each row would have a start time and end time. Look for the most recent start time that doesn't have an end time. If your next job wants to start and there isn't an end time listed then kill the previous job.
You could even put the process id in there.
I ended up just noting the epoch time at the beginning of the procedure, then after each record I process I do a commit and calculate the time elapsed. If it's above a preset timeout value I BREAK and end the procedure.
The only possible failure would be if the logic (an insert) in the stored procedure's while loop takes too long, but this is unlikely. I declared some exit handlers to mitigate this possibility (they do ROLLBACKs).
I have a DB with game data (map, players, etc...) and I have a game core mechanics written in T-SQL stored procedure.
I need process game loop (via the stored procedure) every "X" seconds.
I tried used the SQL Job, but when I set the interval to seconds, the SQL server stops responding. If I set the interval greater than one minute, all was ok.
I need game loop precise in time, e.g. the game loop will run only once and will be executed every "X" precisely (tolerance should be less than one second).
Can I do it with SQL Server capabilities? Or should I create a windows service which will repeatly execute game loop procedure? Or should I go another way?
Thanks!
EDIT:
The game loop stored procedure takes less than the interval.
I would use a windows service for this. Have a loop with a thread sleep in it to get it to wait every x seconds.
The problem with timer jobs of type used in SQL server, is that there is a timer service checking if there is a job that need to be run. This timer job may check for example every 2 minutes, so precision down to a second is not possible.
To run smth with interval of 1 sec you can use code:
CREATE PROCEDURE SP_Execute_job
AS
WHILE 1=1
BEGIN
WAITFOR DELAY '00:00:01'
EXECUTE 'somewhat job'
END
END
This sp should be executed after each SQL Server start:
exec sp_procoption N'SP_Execute_job', 'startup', 'on'