Monday, October 22, 2012

PRKP-1029, CRS-0211 on srvctl modify/add service
=====================================================
What I was trying to do:
My requirement was to change the preferred node and available node for a service.
Issues:
srvctl modify service -d ORCL -s BULK -i node3,node4 -a node1,node2
PRKP-1029 : Failed to register the service ORCL_BULK_svc.
CRS-0211: Resource 'ora.ORCL.ORCL_BULK_svc.cs' has already been registered.
I tried the above command a couple of time, but gave the same error. I decided to stop the service and then try.
I decided to stop the service:
srvctl stop service -d ORCL -s BULK.
The service stopped without any issue.
But even after stopping the service, it gave the same error.
The I decided to remove the service and recreate it with the required configuration.
srvctl remove service -d ORCL -s BULK
Service got removed without any issue.
Now tried to add the service:
srvctl add service -d ORCL -s BULK -r node3,node4 -a node1,node2
PRKP-1029 : Failed to register the service ORCL_BULK_svc.
CRS-0211: Resource 'ora.ORCL.ORCL_BULK_svc.cs' has already been registered.

DAAAM, the error was not supposed to come, as I had already removed the service. Interestingly, I checked the DBA_SERVICES and still saw the entry of this service there. And also crs_stat showed this service.
Now I was in a soup as one of the most important application could not connect. Check with metalink/web the only thing I found was to "contact support". Turned to a couple of colleagues and got the suggestion to use crs_unregister. This is not a recommended thing to do, but I was in dire straits.
So this is what we did:
crs_unregister ora.ORCL.ORCL_BULK_svc.cs
srvctl add service -d ORCL -s BULK -r node3,node4 -a node1,node2
PRKP-1029 : Failed to register the service ORCL_BULK_svc.
CRS-0211: Resource 'ora.ORCL.ORCL_BULK_svc.ORCL.srv' has already been registered.

crs_unregister ora.ORCL.ORCL_BULK_svc.ORCL.srv

srvctl add service -d ORCL -s BULK -r node3,node4 -a node1,node2
PRKP-1029 : Failed to register the service ORCL_BULK_svc.
CRS-0211: Resource 'ora.ORCL.ORCL_BULK_svc.cs' has already been registered.

We had already unregistered this one, but it gave the error for the same thing again. We ran the unregister once again:

crs_unregister ora.ORCL.ORCL_BULK_svc.cs
Looks like the sequence is to first remove the .srv and then the .cs:

crs_unregister ora.ORCL.ORCL_BULK_svc.ORCL.srv
CRS-0210: Could not find resource 'ora.ORCL.ORCL_BULK_svc.ORCL.srv'.
crs_unregister ora.ORCL.ORCL_BULK_svc.cs
CRS-0210: Could not find resource 'ora.ORCL.ORCL_BULK_svc.cs'.

Finally:
srvctl add service -d ORCL -s BULK -r node3,node4 -a node1,node2
and now it worked. And I started the service.

Details on crs_unregister from Oracle:
The crs_unregister command removes the registration information of Oracle Clusterware resources from the binary Oracle Clusterware registry database. The Oracle Clusterware will no longer acknowledge this resource. An application associated with a resource that is unregistered is no longer highly available. You must have full administrative privileges to use this command.
Upon successful completion of the crs_unregister command, the resource is removed from the online Oracle Clusterware environment. You cannot unregister a resource that is a required resource for another resource. You must stop the resource by using the crs_stop command before unregistering it.
Syntax and Options for crs_unregister
Use the crs_unregister command with the following syntax:
crs_unregister resource_name [...] [-q]
The only option available for this command is -q, that runs the crs_unregister command in quiet mode, which means no messages are displayed.
Example of crs_unregister
The following example unregisters a highly available application called postman:
crs_unregister postman

Errors for crs_unregister
Oracle displays a corresponding text message for the following error conditions:
* No root privilege
* CAA daemon is not running
* The application is running
* The application is not registered
Configuring streams on Oracle 10g Database [Unidirectional ]
=================================================================
1.Some useful DB parameter which need to be set .

> COMPATIBLE
> GLOBAL_NAMES
> JOB_QUEUE_PROCESSES
> STREAMS_POOL_SIZE

2.Create the "stradmin" user on both the source and destination database and grant the necessary privileges.

SQL> create user stradmin identified by stradmin;
SQL>grant connect, DBA, imp_full_database, exp_full_database, aq_administrator_role to stradmin;
SQL>exec DBMS_STREAMS_AUTH.GRANT_ADMIN_PRIVILEGE('STRADMIN');
As an option, it is possible to create a separate tablespace for each streams administrator schema (STRADMIN) at each participating Streams
database.This tablespace will be used for any objects created in the streams administrator schema, including any spillover of messages from
the in-memory queue.
SQL> Create tablespace streams datafile ‘/disk1/oradata/prod/streams.dbf’ size 40m autoextend on;
SQL> alter user streams default tablespace streams;

3. Source Database
========================
Turn on Supplemental logging at database level, or table level.
connect SYS/password as SYSDBA
SQL> ALTER DATABASE ADD SUPPLEMENTAL LOG DATA;
SQL>ALTER DATABASE ADD SUPPLEMENTAL LOG DATA (ALL) COLUMNS;
SQL>ALTER DATABASE ADD SUPPLEMENTAL LOG DATA (primary key, unique, foreign key) COLUMNS;
SQL>ALTER TABLE scott.emp ADD SUPPLEMENTAL LOG GROUP pk_emp (id) ALWAYS;
select log_group_name, table_name from dba_log_groups where owner='SCOTT';

4.Create DB link
====================
Create Database Links between the stream administrator users in the 2 databases.
SQL> CREATE DATABASE LINK TEST.REGRESS.RDBMS.DEV.US.ORACLE.COM CONNECT TO STREAMADMIN IDENTIFIED BY streamadmin USING 'TEST_REP2';
Database link created.

5. Create the 2- Queues , one is for capture and second one for apply
===================================================================
Create Stream Queues under the streamadmin user to apply and capture the database changes to be replicated.
This also needs to run on both the databases as streamadmin.
SQL> show user
USER is "STREAMADMIN"
SQL> exec dbms_streams_adm.set_up_queue(queue_table => 'apply_q', queue_name => 'apply_q', queue_user => 'streamadmin');
PL/SQL procedure successfully completed.
SQL> exec dbms_streams_adm.set_up_queue(queue_table => 'capture_q',queue_name => 'capture_q',queue_user => 'streamadmin');
PL/SQL procedure successfully completed.

6. Create schema rule on Capture source DB
=======================================
conn streams administrator/password@Source database
BEGIN
DBMS_STREAMS_ADM.ADD_SCHEMA_RULES(
schema_name => 'schema to be streamed',
streams_type => 'Capture',
streams_name => 'streams_Capture',
queue_name => 'streams_capture_queue',
include_dml => true,
include_ddl => true,
source_database => 'source database db link');
END;
/

7.Create the capture process
===============================
begin
dbms_capture_adm.create_capture(
queue_name => 'STRMADMIN.MAIN_OT_QUEUE',
capture_name => 'CAPTURE_MAIN',
rule_set_name => 'STRMADMIN.RULESET$_13',
first_scn => 1103875820);
end;
/
8. Creating propagation process on source DB
==============================================
BEGIN
  DBMS_PROPAGATION_ADM.CREATE_PROPAGATION(
    propagation_name   => 'strm02_propagation',
    source_queue       => 'strmadmin.strm03_queue',
    destination_queue  => 'strmadmin.strm04_queue',
    destination_dblink => 'dbs2.example.com',
    rule_set_name      => 'strmadmin.strm01_rule_set',
    queue_to_queue     => TRUE);
END;
/

9. Creating the apply process on destination DB
===============================================
BEGIN
  DBMS_APPLY_ADM.CREATE_APPLY(
    queue_name             => 'strm03_queue',
    apply_name             => 'strm03_apply',
    rule_set_name          => 'strmadmin.strm03_rule_set',
    message_handler        => NULL,    
    ddl_handler            => 'strmadmin.history_ddl',
    apply_user             => 'hr',
    apply_database_link    => NULL,
    apply_tag              => HEXTORAW('5'),
    apply_captured         => true,
    negative_rule_set_name => NULL,
    source_database        => 'dbs1.net');
END;
/
10 .Doing Data exp/imp
===========================
Export, import and instantiation of tables from Source to Destination Database
If the objects are not present in the destination database, perform an export of the objects from the source database and import them
into the destination database Export from the Source Database:
Specify the OBJECT_CONSISTENT=Y clause on the export command. By doing this, an export is performed that is consistent for each individual
object at a particular system change number (SCN).
exp USERID=SYSTEM/manager@prod.com OWNER=SCOTT FILE=scott.dmp LOG=exportTables.log OBJECT_CONSISTENT=Y STATISTICS = NONE
Import into the Destination Database:
Specify STREAMS_INSTANTIATION=Y clause in the import command. By doing this, the streams metadata is updated with the appropriate
information in the destination database corresponding to the SCN that is recorded in the export file.
imp USERID=SYSTEM@prod2.com FULL=Y CONSTRAINTS=Y FILE=scott.dmp IGNORE=Y COMMIT=Y LOG=importTables.log STREAMS_INSTANTIATION=Y
If the objects are already present in the desination database, there re two ways of instanitating the objects at the destination site.
1. By means of Metadata-only export/import :
Specify ROWS=N during Export
Specify IGNORE=Y during Import along with above import parameters.
2. By Manaually instantiating the objects
Get the Instantiation SCN at the source database:
connect STRADMIN/STRADMIN@source
set serveroutput on
DECLARE
iscn NUMBER; -- Variable to hold instantiation SCN value
BEGIN
iscn := DBMS_FLASHBACK.GET_SYSTEM_CHANGE_NUMBER();
DBMS_OUTPUT.PUT_LINE ('Instantiation SCN is: ' || iscn);
END;
Instantiate the objects at the destination database with this SCN value. The SET_TABLE_INSTANTIATION_SCN procedure controls which LCRs for a table are to be applied by the apply process. If the commit SCN of an LCR from the source database is less than or equal to this instantiation SCN, then the apply process discards the LCR. Else, the apply process applies the LCR.
connect STRADMIN/STRADMIN@destination
BEGIN
DBMS_APPLY_ADM.SET_SCHEMA_INSTANTIATION_SCN(
SOURCE_SCHEMA_NAME => 'SCOTT',
source_database_name => 'prod.com',
instantiation_scn => &iscn );
END;
Enter value for iscn:65876799945

now start all the process