How to make the entries delete automatically after certain time in Potgresql - database

I have created a database and it is going to have some temporary values such as login type and some hask keys that I want it to be deleted after certain period of time.
I have installed postgres on docker.
I found out a solution through pgagent, but I don't know if it works on docker. Can anyone help me figure out how to do it?
Thanks in advance

You can create the function/procedure to delete the records based on the criteria.
Schedule the execution of the function either using the cron job or the pgagent to execute at the specified time. For executing on the cron job you need to create the shell scrip to call from the cron job.

Related

Triggering Hangfire Jobs using SQL

I have a Hangfire service running on one of my servers, I'm a DBA and sometimes I'm asked to trigger jobs using the Dashboard, but it takes me a lot of time to connect to the jobs' server due to some connectivity and security issues.
And to overcome that, I want to trigger those jobs by inserting in Hangfire's tables on the database, I can already query those tables to find which job executed when and whether they failed, succeeded or still enqueued, does anyone know an approach to do so?
I've included a sample of two tables which I think will be used to do this trick, their names are Hash and Set respectively:
Hangfire normally uses a gui like swagger in .net (http://localhost:5000/hangfire) , there should be a immediate trigger feature. If not a second option is changing the cron expression for every minute or maybe every 30 seconds.

SSRS - Using ReportServer AddEvent, not processing subscriptions always

I'm trying to create a homegrown subscription system for our ReportServer for QA purposes. I'm creating subscriptions on the front end and setting them on a schedule to execute once in the past (1/1/2019 for example) so the only way they would be executed is manually.
I looked at the jobs and they are simply executing a procedure "ReportServer.dbo.AddEvent" with EventType and EventData as parameters. When I execute that procedure, it adds a record to the Event table and then the Notifications table for the RS to pick up and process the subscription. Most of the time it works but sometimes it just hangs. I'm finding this for data-driven subscriptions especially. They are stuck in pending/processing and never execute fully.
Has anyone else had issues with this before? I'm building out a homegrown system because we have 200+ reports that we want to execute on a nightly basis. They are usually pretty quick but I want to only execute a handful at a time and I'm taking care of this through a custom Queue table.
Figured it out within the log files... It was data-driven but each version had the same file name and it was trying to overwrite a file that was still open.

Create SQL Server Agent job by using existing job script?

I have two sql server agent jobs: Job1 and Job2. Since Job2 is very similar to Job1, I right-clicked on Job1 > Script Job As > Create To and used that script to create the Job2.
Now I'm seeing that any change I make in the schedule of Job2 is also affecting Job1, and I'm assuming that it's happening because both have the same #schedule_uid.
So, two questions:
Is it correct to generate a job by using the sql script of another job? If it's correct, how can I fix this error where changes made in one job affect the other job?
Thanks.
Schedules are distinct objects within SQL Server and as you have found are independent to the Job, referenced by an ID.
If you are creating jobs via script you just need to either not assign a schedule, create a new schedule as well for every job, or define a set of possible schedules that fit around your requirements/maintenance windows and specify the correct ID in your script.
Obviously any two jobs that share a schedule will be affected if you change the schedule so, if you foresee a lot of individual job management/tweaking going on, it may be best that your script creates a schedule and then reference that new schedule in the job creation.
If you look in your script you will see that the #schedule_uid is the same. If you would fetch the new #schedule_uid (and all other hardcoded id's) from the tables in the MSDB database you will get a correct running job

Need to split two SQL Server Agent Jobs into different schedules

I have two SQL Agent jobs that share the same schedule due to an error I made during the creation of the second job. I generated a script in SSMS and edited some values, but I left the schedule_uid the same. Now it turns out that while those two jobs are running at the same time, they are corrupting each other's data.
What I need to do is leave the original job alone, but create a new schedule and have the second job use this new schedule. However, my searches for the correct way to do this have all resulted in dead-ends.
None of this can be done using a UI .. it all must be scripted so it can be run during a maintenance window without me present.
Thanks in advance for any assistance.
Use msdb.dbo.sp_detach_schedule followed by msdb.dbo.sp_add_jobschedule.

CRM 2011 find out which batch process last changed a record

I have inherited a poorly documnted CRM 2011 instance, lets call it 'haystack', that has literally 100s of batch processes and workflows running on it under the same user account (IT_Job). One of them, lets call it 'needle', has a problem.
I know 'needle' ran at noon. But the Advanced find only allows me to query the scheduled jobs down to the day they ran NOT the time they ran.
How do I find out which Batch Process or Workflow last updated an entity (incident). All I seem to be able to query the scheduled jobs by is IT_Job.
It seems to me that the only way to find the 'needle' job would be to systematically add a corresponding User for each job that acts on 'incident' to then search for job running as the user that last modified the record.
So how do I find 'needle' quickly?
EDIT
Ok it turns out the site I am working for won't allow me access to the database or allow me to deploy a console app. (One could argue that they're not interested in a solution to this problem) So is there any other way to query this data?
If you have access to the SQL server then you can query the table dbo.WorkflowLogBase. This will help you narrow down which workflows had run at that exact time.
You might also be able to add some extra information by looking at the audit history for the record that has been changed assuming that auditing is turned on.

Resources