Friday, January 6, 2017

Ooops... I did it again.

APEX 5.1 is released! As Shaun points out at this forum post, the appendix of the Oracle Application Express 5.1 Installation Guide is missing instructions to downgrade back to 5.0, after a failed upgrade attempt.

My bad. I signed off on the Oracle Application Express Installation Guide as being complete for 5.1. Unfortunately, I did not pay enough attention to the appendix. We will get this corrected soon in a refreshed version of the Installation Guide, but in the meantime, below are the instructions we will be including.


Reverting to Release 5.0 in a non-CDB
To revert to a previous Oracle Application Express release 5.0 in a non-CDB:
  1. If you altered your images directory, revert it back to the release you want to revert to. See "Reverting the Images Directory."
  2. Change your working directory to apex/core in the 5.0 source.
  3. Start SQL*Plus and connect to the database where Oracle Application Express is installed as SYS specifying the SYSDBA role:
On Windows:
SYSTEM_DRIVE:\ sqlplus /nolog
SQL> CONNECT SYS as SYSDBA
Enter password: SYS_password 

On UNIX and Linux:
$ sqlplus /nolog
SQL> CONNECT SYS as SYSDBA
Enter password: SYS_password
  1. Execute the following commands:
alter session set current_schema = SYS;   

@wwv_flow_val.sql 
@wwv_flow_val.plb 

begin
     dbms_utility.compile_schema('APEX_050000');
end;
/ 

set define '^'   
@validate_apex x x APEX_050000

begin
  for i in ( select owner, trigger_name
               from sys.dba_triggers
              where owner        =    'APEX_050000'
                and trigger_name like 'WWV_FLOW_UPGRADE_%'
              order by 1 )
  loop
    sys.dbms_output.put_line('Dropping trigger '||i.owner||'.'||i.trigger_name);
    execute immediate 'drop trigger '||i.owner||'.'||i.trigger_name;
  end loop;
end;
/

ALTER SESSION SET CURRENT_SCHEMA = APEX_050000; 
exec apex_050000.wwv_flow_upgrade.switch_schemas('APEX_050100','APEX_050000');
ALTER SESSION SET CURRENT_SCHEMA = SYS; 
drop context APEX$SESSION;
create context APEX$SESSION using APEX_050000.WWV_FLOW_SESSION_CONTEXT;
declare
     l_apex_version varchar2(30); 
     l_schemas sys.dbms_registry.schema_list_t;
begin
     l_apex_version := apex_050000.wwv_flows_release;
     dbms_registry.downgrading('APEX','Oracle Application Express','validate_apex','APEX_050000');
     dbms_registry.downgraded('APEX',l_apex_version);
     select username
       bulk collect into l_schemas
       from all_users
      where username in ('FLOWS_FILES','APEX_PUBLIC_USER','APEX_LISTENER','APEX_REST_PUBLIC_USER','APEX_INSTANCE_ADMIN_USER')
      order by 1;
     sys.dbms_registry.update_schema_list('APEX', l_schemas);
     validate_apex;
end;
/
  1. See the next section, "Removing the Oracle Application Express Release 5.1 Schema."


Reverting to Release 5.0 in a CDB

To revert to a previous Oracle Application Express release 5.0 in a CDB:
  1. If you altered your images directory, revert it back to the release you want to revert to. See "Reverting the Images Directory."
  2. Change your working directory to apex/core in the 5.0 source.
  3. Create a new text file in that directory named apx50dgrd1.sql consisting of the following:
alter session set current_schema = SYS;   

@wwv_flow_val.sql 
@wwv_flow_val.plb 

begin
     dbms_utility.compile_schema('APEX_050000');
end;
/ 

set define '^'   
@validate_apex x x APEX_050000

begin
  for i in ( select owner, trigger_name
               from sys.dba_triggers
              where owner        =    'APEX_050000'
                and trigger_name like 'WWV_FLOW_UPGRADE_%'
              order by 1 )
  loop
    sys.dbms_output.put_line('Dropping trigger '||i.owner||'.'||i.trigger_name);
    execute immediate 'drop trigger '||i.owner||'.'||i.trigger_name;
  end loop;
end;
/

ALTER SESSION SET CURRENT_SCHEMA = APEX_050000; 
exec apex_050000.wwv_flow_upgrade.switch_schemas('APEX_050100','APEX_050000');
ALTER SESSION SET CURRENT_SCHEMA = SYS; 
drop context APEX$SESSION;
create context APEX$SESSION using APEX_050000.WWV_FLOW_SESSION_CONTEXT;
declare
     l_apex_version varchar2(30); 
     l_schemas sys.dbms_registry.schema_list_t;
begin
     l_apex_version := apex_050000.wwv_flows_release;
     dbms_registry.downgrading('APEX','Oracle Application Express','validate_apex','APEX_050000');
     dbms_registry.downgraded('APEX',l_apex_version);
     select username
       bulk collect into l_schemas
       from all_users
      where username in ('FLOWS_FILES','APEX_PUBLIC_USER','APEX_LISTENER','APEX_REST_PUBLIC_USER','APEX_INSTANCE_ADMIN_USER')
      order by 1;
     sys.dbms_registry.update_schema_list('APEX', l_schemas);
     validate_apex;
end;
/
  1. Create a second new text file in that directory named apx50dgrd.sql consisting of the following:
set define '^'   
whenever sqlerror exit   
column :xe_home new_value OH_HOME NOPRINT 
variable xe_home varchar2(255)   
set serverout on 
begin 
-- get oracle_home     
sys.dbms_system.get_env('ORACLE_HOME',:xe_home);     
if length(:xe_home) = 0 then
    sys.dbms_output.put_line(lpad('-',80,'-'));         
    raise_application_error (-20001,'Oracle Home environment variable not set' );  
end if; 
end; 
/ 
whenever sqlerror continue   
set termout off 
select :xe_home from sys.dual; 
set termout on   
host ^OH_HOME/perl/bin/perl -I ^OH_HOME/rdbms/admin ^OH_HOME/rdbms/admin/catcon.pl -b apx50dgrd apx50dgrd1.sql
  1. Start SQL*Plus and connect to CDB$ROOT of the database where Oracle Application Express is installed as SYS specifying the SYSDBA role:
On Windows:
SYSTEM_DRIVE:\ sqlplus /nolog
SQL> CONNECT SYS as SYSDBA
Enter password: SYS_password

On UNIX and Linux:
$ sqlplus /nolog
SQL> CONNECT SYS as SYSDBA
Enter password: SYS_password
  1. Execute the following commands:
@apx50dgrd.sql
  1. See the next section, "Removing the Oracle Application Express Release 5.1 Schema."
 

1 comment:

EMSHarris said...

This really saved my bacon today! Thank you.