Skip to content

Instantly share code, notes, and snippets.

@deeTEEcee
Last active July 13, 2021 15:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deeTEEcee/124ac8faa0d2b1df0e5e09799bd19db6 to your computer and use it in GitHub Desktop.
Save deeTEEcee/124ac8faa0d2b1df0e5e09799bd19db6 to your computer and use it in GitHub Desktop.
Setting up an oracle database for testing

Setting up database for testing

  1. To build the image (since not hosted on dockerhub), follow the instructions on this page
    • If the dockerfile is incorrect, it's probably them just failing at README's. Try docker build -f Dockerfile.xe -t oracle/database:11.2.0.2-xe .
    • The README also provides more info. Under that page, search for the section referring to this specific image.
  2. Do a test run: docker run -d -e ORACLE_PWD=oracle --shm-size="1g" -p 1521:1521 -p 8080:8080 oracle/database:11.2.0.2-xe (More details on --shm-size: oracle/docker-images#458)
    • The default database name will be 'xe.'
  3. Add cx_Oracle / sqlalchemy to your system. Example here

Client installation (Debian)

A couple of things you still have to do to get this working on the client side.

  1. Install the following libraries:
  • wget
  • unzip
  • libaio-dev
  1. Do the installation and env setup below. (I wouldn't be surprised if any of that changes though)
# Oracle DB connection dependencies
# Alternative source link in case the oracle one disappears:
# https://storage.googleapis.com/artifacts.sightmachine-178216.appspot.com/instantclient-basiclite-linux.x64-21.1.0.0.0.zip
RUN mkdir -p /opt/oracle && \
    wget -O /opt/oracle/instantclient.zip https://download.oracle.com/otn_software/linux/instantclient/211000/instantclient-basiclite-linux.x64-21.1.0.0.0.zip && \
    unzip /opt/oracle/instantclient.zip -d /opt/oracle && \
    rm /opt/oracle/instantclient.zip
ENV LD_LIBRARY_PATH=/opt/oracle/instantclient_21_1

Database-specific features

Oracle SQL is somewhat different from the regular SQL language in a few ways.

  • If you're using 11g or older and want to use SQL Limit, you can use the example below. ROWNUM is a generated column. Note that below
   SELECT *
     FROM (SELECT * FROM table ORDER BY any_column ASC)
    WHERE counter > :counter AND ROWNUM <= 500
@deeTEEcee
Copy link
Author

This also works with 18.4 xe but the complication is the image is a lot larger and takes a lot longer to setup. https://github.com/deeTEEcee/minimized-oraclexe-image is a fork I added that adds migration support to the minimized version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment