Wednesday, June 19, 2013

Goldengate User Creation.

This is SQL script to Create GG Admin User. Script Run DBMS_PACKAGE and grants according to Oracle database Version.

It also created Dedicated Tablespace for Goldengate User.

prompt "Enter Goldengate Tablespace Name"
def GGATE_ADMIN_TABLESPACE_NAME=&1
prompt "Enter Goldengate Tablespace Location"
def GG_ADMIN_TABLESPACE_LOCATION=&2
prompt "Enter Goldengate Admin UserName"
def GOLDENGATE_ADMIN_USER=&3
prompt "Enter Goldengate username password"
def GOLDENGATE_ADMIN_USER_PWD=&4
set serveroutput on;
prompt "-------------------------------------------------------------------------"
prompt "This script first drop Old tablespace and Goldengate user if same name exist"
prompt "Provide DISKGROUP NAME LIKE +DATA if Tablespace location is on ASM  "
PROMPT "OR"
prompt "provide filesystem with datafile name like /u01/app/datafile/GGADMIN.dbf"
prompt "-------------------------------------------------------------------------"
spool GG_ADMIN_USER_CREATION.LOG
prompt "Goldengate User must have its own Tablespace it can not be shared with"
Prompt "shared with any other user or ddl_setup script will fail"
--prompt "=======first read above instruction clearly============"
prompt "-------------------------------------------------------------------------"
prompt "------------------------Disable DDL--------------------------------------"
@ddl_disable.sql
SET VERIFY OFF;
prompt "-----------------------Droping any existing Tablespace-------------------"
DROP TABLESPACE &GGATE_ADMIN_TABLESPACE_NAME INCLUDING CONTENTS AND DATAFILES;
prompt "-----------------------Droping any existing User-------------------------"
DROP USER &GOLDENGATE_ADMIN_USER CASCADE;
Prompt "-----------------------creating new Tablespace --------------------------"
CREATE TABLESPACE &GGATE_ADMIN_TABLESPACE_NAME  datafile '&GG_ADMIN_TABLESPACE_LOCATION' SIZE 1500M autoextend on;
--PROMPT "ENTER PASSWORD FOR NEW GOLDENGATE ADMIN USER"
prompt "-----------------------creating new Goldengate Admin User----------------"
CREATE USER &GOLDENGATE_ADMIN_USER IDENTIFIED BY &GOLDENGATE_ADMIN_USER_PWD DEFAULT TABLESPACE &GGATE_ADMIN_TABLESPACE_NAME TEMPORARY TABLESPACE TEMP;
GRANT CONNECT,alter session,CREATE SESSION,RESOURCE,CREATE TABLE TO &GOLDENGATE_ADMIN_USER;
GRANT FLASHBACK ANY TABLE TO &GOLDENGATE_ADMIN_USER;
grant SELECT ANY TRANSACTION to &GOLDENGATE_ADMIN_USER;
grant SELECT ANY TABLE to &GOLDENGATE_ADMIN_USER;
grant SELECT ANY DICTIONARY to &GOLDENGATE_ADMIN_USER;
grant CREATE TABLE to &GOLDENGATE_ADMIN_USER;
grant ALTER SESSION to &GOLDENGATE_ADMIN_USER;
grant UNLIMITED TABLESPACE  to &GOLDENGATE_ADMIN_USER;
grant EXECUTE ON utl_file to &GOLDENGATE_ADMIN_USER;
grant select on v_$instance to &GOLDENGATE_ADMIN_USER;
grant select on v_$database to &GOLDENGATE_ADMIN_USER;
grant LOCK ANY TABLE to &GOLDENGATE_ADMIN_USER;
PROMPT "----------DBA PRIVILEGES WILL BE GRANTED TO GOLDENGATE_ADMIN_USER--------"
GRANT DBA TO &GOLDENGATE_ADMIN_USER;
Prompt "-------------------------------------------------------------------------"
Prompt "-------------------------------------------------------------------------"
Prompt " Running PLSQL BLOCK to execute procedure and grants according to Oracle version"
Prompt "-------------------------------------------------------------------------"
Prompt "-------------------------------------------------------------------------"
Prompt
Prompt


declare
v1 VARCHAR2(200);
v2 varchar2(200);
V3 varchar2(1000);
l_sql varchar2(1000);
begin
select version into v1 from DBA_REGISTRY WHERE COMP_NAME LIKE '%Catalog Views%';
 CASE
      WHEN v1 like '10.2%' THEN
DBMS_OUTPUT.PUT_LINE('it is Oracle version 10.2');
execute immediate 'BEGIN dbms_streams_auth.grant_admin_privilege(''&GOLDENGATE_ADMIN_USER''); END;';
EXECUTE IMMEDIATE 'grant insert on system.logmnr_restart_ckpt$ to &GOLDENGATE_ADMIN_USER';
EXECUTE IMMEDIATE 'grant update on sys.streams$_capture_process to &GOLDENGATE_ADMIN_USER';
EXECUTE IMMEDIATE 'grant become user to &GOLDENGATE_ADMIN_USER';
dbms_output.put_line('Executing dbms_streams_auth.grant_admin_privilege');
WHEN v1 like '11.1%' THEN
DBMS_OUTPUT.PUT_LINE('it is Oracle version 11.1');
execute immediate 'BEGIN dbms_streams_auth.grant_admin_privilege(''&GOLDENGATE_ADMIN_USER''); END;';
EXECUTE IMMEDIATE 'grant become user to &GOLDENGATE_ADMIN_USER';
dbms_output.put_line('Executing dbms_streams_auth.grant_admin_privilege');
WHEN v1 like '11.2.0.3%' THEN
DBMS_OUTPUT.PUT_LINE('it is Oracle version 11.2.0.3');
EXECUTE IMMEDIATE 'begin dbms_goldengate_auth.grant_admin_privilege(''&GOLDENGATE_ADMIN_USER''); END;';
dbms_output.put_line('Executing dbms_goldengate_auth.grant_admin_privilege');
    END CASE;
exception when others
then
dbms_output.put_line('ERROR IS ' || SQLCODE || SQLERRM);
end;
/
prompt "---------------------script end-------------------------------------------"
prompt
prompt
prompt "~~~~~~~~please verify GG_ADMIN_USER_CREATION.LOG for Errors ~~~~~~~~~~~~~~"
prompt
prompt
prompt
spool OFF;

No comments:

Post a Comment