我尝试自动化DBCA来创建新数据库。我正在使用Vagrant框bseller/oracle-standard。
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
但是这个脚本不起作用:
$ sh provision.sh
Import environment variables
Connect with user ORACLE
Loading environment variables
Create database mydatabase
DBCA cannot be run as root.
在命令行中从provision.sh运行所有行。成功了!
答案 0 :(得分:1)
我想知道下面这行不能在shell脚本中运行oracle命令:
sudo su -l oracle
您应该包装命令以使其正常工作:
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
我在这里得到了这个解决方案: how to run script as another user without password
答案 1 :(得分:0)
“ 无法检查可用内存”
我以这种形式固定:
我转到装有OLD安装Oracle(运行良好的Oracle 11g)的其他服务器,然后找到3个文件:
oracle_env.csh
oracle_env.sh
nls_lang.sh
因为此文件不存在在新服务器中,所以我使用内容(路径正确)创建了文件
并将这些行放入其中:
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
第二个文件之后:
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
因为文件 nls_lang.sh 很长,并且具有许多关于CHARSET的配置,所以我从旧服务器复制到新服务器。
之后是此文件的必要配置所有者/组:
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
nls_lang.sh 文件也需要755:
chmod 0755 /opt/oracle/product/18c/dbhomeXE/bin/nls_lang.sh
必须以oracle用户身份登录:
su -l oracle
然后我转到文件夹并加载vars环境:
cd /opt/oracle/product/18c/dbhomeXE/bin
. ./oracle_env.sh
最后,我可以运行命令 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
我得到了最好的结果:
[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]$
因为在此服务器中需要PHP,所以需要OCI8,然后运行:
/usr/bin/ea-php72-pecl install oci8
/usr/bin/ea-php71-pecl install oci8
/usr/bin/ea-php70-pecl install oci8
此请求时:
**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] :**
样本[ENTER],然后对我来说运行正常...
致谢。