How to use "alter system.." sql statement in AWS RDS oracle? - oracle

"ALTER SYSTEM FLUSH BUFFER_CACHE;"
to delete data buffer cache of oracle db command was used.
But then the error occurred.
SQL Error [1031] [42000]: ORA-01031
So I used another command:
"EXEC rdsadmin.rdsadmin_util.flush_buffer_cache;
The following error occurred.
SQL Error [900] [42000]: ORA-00900
According to the documentation, "exec admin.admin_util.flush_buffer_cache;" This command says it can be used, but can you tell me why it can't?
And is there any other way to do flust_buffer_cache?

The first error indicates that your user doesn't have privileges to use alter system.
The second error indicates your command is incorrect. You seem to have lost the "rds" from "rdsadmin". Have you tried this:
EXEC rdsadmin.rdsadmin_util.flush_buffer_cache;
or
begin
rdsadmin.rdsadmin_util.flush_buffer_cache;
end;
/
Per the AWS documentation, here: https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Appendix.Oracle.CommonDBATasks.System.html

Related

how to use Big SQL commands to automate the synchronization with HIVE through shell script?

I have written a small shell script to automate the Big SQL and HIVE synchronization.
Code is as below
echo "Login to BigSql"
<path to>/jsqsh bigsql --user=abc --password=pwd
echo "login succesfull"
echo "Syncing hive table <tbl_name> to Big SQL"
call syshadoop.hcat_sync_objects('DB_name','tbl_name','a','REPLACE','CONTINUE');
echo "Syncing hive table TRAINING_TRACKER to Big SQL Successfully"
Unfortunately, I am getting the message:
Login to BigSql
Welcome to JSqsh 4.8
Type "\help" for help topics. Using JLine.
And then it enters the Big SQL command prompt. Now when I type "quit" and hit enter, it gives me following messages:
login succesful
Syncing hive table <tbl_name> to Big SQL
./script.sh: line 10: call syshadoop.hcat_sync_objects(DB_name,tbl_name,a,REPLACE,CONTINUE): command not found
What am I doing wrong?
You would need to redirect the output of your later commands into the jsqsh command. E.g. see this example
You can start JSqsh and run the script at the same time with this command:
/usr/ibmpacks/common-utils/current/jsqsh/bin/jsqsh bigsql < /home/bigsql/mySQL.sql
from here https://www.ibm.com/support/knowledgecenter/en/SSCRJT_5.0.2/com.ibm.swg.im.bigsql.doc/doc/bsql_jsqsh.html
There already is an auto-hcat sync job in Big SQL that does exactly what you're trying to do
Check if the job is running by
su - bigsql (or whatever instance owner)
db2 connect to bigsql
db2 "select NAME, BEGIN_TIME, END_TIME, INVOCATION, STATUS from
SYSTOOLS.ADMIN_TASK_STATUS where BEGIN_TIME > (CURRENT TIMESTAMP - 60 minutes)
and name ='Synchronise MetaData Changes from Hive' "
if you don't see an output , simply enable it through Ambari :
Enable Automatic Metadata Sync

Oracle OCI API RMAN Commands

When I try to execute the "delete noprompt archivelog until time ‘SYSDATE-1’;" command using "OCIStmtExecute" function ,
I am getting an error like "ORA-00933: SQL command not properly ended"
Is this the correct command to delete ARCHIVE logs? Whether it is possible to execute RMAN commands using OCI API ? Are there any OCI functions to delete ARCHIVELOGS (log truncation) ?

Executing an sql script vi an OCI8 connection object

I have a locally running oracle thin client and have successfully created a ruby script to connect to a remote oracle database. I successfully make a call (select * from table_name) to the database to get the content of a table:
begin
con = OCI8.new('<user>', <password>, '<host>:<port>/XE')
con.exec('select name from actor') do |records|
puts records
end
rescue OCIError
puts "Database Connection Error"
end
I also want to run an sql script that resides in the oracle directory on the remote host.
Usually I perform the following:
su - oracle
sqlplus <user>/<password>
<SQL> #<script_name>
and this will run the script
In the ruby script I try the following:
con.exec('#<script_name>')
Yet, I get the following error:
stmt.c:230:in oci8lib_200.bundle: ORA-00900: invalid SQL statement (OCIError)
#<script_name> is an sqlplus command.
When sqlplus find #<script_name>, it opens <script_name>, divides its contents to SQL statements and executes them.
If you want to run SQL statements in a script by ruby, you need to write code which opens the script, divides its contents and pass SQL statements to con.exec one by one.
I also want to run an sql script that resides in the oracle directory on the remote host. Usually I perform the following:
No, it can't. sqlplus reads the sql script that resides on the local host.
You can put this script in a function (function_name) and execute
con.exec("select function_name from dual")

using strace to debug db2 CLI executing a query

I would like to use strace to debug a strange behaviour I have with db2. I have a SQL function myFoo() implemented in C that doesn't get called for some reason (some code access path not existing or not authorized see here). My Sql Function call a function Fooin shared library in /usr/local/lib/libmyfoo (so in db2 term /usr/local/lib/libmyfoo!Foo).
If I use strace directly with db2 and the query I have an error saying
A database connection does not exist
so i created a script call debug.sh with the following. The idea is to have a shell with the db2 connection active and trace it.
db2 "connect to MYDB"
db2 "select * from table(myFoo())" # this calls /usr/local/lib/libmyfoo!Foo
db2 "disconnect MYDB"
It doesn't work cos I realized that strace works with binary so I have the error
Exec Format Error
Probably you are calling each DB2 command in different subshells.
You can fix that problem by executing everything in just one subshell, for example
VALUE=$(. /home/db2inst1/sqllib/db2profile ; db2 connect to MYDB ; db2 "select * from table(myFoo())")
My Sql Function call a function Foo in shared library in /usr/local/lib/libmyfoo (so in db2 term libmyfoo!Foo).
Is this really how you defined your function? libmyfoo!Foo will point to the library $INSTANCE_HOME/sqllib/function/libmyfoo. If your library is elsewhere you need to provide the absolute path to it.

Execute SQL query on Oracle working in Unix prompt but not in shell script

I am trying to connect to an Oracle db using a ksh script. When I run this directly from the prompt, it works. But when I put it inside a script (abc.sh) it fails. Below is what I've put in the script (edited to make it shorter):
Here abc is the username, while abc$123 is the password of the user which has access on database DBNAME.
#!/usr/bin/ksh
sqlplus -s /nolog << EOF > output
connect abc/abc$123#DBNAME;
set echo off
set heading off
select table_name from dba_tables;
exit;
EOF
This works if typed directly, but run as ./abc.sh, gives error -
ERROR ORA-01017: invalid username/password; logon denied
I'm sure I'm missing something simple, but can't figure this out. Thanks for your help.
You cannot just write code like this and expect it to be passed to the relevant program. Your SQL lines are being executed by KSH instead of your SQL server. Instead you need to do something more along the lines of:
echo "SQL CODE HERE" | sqlplus ....

Resources