Tuesday 25 April 2023

Install Oracle 23c Developer Edition in Oracle Linux 8 VM

The Oracle 23c Developer Release is available as a complete, ready-to-run VM with a complete set of tools. But if you want, for whatever reason, build your own VM, you might want to follow this guide.

Start with a fresh Oracle Linux 8.7 VM like the one from The Oracle DB Developers VM project and run a sudo dnf upgrade to make sure to be on the latest patches. Avoid using Red Hat's historic kernels and boot with the latest kernel provided by Oracle.

Download the rpm and follow the installation guide from Oracle. My OL installation only found the preinstallation packages for 19c and 21c, but not for 23c. So I followed the guide for Red Hat Linux, which worked.

sudo -s
curl -L -o oracle-database-preinstall-23c-1.0-0.5.el8.x86_64.rpm https://yum.oracle.com/repo/OracleLinux/OL8/developer/x86_64/getPackage/oracle-database-preinstall-23c-1.0-0.5.el8.x86_64.rpm
dnf -y localinstall oracle-database-preinstall-23c-1.0-0.5.el8.x86_64.rpm
dnf -y localinstall /home/oracle/ddrive/Install/Linux-x64/oracle-database-free-23c-1.0-1.el8.x86_64.rpm
/etc/init.d/oracle-free-23c configure

When the installer is done, follow the installation guide and set the variables in .bashrc and source it:

export ORACLE_SID=FREE
export ORAENV_ASK=NO
. /opt/oracle/product/23c/dbhomeFree/bin/oraenv
export PATH=$ORACLE_HOME/bin:$PATH

Take a first look at the DB, it is ready to run now.

Download the latest SQLcl and unzip it to your favorite tools location like
wget https://download.oracle.com/otn_software/java/sqldeveloper/sqlcl-latest.zip
unzip sqlcl-latest.zip -d ~/bin

Add SQLcl to your PATH and also add a TNS_ADMIN variable to your .bashrc and source it.

export PATH=/home/oracle/sqlcl/bin:$PATH
export SQLPATH=~/sql

Make some settings for SQLcl for a nicer experience 

mkdir ~/sql
cat >> ~/sql/login.sql <<EOF
set statusbar on
set highlighting on
EOF

Now we have SQLcl:

Download SQLDeveloper from https://www.oracle.com/database/sqldeveloper/technologies/download/
I prefer the Other Platforms version. Unzip it to its destination.

unzip ~/ddrive/Install/Generic/sqldeveloper-23.1.0.097.1607-no-jre.zip -d ~/bin

Look here on how to add SQLDeveloper to the Gnome menu. Run SQLDeveloper, it will tell you if you need to adjust the JDK location at startup.

Create a connection

Follow this guide on how to install VSCodium and the Oracle Developer Tools for VSCode. Create a new Database connection in VSCodium to freepdb1.

So far, this is quite a complete environment to start with Oracle 23c Developers Edition.


Thursday 13 April 2023

Cloning a PDB with APEX pointing to ORDS REST services on the same database

This post shows cloning a database with APEX and some database REST services in the same database, which are accessed from APEX via a REST data source. Say we have a PDB testpdb and clone it to clonepdb for dev/test. The EMPLOYEES table in HR is REST enabled and the APEX application has a REST Data Source for that REST service. Without any changes, the REST Data Source from clonepdb would still point to testpdb. But it should point to clonepdb. This could be changed manually, but if this is needed for automatic provisioning of developer environments, some automation would be helpfull.

The URL is shown in ORDS Database Actions under REST/AutoREST


The APEX application has a REST Data Source TestEmployees pointing to that service:


The Remote Server attribute contains the IP address and the database connection, in this case the TESTPDB. Click on the pen next to it.
Enable Prompt on Install.

Now clone testpdb to clonepdb:

create pluggable database clonepdb from testpdb 
file_name_convert = ('/testpdb/', '/clonepdb/');

alter pluggable database clonepdb open;

For easier access add clonepdb to tnsnames.ora:

cat >> $TNS_ADMIN/tnsnames.ora <<EOF
CLONEPDB =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = clonepdb)
    )
  )

EOF
tnsping clonepdb

Stop ORDS, register clonepdb with ORDS interactively or create a password.txt file with your passwords and run:

cat > password.txt <<EOF 
<password>
<password>
EOF

ords install --db-pool clonepdb --db-hostname localhost --db-port 1521 --db-servicename clonepdb --feature-sdw true --feature-db-api true --feature-rest-enabled-sql true --admin-user sys --proxy-user --password-stdin < password.txt

Restart ORDS and navigate to REST/AutoREST. The service for the employees table also exists in clonepdb ...


... and works as expected.


The APEX application also made it into clonepdb, but of course the TestEmployees REST Data Source still points to testpdb
As the application has been cloned with the PDB, the Prompt on Install attribute does not trigger. We need to ex- and import the application. Export the application from testpdb and make sure that Export with Original IDs is checked
Import the application on clonepdb and check Reuse Application ID 100 From Export File 
In the last step, the installer prompts for the Base URL of the Remote Server, which has been tagged for Prompt on Install. Change it from testpdb to clonepdb.
Open the REST Data Source, it now shows the correct local endpoint. 
But for automatic deployment of developer environments, we need to get rid of the interactive step. Before we can import the export file by running it in SQLcl, we need to set the override with APEX_APPLICATION_INSTALL.SET_REMOTE_SERVER .

declare
    l_base_url varchar2(255);
begin
  apex_application_install.set_remote_server(
    p_static_id => '192_168_56_104_ords_testpdb',
    p_base_url  => 'http://192.168.56.104:8080/ords/clonepdb/');

    l_base_url := apex_application_install.get_remote_server_base_url('192_168_56_104_ords_testpdb');
    DBMS_OUTPUT.PUT_LINE('Base URL for ' || '192_168_56_104_ords_testpdb' || ' is now ' || l_base_url);
end;
/

That should give
And opening the REST Data Source in the APEX application on clonepdb should show the URL pointing to clonepdb.

So all that is needed after cloning the database with the APEX application and the REST service is running a script with apex_application_install.set_remote_server and re-importing the application.