Oracle Goldengate : start replicat ATCSN or AFTERCSN ?

There is a following question on the web with different answers:

You must synchronize the starting point for Replicat with the restore point of the target database. How should you accomplish this?

A. Use the command option AFTERCSN.
B. Use the command option ATCSN.
C. Use the command option UNTIL CANCEL.
D. Use the command option RESUME.

There are more than one correct answer, i think.

A is correct, if datapump has been used to instantiate the target database. expdp performed consistency as of FLASHBACK_SCN included.

B is correct, if RMAN has been used to instantiate the target database. Oracle RMAN restore or recovery using UNTIL SCN which specifies an SCN as an upper limit  but not including the specified SCN.

For Oracle GoldenGate 12.2 and above, neither AFTERCSN nor ATCSN is required anymore, if “DBOPTIONS ENABLE_INSTANTIATION_FILTERING” is enabled in replicat parameter file.

Reference : Oracle GoldenGate Best Practices: Instantiation from an Oracle Source Database
Version 12c
Document ID 1276058.1

Privileges Consideration when Refresh Oracle Schema

When DBA refreshes an Oracle schema or objects, privileges should be taken care carefully , specially for long time running complex environment.

After dropping a schema, all the granted privileges will be lost. So before refresh, DBA should record all the privileges granted to users, roles, etc.

Export a Schema from Source Database

$ expdp Username/Password directory=  dumpfile= logfile= SCHEMAS= FLASHBACK_TIME=systimestamp

Record / Extract the Granted Privileges

Granted Column Privileges

SQL> select * from dba_col_privs where GRANTOR='SCHEMANAME';

Here ‘SCHEMANAME’ is the schema to be refreshed.

Granted Objects Privileges

 SQL>select GRANTEE,OWNER||'.'||TABLE_NAME,GRANTOR,PRIVILEGE,GRANTABLE from dba_tab_privs where GRANTOR ='SCHEMANAME';

Other privileges you may be interested from following views:

  • User_role_privs, dba_role_privs ( Users granted with with roles )
  • User_sys_privs, dba_sys_privs
  • Role_role_privs, role_sys_privs, role_tab_privs
  • Session_privs, session_roles

Refresh Schema

Drop Schema Objects

 SQL> select 'drop '||object_type|| ' '||owner||'.'||object_name ||' ;' from dba_objects where owner='SCHEMANAME';

Import Schema by Data Pump

$ impdp username/password directory= dumpfile= logfile= schemas=sourceschemaname remap_schema= remap_tablespace=

Fix Invalid Objects

Fix all invalid objects, check all synonyms, etc

Collect Stats

SQL>EXECUTE DBMS_STATS.GATHER_SCHEMA_STATS(ownname =>'SCHEMANAME');

Column Privileges in Oracle

Table column privileges include only INSERT,UPDATE without SELECT unfortunately.

How to Grant Column Privileges ?

SQL> GRANT update (columnname1),insert (columnname2, columnname3)  ON user1.table1 TO user2;

How to Check Column Privileges ?

SQL> select * from dba_col_privs ;

How to Remove Column Privileges ?

SQL> revoke insert (columnname2, columnname3) ON user1.table1 from user2;
revoke insert (columnname2, columnname3) ON user1.table1 from user2;
              *
ERROR at line 1:
ORA-01750: UPDATE/REFERENCES may only be REVOKEd from the whole table, not by column

SQL> revoke insert  on  user1.table1 from user2;
Revoke succeeded.

Upgrade RMAN Catalog Fails with “RMAN-01005: Error while converting X lock to S lock”

The following errors occur while upgrading RMAN catalog from version 19.10 to version 19.16:

RMAN> upgrade catalog;

recovery catalog owner is RMAN
enter UPGRADE CATALOG command again to confirm catalog upgrade

RMAN> UPGRADE CATALOG;


recovery catalog upgraded to version 19.16.00.00.00
DBMS_RCVMAN package upgraded to version 19.16.00.00
DBMS_RCVCAT package upgraded to version 19.16.00.00.
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-01005: Error while converting X lock to S lock

INVESTIGATION

Check the RMAN debug trace file with following messages:

...
..
.
DBGSQL: RCVCAT> declare ret integer; str varchar2(120); begin str := 'begin :ret := '||dbms_catowner||'.get_lock_on_catalog(dbms_lock.S_MODE); end;'; EXECUTE IMMEDIATE str USING OUT ret; :retlock := ret; end;
DBGSQL: sqlcode = 6550
DBGSQL: B :retlock = NULL
DBGSQL: error: ORA-06550: line 1, column 50: (krmkosqlerr)
DBGSQL: PLS-00201: identifier 'DBMS_LOCK' must be declared (krmkosqlerr)
DBGSQL: ORA-06550: line 1, column 9: (krmkosqlerr)
DBGSQL: PL/SQL: Statement ignored (krmkosqlerr)
DBGSQL: ORA-06512: at line 1 (krmkosqlerr)
...
..
.

SOLUTION

Grant execute privilege to RMAN user, here we assume it is ‘rman’ user used in most environment.

SQL> grant execute on DBMS_LOCK to rman;

Grant succeeded.
RMAN>  UPGRADE CATALOG;

recovery catalog owner is RMAN
enter UPGRADE CATALOG command again to confirm catalog upgrade

RMAN>  UPGRADE CATALOG;

recovery catalog upgraded to version 19.16.00.00.00
DBMS_RCVMAN package upgraded to version 19.16.00.00
DBMS_RCVCAT package upgraded to version 19.16.00.00.