Oracle Database 23c on a Mac with an M-Series Chip

blank

Starting Position

I got my MacBook Pro 16″ with an Apple M1 Max chip with 10 cores, 64 GB RAM and 4 TB disk in November 2021. At that time, the M1 chip had already been on the market for a year and I knew that there were problems when running virtual machines or Docker containers with the Intel x86_64 architecture. Most of my colleagues decided to go with a database instance in the cloud. However, I like the ability to develop offline and I often need an Oracle Database. And disk space is not an issue.

My solution was to run Windows on ARM in Parallels Desktop and install the Oracle Database there. Microsoft did a tremendous job running Intel-based software under Windows on ARM. As far as I remember I did not experience a single crash. And the performance was similar to the Oracle Databases that ran in a Docker container on my Mac mini Server with a 2.3 GHz Intel Quad-Core i7.

I tried other solutions based on QEMU like UTM, but the performance was unbearable slow. So, I lived with my Oracle Database under Windows. Happily until 4th April 2023. The release date of Oracle Database 23c Free.

Oracle Database 23c Free

The Oracle Database 23c Free is available as Linux RPM, VirtualBox VM or Docker image. There are two distributions for the Docker image:

Gerald and the team at Oracle managed to allow us to download Oracle software without forcing us to log in and accept some license agreements. This is super cool, especially in CI environments.

Gerald mentions also the limitation regarding the Oracle Database Free on Apple M chips and points to Colima. I have not used Colima before, however, it sounds like the way to go until Oracle releases their flagship database system for ARM.

What is Colima?

Colima provides an alternative context for Docker containers. Docker containers do not run natively on macOS. Instead, the context provides a virtual machine and the containers run there. The idea is that we do not need to know that there is a VM behind the scenes. Mostly.

Docker Desktop provides already a VM. Why do we need an alternative or an additional VM? Well, I see the following reasons:

  • Firstly, you can use Colima as a replacement for Docker Desktop.
  • Secondly, you have more control over the configuration of the virtual machine, and this effectively allows you to run an Oracle Database in a Docker container on a macOS machine with an Apple M-Series chip.

It’s important to note, that Colima can run side-by-side with Docker Desktop. You can change the current context via the docker context command. However, Docker Desktop 4.17.0 is not able to see “foreign” contexts. This means when you work with Colima you do that from the command line.

Prerequisites

For the next steps, you will need the following:

  • A Mac with an M-Series chip,
  • with macOS Ventura 13.3.1 or newer,
  • Internet access,
  • and the ability to work in a terminal window and execute sudo commands.

So, let’s get started.

Step 1 – Install Homebrew

Run the following command in a terminal window, if you have not installed homebrew already:

If you already have installed homebrew, then update your installation as follows:

You might be asked to upgrade outdated formulae. – You know what to do.

Step 2 – Install Colima

We install the stable version of Colima via homebrew. See the installation guide for all options.

Step 3 – Create Colima VM

Now we can start Colima. The initial start creates the virtual machine. We pass a minimal set of parameters to override the defaults where necessary.

This command produces a VM with 2 CPUs, 4 GB RAM and 60 GB disk space. The architecture is x86_64. To improve the performance we use the virtualization framework of macOS 13 vz, enable Rosetta 2 and use the macOS-specific volume mount driver virtiofs.

The VM is created in $HOME/.lima. The configuration of the VM is stored in $HOME/.colima/default/colima.yaml. Most of the settings can be changed, but require a restart of the VM (via colima restart or colima stop followed by colima start).

Starting Colima changes the context to colima and stopping it changes it back to default. Use docker context use to change the context.

Updated on 2023-04-19: The x86_64 architecture prohibits the use of Rosetta 2. Colima falls back silently to QEMU. Providing --arch aarch64 enables Rosetta 2. However, it will not be possible to start an Oracle Database. You will get the same errors as with the default Docker context. As a result, you do not need to pass the highlighted parameters.

Step 4 – Create 23c Container

We want to create a container with a volume mapped to a local directory. Due to various permission issues, it is not that simple to achieve that directly. It’s easier if we create an internal Docker volume (within the VM) first.

We use Oracle’s distribution of the image. It will be pulled automatically. The volume 23c-data is also created automatically.

To monitor the console output we run the following command:

Here’s the log output with timestamps. The database was up and running after 38 seconds.

We can press Ctrl-C once we see this output.

Step 5 – Change Passwords

The database was created with random passwords for SYS, SYSTEM and PDBADMIN. To change them we run the following:

As result, we expect the following SQL*Plus console output:

That’s it if you are happy with a Docker volume.

If you’d like the volume to be mapped to a local directory on your Mac, then read on.

Step 6 – Export Volume

There are several ways to export a volume. The following script uses a helper container to access the volume and copy the content to the local directory which we want to use in the future as the replacement for the Docker volume.

Step 7 – Change Permissions

We used sudo tar xvpfz... previously to ensure that we can create all files in the target directory with the same permissions as in the original Docker volume. However, this does not seem to be enough.

orapwFREE is the password file. It needs restrictive permission to work.

If you’d like to have the user oracle and the group oinstall also on your Mac, then you can run the following:

After that the output of cd $HOME/docker;ls -lR 23c-data should look similar to this:

Step 8 – Remove Container & Volume

Now we can remove the existing 23c Container and its associated volume.

Step 9 – Recreate 23c Container

Finally, we recreate the container as in step 4. The only difference is the volume. We use now a local directory.

To monitor the console output we run the following command:

Here’s the log output with timestamps. The database was up and running after 40 seconds.

We can press Ctrl-C once we see this output.

Summary

Thanks to the prepared database files within the Docker image we can start an Oracle Database quite fast. Even on a Mac with an M-Series chip.  Mounting a folder as a volume needs a bit of fiddling. I like to mount volumes this way because they are easy to share and I can reset the underlying VM without losing data.

The runtime performance of the Database in a Colima container is still bad, compared to my Intel i7 Mac mini and the Oracle Database under Windows on ARM. Depending on the workload it is 5 to 10 times slower. Sometimes even more.  I do not see a big difference with or without Rosetta 2. That’s a bit disappointing. Maybe I do something wrong and someone can point me in the right direction. Microsoft showed what’s possible.

Anyway, I’m not sure if I’m going to use a database within Colima during my live demos. But I will definitely keep one ready as a backup.

Hopefully, Oracle will release an ARM version of their Database soon.


Updated on 2022-11-02, Rosetta 2 cannot be used with X86_64 architecture. Colima silently falls back to QEMU. To use Rosetta 2 you need to pass --arch aarch64 when creating the Colima VM. However, it will not be possible to start an Oracle Database. You will get the same errors as with the default Docker context. Added a note in step 3 and crossed out the relevant parts in the summary.

17 Comments

  1. blank Niko says:

    Hello Philipp,

    thanks for the great blog post about this topic!

    As I’ve also a M1 Device, I wanted to give it a try – and indeed it worked. Due to the slow (network) emulation used, I’m not able to connect the 23c DB to a ORDS Container (on the same docker network) though. Do you have any experience with that?

    Cheers,
    Niko

    • Thank you, Niko. I just answered a question on Twitter regarding ORDS. It works when you run ORDS in the default context.

      The ORDS Docker image is available for ARM (aarch64), hence you get the optimal performance. You can do the following when you’ve installed the database according to this blog post:

      1. Prepare Volumes for Password and ORDS configuration

      2. Change the docker context to the default context

      3. Create the ORDS container

      4. Watch the progress

      This image comes also with APEX 22.2.0. By default it will be also installed. Since the Database is quite slow, the APEX installation takes a bit more time than usual. Be patient the console output of the ORDS container provides all information to monitor the progress.

      Once ORDS is installed you can connect to it via this URL: http://localhost:8181/ords . Enter “internal” for workspace, “admin” for username and “Welcome_1” for password.

      The container activates Database Actions by default. You can reach it via this URL: http://localhost:8181/ords/sql-developer . At this point, you have to enable an ordinary schema for REST.

      I’ve done the following as SYS:

      And then as ADMIN:

      Afterwards, you can log in as ADMIN in Database Actions.

      Cheers,
      Philipp

      • blank Niko says:

        Hello Philipp,

        worked like a charm – thank you very much! I was not aware that we can setup ORDS on ARM and do a docker context switch to connect the ORDS container with the DB Container running in colima.

        Safed my a lot of trouble.

        Cheers,
        Niko

        • Thanks for the feedback.

          It’s important to note that the communication happens via the host (your Mac). The two Docker VMs do not know each other, but both know the host. IMO that’s an elegant way to communicate between containers.

          I run everything that is possible in the default docker context, even containers based on x86_64 architecture. Performance with Rosetta 2 is quite good. However, Rosetta 2 cannot handle all x86_64 instructions and the Oracle Database seems to use some of them. Hence we have to stick with Colima and QEMU for the time being.

  2. blank Omar says:

    I was facing a problem with Oracle23c Docker if I tried to map to a local volume, I just tried your way, but had an error starting colima.
    FATA[0000] unknown flag: –vz-rosetta

  3. blank Omar says:

    After running this piece of code and following each step,

    docker run --rm \
    -v 23c-data:/source \
    -v $HOME/docker:/target \
    ubuntu tar czvf /target/23c-data.tar.gz /source

    the “23c-data.tar.gz” is not created.
    also, the “23c-data” folder is empty

    • I cannot reproduce this. What is the console output you get? What is the output of docker volume ls?

      • blank Omar says:

        Sorry To bother you, but It didn’t work if you can help, here is the console output
        > docker exec -it 23c ./setPassword.sh Oracle123
        The Oracle base remains unchanged with value /opt/oracle

        SQL*Plus: Release 23.0.0.0.0 – Developer-Release on Tue Apr 25 12:47:04 2023
        Version 23.2.0.0.0

        Copyright (c) 1982, 2023, Oracle. All rights reserved.

        Connected to:
        Oracle Database 23c Free, Release 23.0.0.0.0 – Developer-Release
        Version 23.2.0.0.0

        SQL>
        User altered.

        SQL>
        User altered.

        SQL>
        Session altered.

        SQL>
        User altered.

        SQL> Disconnected from Oracle Database 23c Free, Release 23.0.0.0.0 – Developer-Release
        Version 23.2.0.0.0
        > docker stop 23c
        23c
        >  ls
        apex docker-oracle-ords oracle ords
        >  mkdir -p $HOME/docker/23c-data
        > docker run –rm \
        -v 23c-data:/source \
        -v $HOME/docker:/target \
        ubuntu tar czvf /target/23c-data.tar.gz /source
        tar: Removing leading `/’ from member names
        /source/
        /source/FREE/
        /source/FREE/system01.dbf
        /source/FREE/sysaux01.dbf
        /source/FREE/redo03.log
        /source/FREE/control02.ctl
        /source/FREE/control01.ctl
        /source/FREE/users01.dbf
        /source/FREE/pdbseed/
        /source/FREE/pdbseed/system01.dbf
        /source/FREE/pdbseed/sysaux01.dbf
        /source/FREE/pdbseed/undotbs01.dbf
        /source/FREE/pdbseed/temp01.dbf
        /source/FREE/undotbs01.dbf
        /source/FREE/temp01.dbf
        /source/FREE/redo02.log
        /source/FREE/.prebuiltdb
        /source/FREE/FREEPDB1/
        /source/FREE/FREEPDB1/system01.dbf
        /source/FREE/FREEPDB1/sysaux01.dbf
        /source/FREE/FREEPDB1/users01.dbf
        /source/FREE/FREEPDB1/undotbs01.dbf
        /source/FREE/FREEPDB1/temp01.dbf
        /source/FREE/redo01.log
        /source/.FREE.created
        /source/dbconfig/
        /source/dbconfig/FREE/
        /source/dbconfig/FREE/oratab
        /source/dbconfig/FREE/tnsnames.ora
        /source/dbconfig/FREE/sqlnet.ora
        /source/dbconfig/FREE/orapwFREE
        /source/dbconfig/FREE/listener.ora
        /source/dbconfig/FREE/spfileFREE.ora

        >  ls
        23c-data apex docker-oracle-ords oracle ords

        > docker volume ls
        DRIVER VOLUME NAME
        local 23c-data

        • Looks good. A $HOME/docker/23c-data.tar.gz should have been produced.

        • blank Omar says:

          Sorry to say it is not,
          I ran the command “ls” If you can see in the log above, it shows only my current directories.
          23c-data apex docker-oracle-ords oracle ords

        • I’m running out of ideas. These are the versions I use:

          Your issue sounds similar to https://github.com/abiosoft/colima/issues/503 . So, I’d try to seek help there, if you cannot figure out the issue yourself.

          Thank you.

  4. blank Alex says:

    Hi, Philipp. Sorry for the stupid question, I am a new learner of database. After following all the step you shared, how can I access the database like what I did in window PC? do I need to install a sql plus to access the database?

    • This blog post is about how to run Oracle Database 23c Free on an Apple Silicon chip. To run it on a Windows PC this blog post is not helpful. Have a look at https://www.oracle.com/database/free/download/. At the moment there is no dedicated Windows version available. However, you can download the VirtualBox variant. It’s probably the easiest way to get it up and running on Windows.

      • blank Alex says:

        Oh, sorry. My present is not good. I mean I have a experience on using Oracle database in a window PC, but now I use a M2 mackbook air, and install a database following your instruction. But after installed, how can I start to access the database? I was using sql plus to access database when I was using Window PC, how about MacOS?

        • If you want to use SQL*Plus you can open a terminal and run docker exec -it 23c bash to open a shell in the container. However, I would install SQLcl or SQL Developer or another IDE such as dBeaver.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.