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 to 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:
- Oracle’s official image (container-registry.oracle.com/database/free)
- Gerald Venzl’s images (gvenzl/oracle-free) in the flavours
thin
,regular
,full
andfaststart
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:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
If you already have installed homebrew, then update your installation as follows:
brew update
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.
brew install colima
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.
colima start \ --arch x86_64 \ --vm-type=vz \ --vz-rosetta \ --mount-type=virtiofs \ --memory 4
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.
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.
docker run -d \ --name 23c \ -p 1522:1521 \ -v 23c-data:/opt/oracle/oradata \ container-registry.oracle.com/database/free
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:
docker logs -tf 23c
Here’s the log output with timestamps. The database was up and running after 38 seconds.
2023-04-16T10:16:43.392545000Z Starting Oracle Net Listener. 2023-04-16T10:16:44.057130000Z Oracle Net Listener started. 2023-04-16T10:16:44.057316000Z Starting Oracle Database instance FREE. 2023-04-16T10:17:19.544454000Z Oracle Database instance FREE started. 2023-04-16T10:17:19.547911000Z 2023-04-16T10:17:19.705193000Z The Oracle base remains unchanged with value /opt/oracle 2023-04-16T10:17:21.584419000Z ######################### 2023-04-16T10:17:21.584722000Z DATABASE IS READY TO USE! 2023-04-16T10:17:21.584981000Z ######################### 2023-04-16T10:17:21.669542000Z The following output is now a tail of the alert.log: 2023-04-16T10:17:21.720236000Z FREEPDB1(3):Opening pdb with Resource Manager plan: DEFAULT_PLAN 2023-04-16T10:17:21.720480000Z 2023-04-16T10:17:17.657677+00:00 2023-04-16T10:17:21.720530000Z Completed: Pluggable database FREEPDB1 opened read write 2023-04-16T10:17:21.720563000Z Completed: ALTER DATABASE OPEN 2023-04-16T10:17:21.720592000Z 2023-04-16T10:17:19.761876+00:00 2023-04-16T10:17:21.720620000Z =========================================================== 2023-04-16T10:17:21.720647000Z Dumping current patch information 2023-04-16T10:17:21.720673000Z =========================================================== 2023-04-16T10:17:21.720698000Z No patches have been applied 2023-04-16T10:17:21.720722000Z ===========================================================
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:
docker exec -it 23c ./setPassword.sh oracle
As result, we expect the following SQL*Plus console output:
The Oracle base remains unchanged with value /opt/oracle SQL*Plus: Release 23.0.0.0.0 - Developer-Release on Sun Apr 16 10:18:57 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
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.
docker stop 23c 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 sudo tar xvpfz $HOME/docker/23c-data.tar.gz \ --strip-components=1 -C $HOME/docker/23c-data
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.
sudo chown 54321:54321 $HOME/docker/23c-data sudo chmod -R 777 $HOME/docker/23c-data sudo chmod 4640 $HOME/docker/23c-data/dbconfig/FREE/orapwFREE
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:
sudo dscl . -create /Groups/oinstall sudo dscl . -create /Groups/oinstall name oinstall sudo dscl . -create /Groups/oinstall gid 54321 sudo dscl . -create /Users/oracle sudo dscl . -create /Users/oracle name oracle sudo dscl . -create /Users/oracle uid 54321 sudo dscl . -create /Users/oracle PrimaryGroupID 54321 sudo dseditgroup -o edit -a oracle -t user oinstall sudo dseditgroup -o edit -a $USER -t user oinstall sudo dscl . -create /Groups/oinstall GroupMembership oracle sudo dscl . -create /Groups/oinstall GroupMembership $USER
After that the output of cd $HOME/docker;ls -lR 23c-data
should look similar to this:
total 0 drwxrwxrwx 15 oracle oinstall 480 Apr 16 12:16 FREE drwxrwxrwx 3 oracle oinstall 96 Apr 16 12:16 dbconfig 23c-data/FREE: total 4928904 drwxrwxrwx 7 oracle oinstall 224 Apr 16 12:16 FREEPDB1 -rwxrwxrwx 1 oracle oinstall 18759680 Apr 16 12:19 control01.ctl -rwxrwxrwx 1 oracle oinstall 18759680 Mar 28 15:28 control02.ctl drwxrwxrwx 6 oracle oinstall 192 Apr 16 12:16 pdbseed -rwxrwxrwx 1 oracle oinstall 209715712 Apr 16 12:16 redo01.log -rwxrwxrwx 1 oracle oinstall 209715712 Apr 16 12:19 redo02.log -rwxrwxrwx 1 oracle oinstall 209715712 Apr 16 12:16 redo03.log -rwxrwxrwx 1 oracle oinstall 576724992 Apr 16 12:19 sysaux01.dbf -rwxrwxrwx 1 oracle oinstall 1216356352 Apr 16 12:19 system01.dbf -rwxrwxrwx 1 oracle oinstall 20979712 Mar 28 15:24 temp01.dbf -rwxrwxrwx 1 oracle oinstall 26222592 Apr 16 12:19 undotbs01.dbf -rwxrwxrwx 1 oracle oinstall 5251072 Apr 16 12:19 users01.dbf 23c-data/FREE/FREEPDB1: total 1464400 -rwxrwxrwx 1 oracle oinstall 325066752 Apr 16 12:19 sysaux01.dbf -rwxrwxrwx 1 oracle oinstall 293609472 Apr 16 12:19 system01.dbf -rwxrwxrwx 1 oracle oinstall 20979712 Apr 16 12:17 temp01.dbf -rwxrwxrwx 1 oracle oinstall 104865792 Apr 16 12:19 undotbs01.dbf -rwxrwxrwx 1 oracle oinstall 5251072 Apr 16 12:19 users01.dbf 23c-data/FREE/pdbseed: total 1454144 -rwxrwxrwx 1 oracle oinstall 325066752 Mar 28 15:27 sysaux01.dbf -rwxrwxrwx 1 oracle oinstall 293609472 Mar 28 15:27 system01.dbf -rwxrwxrwx 1 oracle oinstall 20979712 Mar 28 15:25 temp01.dbf -rwxrwxrwx 1 oracle oinstall 104865792 Mar 28 15:27 undotbs01.dbf 23c-data/dbconfig: total 0 drwxrwxrwx 8 oracle oinstall 256 Apr 16 12:16 FREE 23c-data/dbconfig/FREE: total 48 -rwxrwxrwx 1 oracle oinstall 449 Mar 28 15:28 listener.ora -rwSr----- 1 oracle oinstall 2048 Apr 16 12:19 orapwFREE -rwxrwxrwx 1 oracle oinstall 779 Mar 28 15:28 oratab -rwxrwxrwx 1 oracle oinstall 3584 Apr 16 12:17 spfileFREE.ora -rwxrwxrwx 1 oracle oinstall 69 Mar 28 15:28 sqlnet.ora -rwxrwxrwx 1 oracle oinstall 690 Mar 28 15:28 tnsnames.ora
Step 8 – Remove Container & Volume
Now we can remove the existing 23c Container and its associated volume.
docker rm 23c docker volume prune -f
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.
docker run -d \ --name 23c \ -p 1522:1521 \ -v $HOME/docker/23c-data:/opt/oracle/oradata \ container-registry.oracle.com/database/free
To monitor the console output we run the following command:
docker logs -tf 23c
Here’s the log output with timestamps. The database was up and running after 40 seconds.
2023-04-16T10:27:31.320723000Z Starting Oracle Net Listener. 2023-04-16T10:27:31.958206000Z Oracle Net Listener started. 2023-04-16T10:27:31.958391000Z Starting Oracle Database instance FREE. 2023-04-16T10:28:08.401153000Z Oracle Database instance FREE started. 2023-04-16T10:28:08.404032000Z 2023-04-16T10:28:08.520502000Z The Oracle base remains unchanged with value /opt/oracle 2023-04-16T10:28:11.555842000Z ######################### 2023-04-16T10:28:11.565430000Z DATABASE IS READY TO USE! 2023-04-16T10:28:11.565936000Z ######################### 2023-04-16T10:28:11.670669000Z The following output is now a tail of the alert.log: 2023-04-16T10:28:11.697019000Z FREEPDB1(3):Opening pdb with Resource Manager plan: DEFAULT_PLAN 2023-04-16T10:28:11.697309000Z 2023-04-16T10:28:07.384593+00:00 2023-04-16T10:28:11.697423000Z Completed: Pluggable database FREEPDB1 opened read write 2023-04-16T10:28:11.697460000Z 2023-04-16T10:28:07.573292+00:00 2023-04-16T10:28:11.697490000Z =========================================================== 2023-04-16T10:28:11.697518000Z Dumping current patch information 2023-04-16T10:28:11.697545000Z =========================================================== 2023-04-16T10:28:11.697581000Z No patches have been applied 2023-04-16T10:28:11.697606000Z =========================================================== 2023-04-16T10:28:11.697633000Z Completed: ALTER DATABASE OPEN
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.
The post Oracle Database 23c on a Mac with an M-Series Chip appeared first on Philipp Salvisberg's Blog.