Skip to content

Instantly share code, notes, and snippets.

@lucasslemos
Created April 10, 2023 14:49
Show Gist options
  • Select an option

  • Save lucasslemos/27e4fae25c699ee4c64d45ff6441f4e3 to your computer and use it in GitHub Desktop.

Select an option

Save lucasslemos/27e4fae25c699ee4c64d45ff6441f4e3 to your computer and use it in GitHub Desktop.
Rails Oracle Client 21 Linux
# Version 21.9.0.0.0 (Requires glibc 2.14)
# Instalar a biblioteca
sudo apt-get install libaio1 unzip
# Criar a pasta
sudo mkdir /opt/oracle
# Mover para /opt/oracle
instantclient-basic-linux.x64-21.6.0.0.0.zip
https://download.oracle.com/otn_software/linux/instantclient/219000/instantclient-basic-linux.x64-21.9.0.0.0dbru.zip
instantclient-sdk-linux.x64-21.6.0.0.0.zip
https://download.oracle.com/otn_software/linux/instantclient/219000/instantclient-sdk-linux.x64-21.9.0.0.0dbru.zip
# Extrair para /opt/oracle
unzip instantclient-basic-linux.x64-21.9.0.0.0.zip
unzip instantclient-sdk-linux.x64-21.9.0.0.0.zip
sudo mv instantclient_21_9/ /opt/oracle/
# Criar o link simbolico da lib
cd /opt/oracle/instantclient_21_6
ln -s libclntsh.so.19.1 libclntsh.so
ln -s libocci.so.19.1 libocci.so
# Manter versões legadas
ln -s /opt/oracle/instantclient_21_9 /opt/oracle/instantclient
# Configurando LD
sudo sh -c "echo /opt/oracle/instantclient_21_9 > /etc/ld.so.conf.d/oracle-instantclient.conf"
sudo ldconfig
# Exporta as variaveis abaixo .bashrc .zshrc:
export LD_LIBRARY_PATH=/opt/oracle/instantclient_21_9:$LD_LIBRARY_PATH
export PATH=/opt/oracle/instantclient_21_9:$PATH
# Criando o projeto no Rails
rails new projeto -d oracle
# Adiciona no Gemfile
gem 'activerecord-oracle_enhanced-adapter'
gem 'ruby-oci8'
# Instalando as gems
bundle install
# colocar no config/boot.rb
ENV['LD_LIBRARY_PATH'] ||= '/opt/oracle/instantclient'
ENV['NLS_LANG'] = 'BRAZILIAN PORTUGUESE_BRAZIL.AL32UTF8'
# JAVA_HOME (jdk-8u331-linux-x64.tar.gz)
ln -s /opt/oracle/jdk1.8.0_202 /opt/oracle/jdk
export JAVA_HOME="/opt/oracle/jdk"
export PATH="$JAVA_HOME/bin:$PATH"
# Configuração do Number Oracle
# conf/database.yml
nls_numeric_characters: '.,'
# Criar um arquivo config/initializers/oracle.rb e inserir o código
ActiveSupport.on_load(:active_record) do
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.class_eval do
# true and false will be stored as 'Y' and 'N'
self.emulate_booleans_from_strings = true
# start primary key sequences from 1 (and not 10000) and take just one next value in each session
self.default_sequence_start_value = "1 NOCACHE INCREMENT BY 1"
# Use old visitor for Oracle 12c database
self.use_old_oracle_visitor = false
# other settings ...
# ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.default_tablespaces =
# {:clob => 'TSLOBS', :blob => 'TSLOBS', :index => 'TSINDEXES', :table => 'TSTABLES'}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment