Skip to content

Commit

Permalink
Merge pull request #3879 from akostadinov/dbs
Browse files Browse the repository at this point in the history
some database inscructions and convenience
  • Loading branch information
akostadinov authored Sep 6, 2024
2 parents 1533335 + 1e64ed0 commit a134289
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 9 deletions.
11 changes: 7 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ clean:

oracle-db-setup: ## Creates databases in Oracle
oracle-db-setup: oracle-database
MASTER_PASSWORD=p USER_PASSWORD=p ORACLE_SYSTEM_PASSWORD=threescalepass NLS_LANG='AMERICAN_AMERICA.UTF8' DATABASE_URL="oracle-enhanced://rails:railspass@127.0.0.1:1521/systempdb" bundle exec rake db:drop db:create db:setup
MASTER_PASSWORD=p USER_PASSWORD=p ORACLE_SYSTEM_PASSWORD=threescalepass NLS_LANG='AMERICAN_AMERICA.UTF8' DATABASE_URL="oracle-enhanced://rails:railspass@127.0.0.1:1521/systempdb" ORACLE_DO_NOT_EXPIRE_SYSTEM=1 bundle exec rake db:drop db:create db:setup
MASTER_PASSWORD=p USER_PASSWORD=p ORACLE_SYSTEM_PASSWORD=threescalepass NLS_LANG='AMERICAN_AMERICA.UTF8' DATABASE_URL="oracle-enhanced://rails:railspass@127.0.0.1:1521/systempdb" RAILS_ENV=test bundle exec rake db:drop db:create db:setup

schema: ## Runs db schema migrations. Run this when you have changes to your database schema that you have added as new migrations.
schema: POSTGRES_DATABASE_URL ?= "postgresql://postgres:@localhost:5432/3scale_system_development"
Expand All @@ -103,16 +104,18 @@ schema:

oracle-database: ## Starts Oracle database container
oracle-database:
[ "$(shell docker inspect -f '{{.State.Running}}' oracle-database 2>/dev/null)" = "true" ] || docker start oracle-database &>/dev/null || docker run \
-d \
if [ "$(shell docker inspect -f '{{.State.Running}}' oracle-database 2>/dev/null)" != "true" ]; then \
docker start oracle-database &>/dev/null || docker run -d \
--shm-size=6gb \
-p 1521:1521 -p 5500:5500 \
--name oracle-database \
-e ORACLE_PDB=systempdb \
-e ORACLE_SID=threescale \
-e ORACLE_PWD=threescalepass \
-e ORACLE_CHARACTERSET=AL32UTF8 \
$(ORACLE_DB_IMAGE)
$(ORACLE_DB_IMAGE) && \
docker logs --tail=1 -f oracle-database | grep -m 1 "DATABASE IS READY TO USE"; \
fi

# Check http://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
help: ## Print this help
Expand Down
17 changes: 13 additions & 4 deletions SETUP_ORACLE.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ If you wish, you can also install SQLPLus client from same location as well.

### Setup Podman with user namespaces

On recent Fedora versions, new users already have that setup.

```sh
dnf install -y podman-docker
sudoedit /etc/subuid # add line: myusername:10000:54321
Expand All @@ -20,7 +22,7 @@ sudoedit /etc/subgid # add line: myusername:10000:54330

## Prerequisites on other Linux and probably MAC

### Install Oracle dependencies using the script
### Install Oracle Instant Client using the script

1. Run the script with sudo
```shell
Expand All @@ -34,14 +36,16 @@ LD_LIBRARY_PATH="/opt/oracle/instantclient/:$LD_LIBRARY_PATH"
ORACLE_HOME=/opt/oracle/instantclient/
```

### Install Oracle Instant Client
### Install Oracle Instant Client via RPM

1. Go to [the official Oracle Instant Client Downloads site](https://www.oracle.com/database/technologies/instant-client/downloads.html) and download the following **.rpm** packages for your operative system:

- Basic
- SQL Plus
- SDK

On Fedora or a Red Hat based distro, you can just install the RPMs. Instructions for Debian based systems follow.

2. Create a folder in `/opt/oracle` if it does not exist yet (with `mkdir -p /opt/oracle`) and save these packages there.

3. Install the dependency `libaio1` and the package `alien`.
Expand All @@ -60,7 +64,7 @@ export OCI_LIB_DIR=$ORACLE_HOME/lib
export OCI_INC_DIR=/usr/include/oracle/X/client64
```

### Setup Docker
### Setup Docker (but preferably use podman)

You need to have Docker installed and running. You also need to be able to [run containers as a non-root user](https://docs.docker.com/install/linux/linux-postinstall/).

Expand Down Expand Up @@ -95,10 +99,15 @@ You need to have Docker installed and running. You also need to be able to [run

### ORA-12637: Packet receive failed

Add `DISABLE_OOB=ON` to `sqlnet.ora` ([github issue](https://github.com/oracle/docker-images/issues/1352)).
Add `DISABLE_OOB=ON` to `sqlnet.ora` ([github issue](https://github.com/oracle/docker-images/issues/1352)). For installation from archive that would be

```shell
echo "DISABLE_OOB=ON" >> /opt/oracle/instantclient/network/admin/sqlnet.ora
```

For RPM installation (update version `21` with whatever you installed locally).
```shell
echo "DISABLE_OOB=ON" >> /usr/lib/oracle/21/client64/lib/network/admin/sqlnet.ora
```

For IntelliJ/RubyMine, go to Database -> Database Source properties -> Drivers -> Oracle -> Advanced -> oracle.net.disableOob -> true
2 changes: 1 addition & 1 deletion config/examples/database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ development:

test:
<<: *default
url: <%= "#{ENV['DATABASE_URL']}#{ENV['TEST_ENV_NUMBER']}" %>
url: <%= "#{ENV['DATABASE_URL'].delete_suffix("_development")}test#{ENV['TEST_ENV_NUMBER']}" %>

production:
<<: *default
Expand Down
5 changes: 5 additions & 0 deletions lib/system/database.rb
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,11 @@ def create
if ENV['ORACLE_SYSTEM_PASSWORD'].present?
Logger.new($stderr).warn("Oracle's SYSTEM user will create/update a non-SYSTEM user and grant it permissions")
super

if ["1", "true"].include?(ENV["ORACLE_DO_NOT_EXPIRE_SYSTEM"])
profile = connection.execute("select profile from DBA_USERS where username = 'SYSTEM'").fetch.first
connection.execute "alter profile #{profile} limit password_life_time UNLIMITED"
end
else
# Will raise ActiveRecord::NoDatabaseError if the database doesn't exist
establish_connection(@config)
Expand Down

0 comments on commit a134289

Please sign in to comment.