2

I'm trying automate DBCA to create a new database. I'm using the box bseller/oracle-standard with Vagrant.

provision.sh

#!/bin/bash
echo 'Import environment variables'
env=$( grep -ic "ORACLE_SID" /etc/profile )
if [ ! $env -eq 1 ] ; then
    echo export ORACLE_SID=mydatabase >> /etc/profile
    echo export ORACLE_BASE=/u01/app/oracle >> /etc/profile
    echo export ORACLE_HOME=/u01/app/oracle/product/11.2/dbhome_1 >> /etc/profile
    source /etc/profile
    echo export PATH=$PATH:$ORACLE_HOME/bin >> /etc/profile
fi

echo "Connect with user ORACLE"
sudo su -l oracle

echo "Loading environment variables"
source /etc/profile

echo 'Create database mydatabase'
if [ ! -d /u01/app/oracle/oradata/mydatabase ] ; then
    dbca -silent -createDatabase -templateName General_Purpose.dbc -gdbName mydatabase -sysPassword mypassword -systemPassword mypassword -scriptDest /u01/app/oracle/oradata/mydatabase -characterSet WE8ISO8859P1
fi

But this script doesn't worked:

$ sh provision.sh 
Import environment variables
Connect with user ORACLE
Loading environment variables
Create database mydatabase
DBCA cannot be run as root.

Running all lines from provision.sh in command line. worked!

acfreitas
  • 1,347
  • 2
  • 13
  • 27

2 Answers2

2

I am wondering that the line below does not work to run the oracle command inside of a shell script:

sudo su -l oracle

You should wrap your command to get it work:

su -c "dbca -silent -createDatabase -templateName General_Purpose.dbc -gdbName qualidade -sysPassword password -systemPassword password -scriptDest /u01/app/oracle/oradata/qualidade -characterSet WE8ISO8859P1" -s /bin/sh oracle

I got this solution here: how to run script as another user without password

Community
  • 1
  • 1
Eric
  • 64
  • 5
0

"Unable to check for available memory"

I fixed in this form:

I go to my other server with OLD installation Oracle (running fine Oracle 11g), then I find 3 files:

oracle_env.csh
oracle_env.sh
nls_lang.sh

becouse this files no exist in new server, I create with the content (path correct) the files

  1. oracle_env.csh
  2. oracle_env.sh

and put this lines into they:

touch /opt/oracle/product/18c/dbhomeXE/bin/oracle_env.csh
echo 'setenv ORACLE_HOME /opt/oracle/product/18c/dbhomeXE
setenv ORACLE_SID XE
setenv NLS_LANG `$ORACLE_HOME/bin/nls_lang.sh`
setenv PATH $ORACLE_HOME/bin:$PATH' >> /opt/oracle/product/18c/dbhomeXE/bin/oracle_env.csh

after second file:

touch /opt/oracle/product/18c/dbhomeXE/bin/oracle_env.sh
echo 'export ORACLE_HOME=/opt/oracle/product/18c/dbhomeXE
export ORACLE_SID=XE
export NLS_LANG=`$ORACLE_HOME/bin/nls_lang.sh`
export PATH=$ORACLE_HOME/bin:$PATH' >> /opt/oracle/product/18c/dbhomeXE/bin/oracle_env.sh

becouse the file nls_lang.sh is very long and have many config about CHARSET, I copy from OLD server to NEW server.

after is necesary config owner/group of this files:

chown oracle:oinstall /opt/oracle/product/18c/dbhomeXE/bin/oracle_env.csh
chown oracle:oinstall /opt/oracle/product/18c/dbhomeXE/bin/oracle_env.sh
chown oracle:oinstall /opt/oracle/product/18c/dbhomeXE/bin/nls_lang.sh

also the file nls_lang.sh require 755:

chmod 0755 /opt/oracle/product/18c/dbhomeXE/bin/nls_lang.sh

is necesary login as user oracle:

su -l oracle

then I go to folder and load vars environment:

cd /opt/oracle/product/18c/dbhomeXE/bin
. ./oracle_env.sh

finally I can run the command dbca:

dbca -createDatabase -silent -gdbName ora18c -templateName XE_Database.dbc -sysPassword YourPWD1 -systemPassword YourPWD1 -dbsnmpPassword YourPWD1 -datafileDestination /opt/oracle/oradata -storageType FS -memoryPercentage 20 -emConfiguration NONE -sampleSchema false -J-Doracle.assistants.dbca.validate.ConfigurationParams=false

and I get the greath result:

[server@petro bin]$ dbca -createDatabase -silent -gdbName ora18c -templateName XE_Database.dbc -sysPassword YourPWD1 -systemPassword YourPWD1 -dbsnmpPassword YourPWD1 -datafileDestination /opt/oracle/oradata -storageType FS -memoryPercentage 20 -emConfiguration NONE -sampleSchema false -J-Doracle.assistants.dbca.validate.ConfigurationParams=false
Prepare for db operation
10% complete
Copying database files
40% complete
Creating and starting Oracle instance
42% complete
46% complete
50% complete
54% complete
60% complete
Completing Database Creation
66% complete
69% complete
70% complete
Executing Post Configuration Actions
100% complete
Database creation complete. For details check the logfiles at:
/opt/oracle/cfgtoollogs/dbca/ora18c.
Database Information:
Global Database Name:ora18c
System Identifier(SID):ora18c
Look at the log file "/opt/oracle/cfgtoollogs/dbca/ora18c/ora18c.log" for further details.
[server@petro bin]$

becouse I need PHP in this servers, I require OCI8, then I run:

/usr/bin/ea-php72-pecl install oci8
/usr/bin/ea-php71-pecl install oci8
/usr/bin/ea-php70-pecl install oci8

when this request:

**Please provide the path to the ORACLE_HOME directory. Use 'instantclient,/path/to/instant/client/lib' if you're compiling with Oracle Instant Client [autodetect] :**

samplelly [ENTER] then this run fine for me...

Regards.

Stackoverflow
  • 449
  • 5
  • 13