9.7.3.3.2 Running from a Script

You can also set the ownership of the test master data files using a SQL script.

The following procedure is equivalent to the commands in the previous topic, but it queries V$DATAFILE for the filenames:

  1. Add an operating system user as owner of the disk group.
    SQL> ALTER DISKGROUP DATA ADD USER 'scott';
    
  2. Generate a script called set_owner.sql to set the owner of the test master's data files.
    • If the test master is a full database, run the following in the test master database:

      set newpage 0
      set linesize 999
      set pagesize 0
      set feedback off
      set heading off
      set echo off
      set space 0
      set tab off
      set trimspool on
      spool set_owner.sql
      select 'ALTER DISKGROUP DATA set ownership owner='||''''||'scott'||''''||' for file '||''''||name||''''||';' from v$datafile;
      exit
      
    • If the test master is a PDB, run the following in the CDB$ROOT of the test master PDB:

      In the select statement below, the example assumes the test master PDB has a con_id of 10.

      set newpage 0
      set linesize 999
      set pagesize 0
      set feedback off
      set heading off
      set echo off
      set space 0
      set tab off
      set trimspool on
      spool set_owner.sql
      select 'ALTER DISKGROUP DATA set ownership owner='||''''||'scott'||''''||' for file '||''''||name||''''||';' -
      from v$datafile where con_id=10;
      exit
      
  3. Remove extra lines in set_owner.sql.
    sed -i '/SQL/d' set_owner.sql
    
  4. Run the script in the ASM instance.
    SQL> @set_owner