Insufficient privilege DBMS_SCHEDULER job - oracle

I have created a job in Oracle using following scheduler -
BEGIN
DBMS_SCHEDULER.create_job (
job_name => 'MY_JOB',
job_type => 'PLSQL_BLOCK',
job_action => 'BEGIN my_pkg.pull_data(''Y''); END;',
start_date => '31-AUG-21 07.00.00 PM America/New_York',
repeat_interval => 'freq=daily; byminute=0; bysecond=0;',
enabled => TRUE);
END;
/
When I am running job manually using below code -
BEGIN
DBMS_SCHEDULER.RUN_JOB(
JOB_NAME => 'MY_JOB',
USE_CURRENT_SESSION => FALSE);
END;
The job is running as expected. However, scheduled same jobs are failed again and again with below error.
ORA-01031: insufficient privileges ORA-06512: at "SCOTT.MY_PKG", line 246 ORA-06512: at line 1
Any suggestion, what I am doing wrong? I think I have sufficient privileges.
Edit - If I call, individual procedure which is used in the job, it's working as expected. I have checked the line 246, which is a select statement from a table in the same schema as job, proc and other tables used by the proc.
BEGIN my_pkg.pull_data('Y'); END;

Related

Procedure to move oracledb export to s3 bucket fails when ran in a job

Job fails with:
ORA-29481: Implicit results cannot be returned to client.
ORA-06512: at "SYS.DBMS_SQL", line 2832
ORA-06512: at "SYS.DBMS_SQL", line 2826
ORA-06512: at "owner.SEND_TO_S3", line 8
ORA-06512: at line 1
I can run the procedure manually(BEGIN SEND_TO_S3; END;) without errors and the db exports
show up in the s3 bucket.
****Oracle Job
BEGIN
DBMS_SCHEDULER.CREATE_JOB (
job_name => 'SEND_EXP_TO_S3_JOB',
job_type => 'PLSQL_BLOCK',
job_action => 'BEGIN SEND_TO_S3; END;',
start_date => SYSTIMESTAMP,
enabled => TRUE,
repeat_interval => 'freq=weekly; byday=mon; byhour=20; byminute=40; bysecond=0;');
END;
****Oracle procedure
(If there some other way than to use a refcursor that might solve this issue as well)
CREATE OR REPLACE PROCEDURE send_to_s3
AS
rc sys_refcursor;
BEGIN
open rc for
SELECT
rdsadmin.rdsadmin_s3_tasks.upload_to_s3(
p_bucket_name => 'bucket/name',
p_prefix => 'EXP',
p_s3_prefix => '',
p_directory_name => 'DATA_PUMP_DIR') `your text`
AS TASK_ID FROM DUAL;
DBMS_SQL.RETURN_RESULT(rc);
END send_to_s3;
****The oracle error points to an outdated client but I have the latest client and I'm
not sure the scheduler uses a client.
Is there a way to get this job running correctly?

DBMS_SCHEDULER.CREATE_JOB returning "unknown command"

I am trying to create a simple SQL job in Oracle using SQL Developer. This job will run daily and will execute one stored procedure.
The script is:
DBMS_SCHEDULER.CREATE_JOB (
job_name => '"schema1"."jobName"',
job_type => 'STORED_PROCEDURE',
job_action => 'schema1.import1.sp_import',
number_of_arguments => 0,
start_date => TO_TIMESTAMP_TZ('2021-01-12 14:31:21.000000000 AMERICA/NEW_YORK','YYYY-MM-DD HH24:MI:SS.FF TZR'),
repeat_interval => 'FREQ=DAILY;BYTIME=144500;BYDAY=MON,TUE,WED,THU,FRI',
end_date => NULL,
enabled => FALSE,
auto_drop => FALSE,
comments => 'This job will populate date in new table.');
Upon execution of this I am getting below error:
Error starting at line : 2 in command -
DBMS_SCHEDULER.CREATE_JOB (
Error report -
Unknown Command
Any idea?
Cause of that error is, I believe, the fact that you didn't enclose DBMS_SCHEDULER.CREATE_JOB into a BEGIN-END block:
begin
dbms_scheduler.create_job(...);
end;
/
Also, repeat_interval looks wrong (at least, in my 11g). There's no BYTIME - use BYHOUR and BYMINUTE combination instead. Something like this (note that I don't have your procedure):
SQL> BEGIN
2 DBMS_SCHEDULER.CREATE_JOB (
3 job_name => 'test',
4 job_type => 'STORED_PROCEDURE',
5 job_action => 'p_test',
6 number_of_arguments => 0,
7 start_date => TO_TIMESTAMP_TZ('2021-01-12 14:31:21.000000000 AMERICA/NEW_YORK','YYYY-MM-DD HH24:MI:SS.FF TZR'),
8 repeat_interval => 'FREQ=DAILY;BYDAY=MON,TUE,WED,THU,FRI;BYHOUR=14;BYMINUTE=45',
9 end_date => NULL,
10 enabled => FALSE,
11 auto_drop => FALSE,
12 comments => 'This job will populate date in new table.');
13 END;
14 /
PL/SQL procedure successfully completed.
SQL>

oracle dbms_scheduler.create_job() error when executed within stored procedure

Creating job from anonymous block is working fine:
begin
SYS.DBMS_SCHEDULER.create_job(
job_name => 'test_job',
job_type => 'PLSQL_BLOCK',
job_action => 'begin null; end;',
enabled => TRUE,
auto_drop => TRUE);
end;
Result:
PL/SQL procedure successfully completed.
Creating job from stored procedure:
create or replace procedure pr_create_job is
begin
SYS.DBMS_SCHEDULER.create_job(
job_name =>'test_job',
job_type =>'PLSQL_BLOCK',
job_action =>'begin null; end;',
enabled => TRUE,
auto_drop => TRUE);
end pr_create_job;
Begin
pr_create_job;
End;
Result:
Error report - ORA-27486: insufficient privileges ORA-06512: at
"SYS.DBMS_ISCHED", line 135 ORA-06512: at "SYS.DBMS_SCHEDULER", line
271 ORA-06512: at "PR_CREATE_JOB", line 3 ORA-06512: at line 2
27486. 00000 - "insufficient privileges"
As Kaushik Nayak mentioned, CREATE JOB privilege was granted through a role and not directly to the user, granting directly to user solved this error.

SQL Exception ORA-27478: job "JOB_MIG_17602" is running during DBMS_SCHEDULER.run_job

Getting the below exception when trying to run multiple jobs in parallel. This occurs intermittently.
The point of failure is DBMS_SCHEDULER.run_job
SQL Exception ORA-27478: job "JOB_MIG_17602" is running
"ORA-06512: at "SYS.DBMS_ISCHED", line 196
ORA-06512: at "SYS.DBMS_SCHEDULER", line 48
Description of the Job:
The job invokes a stored procedure which updates a table. The same stored procedure is invoked by different instances of the job created using unique job name.
Below are the steps to run the jobs:
DBMS_SCHEDULER.create_job(
job_name => l_job_name,
job_type => 'STORED_PROCEDURE',
job_action => i_chunk_processor_name,
number_of_arguments => 2,
enabled => FALSE,
auto_drop => FALSE
);
DBMS_SCHEDULER.set_job_argument_value(job_name => l_job_name, argument_position => 1, argument_value => i_user_id);
DBMS_SCHEDULER.set_job_argument_value(job_name => l_job_name, argument_position => 2, argument_value => i_chunk_id);
DBMS_SCHEDULER.enable(l_job_name);
COMMIT;
DBMS_SCHEDULER.run_job(job_name => l_job_name, use_current_session => FALSE);
Enabling a job means it is eligible for execution. So if the scheduler coordinator picks it up and starts it before you get to the "run_job" command, then you'll get the error, eg
SQL> begin
2 DBMS_SCHEDULER.create_job(
3 job_name => 'XXX',
4 job_type => 'PLSQL_BLOCK',
5 job_action => 'begin dbms_lock.sleep(60); end;',
6 enabled => FALSE,
7 auto_drop => FALSE
8 );
9 end;
10 /
PL/SQL procedure successfully completed.
SQL> exec DBMS_SCHEDULER.enable('XXX');
PL/SQL procedure successfully completed.
-- I wait for a few seconds
--
SQL> exec DBMS_SCHEDULER.run_job(job_name => 'XXX', use_current_session => FALSE);
BEGIN DBMS_SCHEDULER.run_job(job_name => 'XXX', use_current_session => FALSE); END;
*
ERROR at line 1:
ORA-27478: job "MCDONAC"."XXX" is running
ORA-06512: at "SYS.DBMS_ISCHED", line 238
ORA-06512: at "SYS.DBMS_SCHEDULER", line 568
ORA-06512: at line 1
If you are enabling it, you should not need an explicit run_job request.

Oracle scheduler error: Security Group ID (your workspace identity) is invalid

I am trying to create oracle scheduler job (send mail) by pl/sql process (job is created on button click). It create job successfully but job always finish with error:
"ORA-20001: Security Group ID (your workspace identity) is invalid. ORA-06512: at "APEX_050100.WWV_FLOW_SECURITY", line 2939 ORA-06512: at
"APEX_050100.HTMLDB_UTIL", line 3014 ORA-06512: at line 7 ORA-06512:
at line 7.
I also have tried to set security_group_id directly (apex_util.set_security_group_id(p_security_group_id => my_worspace_id or
wwv_flow_api.set_security_group_id(p_security_group_id=>my_worspace_id) but it always finish with the same error as my sample code. When i try to create job manually in sql developer it works. But when job is created by pl/sql process it finish with the mentioned error. Job is created successfully in both cases (pl/sql process or manually) with the same parameters so i do not understand why in case when job is created by pl/sql process it finish with error.
BEGIN
DBMS_SCHEDULER.CREATE_JOB (
job_name => '"INVERTORY"."TEST"',
job_type => 'PLSQL_BLOCK',
job_action => 'begin
for c1 in (
select workspace_id
from apex_applications
where application_id = 104 )
loop
apex_util.set_security_group_id(p_security_group_id =>
c1.workspace_id);
end loop;
HTMLDB_MAIL.SEND(
p_to => ''****.****#****.com'',
p_from => ''noreply#****.com'',
p_subj => ''test mail'',
p_body => ''komu'');
end;',
number_of_arguments => 0,
start_date => TO_TIMESTAMP_TZ('2017-08-28 10:29:57.000000000 EUROPE/PRAGUE','YYYY-MM-DD HH24:MI:SS.FF TZR'),
repeat_interval => NULL,
end_date => NULL,
enabled => TRUE,
auto_drop => FALSE,
comments => '');
DBMS_SCHEDULER.SET_ATTRIBUTE(
name => '"INVERTORY"."TEST"',
attribute => 'logging_level', value => DBMS_SCHEDULER.LOGGING_OFF);
DBMS_SCHEDULER.enable(
name => '"INVERTORY"."TEST"');
END;
Try changing this :
for c1 in (
select workspace_id
from apex_applications
where application_id = 104 )
loop
apex_util.set_security_group_id(p_security_group_id =>
c1.workspace_id);
end loop;
To this :
SELECT MAX(workspace_id)
INTO v_workspace FROM apex_applications
WHERE application_id = 104;
--set workspace - declare v_workspace above as type number
wwv_flow_api.set_security_group_id(v_workspace)
In any event, it would be better to put your logic in a package in the database and create a job with job_type => 'STORED_PROCEDURE' and call on your procedure from there.

Resources