ORA-12529 for Connecting to Oracle ATP Database - oracle

I have created an ATP database and I want to connect to it remotely from SQL Developer. When I tried to connect using the wallet files, I got this error:
Estado: Fallo:Fallo de la prueba: Listener refused the connection with the following error: ORA-12529, TNS:connect request rejected based on current filtering rules (CONNECTION_ID=DaiNx3GxQoKa7gYAEdsmwQ==)
This is how my ATP looks like
And this is the error I got:
Any suggestions?

As soon as I select the wallet-zip-file I am able to connect from SQL Developer.
This is the script I use to download and unpack in order to utilize sqlplus.
cat download-wallet-autonomous-database.sh
#!/bin/bash
set -euo pipefail
# set environment (password)
. env.sh
DBNAME=demodb
DB_WALLET_FILE=demodb_wallet.zip
# create directory where to download the wallet
mkdir -p connection/${DBNAME} || true
cd connection/${DBNAME}
# now, generate and retreive the wallet
oci db autonomous-database generate-wallet \
--generate-type all \
--autonomous-database-id $DBID \
--file ${DB_WALLET_FILE} \
--password "${ADMIN_PASSWORD}"
# unzip wallet file. All connection details are unpacked (sqlnet,tnsnames.ora,certificates)
unzip ${DB_WALLET_FILE}
# replace "?/network/admin" by current directory
sed -i '' 's:?/network/admin:'`pwd`':' sqlnet.ora
export TNS_ADMIN=$(pwd)
cat > env.sh <<EOF
#!/bin/bash
export ADMIN_PASSWORD=${ADMIN_PASSWORD}
export TNS_ADMIN=\$(pwd)
export TWO_TASK=${DBNAME}_high
EOF
# handy for later sqlplus connection
cat > connect.sh <<EOF
. env.sh
rlwrap sqlplus admin/\${ADMIN_PASSWORD}
EOF
I need the DBID (redacted)
./list-autonomous-databases.sh
+--------+-----------+---------+-----------+----------------------------------------------------------------------------------------------------------+
| DBName | DBWorkoad | Display | Status | id |
+--------+-----------+---------+-----------+----------------------------------------------------------------------------------------------------------+
| DEMODB | OLTP | DEMODB | AVAILABLE | ocid1.autonomousdatabase.oc1.eu-frankfurt-1.xxxxxxxxxxxxxxxxxx |
+--------+-----------+---------+-----------+----------------------------------------------------------------------------------------------------------+
Now, download wallet
./download-wallet-autonomous-database.sh ocid1.autonomousdatabase.oc1.eu-frankfurt-1.xxxxxxxxxxxxxxxxxxxxx
Both, sqlplus and SQL Developer works as expected.
./connect.sh
SQL*Plus: Release 19.0.0.0.0 - Production on Sun Aug 7 11:25:56 2022
Version 19.8.0.0.0
Copyright (c) 1982, 2020, Oracle. All rights reserved.
Last Successful login time: Sun Aug 07 2022 11:14:14 +02:00
Connected to:
Oracle Database 21c Enterprise Edition Release 21.0.0.0.0 - Production
Version 21.3.0.0.0
admin#MNYYI81SOQCUDNG_DEMODB> col authentication_type for a20
admin#MNYYI81SOQCUDNG_DEMODB> select SYS_CONTEXT('USERENV','NETWORK_PROTOCOL') authentication_type from dual;
AUTHENTICATION_TYPE
--------------------
tcps
Make sure you have connectivity (look into tnsnames.ora for host and port)
nc -vz adb.eu-frankfurt-1.oraclecloud.com 1522
Connection to adb.eu-frankfurt-1.oraclecloud.com port 1522 [tcp/ricardo-lm] succeeded!
Best of luck!

Related

How to store sql query output in variable in shell script

I am trying to store the value of sql query output in a variable using shell script.
size=`${PATH_TO_CLIENT}sqlplus $IMPUSER/$IMPPWD#$ENDPOINT<< EOF
select owner, sum(bytes)/1024/1024/1024 Size_GB from dba_segments where owner = 'XXXX' group by owner;
exit;
EOF`
echo "Total data is ${size}"
The output I am getting is
**Total data is**
SQL*Plus: Release 21.0.0.0.0 - Production on Fri May 14 11:06:42 2021
Version 21.1.0.0.0
Copyright (c) 1982, 2020, Oracle. All rights reserved.
Last Successful login time: Fri May 14 2021 11:01:02 -04:00
Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.8.0.0.0
SQL>
OWNER
--------------------------------------------------------------------------------
SIZE_GB
----------
XXXXXXX
12.2345
SQL> Disconnected from Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.8.0.0.0
Inside the variable full connection string and sql query output all are getting stored. I just want to get value like $size=12.2345 Please tell me how to get that
The size value might be assigned to the current variable through use of the following code block
size=$(sqlplus -S /nolog << EOF
conn $IMPUSER/$IMPPWD#$ENDPOINT
whenever sqlerror exit sql.sqlcode
SET PAGES 0
SELECT SUM(bytes)/1024/1024/1024 FROM dba_segments WHERE owner = 'XXXX';
EOF
)
echo "Total data is "$size
where
keeping owner column and group by clause are redundant as
returning only one column value for a single schema
no need to alias the calculated value as not needed for the returning result while hiding the column title through use of SET PAGES 0 command
using direct connection is not safe, but use sqlplus -S /nolog before
schema connection in order to hide the password while listed by
anbody through ps command.
You can use this:
size=`${PATH_TO_CLIENT}sqlplus -s $IMPUSER/$IMPPWD#$ENDPOINT <<EOF
set echo off
set feedback off
set heading off
set pages 0
select sum(bytes)/1024/1024/1024 Size_GB from dba_segments where owner = 'SYS';
exit;
EOF`
echo "Total data is ${size}"
If the output is consistent with newlines, you could use:
size=`${PATH_TO_CLIENT}sqlplus $IMPUSER/$IMPPWD#$ENDPOINT<< EOF | sed -n '/^\s*SIZE_GB$/{n;n;n;p}'
select owner, sum(bytes)/1024/1024/1024 Size_GB from dba_segments where owner = 'XXXX' group by owner;
exit;
EOF`
It will return the third line after line which contains 'SIZE_GB'.

How to create a new procedure from bash script

I'm trying to create a new PL/SQL Procedure in Oracle DB. The Procedure is to be created by a BASH script. Later-on the Procedure will be executed from the same BASH script.
There are ways to execute the stored procedure from bash script but none explains how to create a stored procedure form a bash script.
backup_procedure_string="CREATE OR REPLACE
PROCEDURE BACKUP_TABLE_PROCEDURE(
.
.
END BACKUP_TABLE_PROCEDURE;"
backup_procedure_execution_string="BACKUP_TABLE_PROCEDURE('${param1}', '${param2}', '${param3}');"
sqlplus -S "${ofca_connect_string}" << EOF >> "${current_directory}/query.log"
WHENEVER SQLERROR EXIT 1
SET SERVEROUTPUT ON
SET TERMOUT OFF
$backup_procedure_string
EXECUTE $backup_procedure_execution_string
SET SERVEROUTPUT OFF
EXIT;
EOF
The Procedure "BACKUP_TABLE_PROCEDURE" should be created in the Database and gets executed. However, there is no error/oracle error but the procedure is also not getting created.
Works for me, here's a complete code sample.
Note I used SQLcl not SQLPlus, but same concept.
No idea what you have in your . . code, so maybe problem is there?
Jeffreys-Mini:19.1 thatjeffsmith$ procedure_string="CREATE OR REPLACE PROCEDURE SO_BASH is BEGIN
> null;
> END SO_BASH;
> /
> "
Jeffreys-Mini:19.1 thatjeffsmith$ echo $procedure_string
CREATE OR REPLACE PROCEDURE SO_BASH is BEGIN null; END SO_BASH; /
Jeffreys-Mini:19.1 thatjeffsmith$ sql hr/oracle << EOF >> so.log
> $procedure_string
> EXIT;
> EOF
Jeffreys-Mini:19.1 thatjeffsmith$ more so.log
SQLcl: Release 18.3 Production on Fri Jun 14 10:16:57 2019
Copyright (c) 1982, 2019, Oracle. All rights reserved.
Last Successful login time: Fri Jun 14 2019 10:16:58 -04:00
Connected to:
Oracle Database 18c Enterprise Edition Release 18.0.0.0.0 - Production
Version 18.3.0.0.0
Procedure SO_BASH compiled
Disconnected from Oracle Database 18c Enterprise Edition Release 18.0.0.0.0 - Production
Version 18.3.0.0.0
Jeffreys-Mini:19.1 thatjeffsmith$
And browsing my schema...

sqlldr error in Oracle

Currently, I am using sqlldr userid= {user}/{pass}#{SID} to load the file into database, and this comment is in a bash file.
The password is generated by a third lib framework.
But, I found that sometimes I got the following error,
export TNS_ADMIN=/opt/config/uat/
export PATH=$PATH:$ORACLE_HOME/bin
sqlldr userid=M_UAT/YAu8D=5r#My_UAT
ERR>LRM-00116: syntax error at 'M_UAT/YAu8D' following '='
I found that there is a special character = in the password,
I checked something, seems sqlplus can avoid this exception by userid= ={user}/\"{pass}\"#{SID}
But sqlldr cannot.
Does anyone have an idea here?
sqlplus makes a connection with the username and password in quotes. The sqlloader(sqlldr) connects to the database only if the name is written without quotes.
The password can contain #!= characters only in quotation marks, for example
password=\"YAu8D=5r\"
password=\"#!YAu8D=5r#\"
Example 1
username=HR
password=\"YAu8D=5r\"
Change password
oracle#esmd:~> sqlplus / as sysdba
SQL*Plus: Release 11.2.0.3.0 Production on Mon Jul 2 13:39:10 2018
Copyright (c) 1982, 2011, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Release 11.2.0.3.0 - 64bit Production
SQL> alter user hr identified by "YAu8D=5r" ;
User altered.
SQL> exit
Test connect sqlplus
#!/bin/sh
username=\"HR\"
password=\"YAu8D=5r\"
echo username: $username
echo password: $password
testoutput=$(sqlplus -s $username/$password << EOF
set pagesize 0 feedback off verify off heading off echo off;
show user
SELECT to_char(sysdate,'DD-MM-YYYY HH24:MI')||' Test passed' from dual
#ulcase1.sql
exit;
EOF
)
echo $testoutput
oracle#esmd:~> ./test_Upper_case2.sh
username: "HR"
password: "YAu8D=5r"
USER is "HR"
Test SQL*loader script test_sqlldr.sh
oracle#esmd:~> more test_sqlldr.sh
#!/bin/sh
username=hr
password=\"YAu8D=5r\"
sqlldr userid=$username/$password control=ulcase2.ctl log=log.log
Test SQL*loader
oracle#esmd:~> ./test_sqlldr.sh
SQL*Loader: Release 11.2.0.3.0 - Production on Mon Jul 2 13:46:29 2018
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
Commit point reached - logical record count 7
oracle#esmd:~>
Test network connection sqlldr
oracle#esmd:~> more test_sqlldr.sh
#!/bin/sh
username=hr
password=\"YAu8D=5r\"
sqlldr userid=$username/$password#esmd control=ulcase2.ctl log=log.log
oracle#esmd:~> ./test_sqlldr.sh
SQL*Loader: Release 11.2.0.3.0 - Production on Mon Jul 2 13:53:24 2018
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
Commit point reached - logical record count 7
Example 2
username=HR
password=\"#!YAu8D=5r#\"
Script for connection testing sqlplus
#!/bin/sh
username=HR
password=\"#!YAu8D=5r#\"
echo username: $username
echo password: $password
testoutput=$(sqlplus -s $username/$password << EOF
set pagesize 0 feedback off verify off heading off echo off;
show user
SELECT to_char(sysdate,'DD-MM-YYYY HH24:MI')||' Test passed' from dual;
#ulcase1.sql
exit;
EOF
)
echo $testoutput
Test connect sqlplus
oracle#esmd:~> ./test_Upper_case2.sh
username: "HR"
password: "#!YAu8D=5r#"
USER is "HR" 03-07-2018 12:44 Test passed
Test SQL*loader script test_sqlldr.sh
#!/bin/sh
username=HR
password=\"#!YAu8D=5r#\"
sqlldr userid=$username/$password control=ulcase2.ctl log=log.log
Test SQL*loader
oracle#esmd:~> ./test_sqlldr.sh
SQL*Loader: Release 11.2.0.3.0 - Production on Tue Jul 3 12:48:53 2018
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
Commit point reached - logical record count 7
Example 3
username=\"HR\"
password=\"#!YAu8D=5r#\"
Script for connection testing sqlplus
#!/bin/sh
username=\"HR\"
password=\"#!YAu8D=5r#\"
echo username: $username
echo password: $password
testoutput=$(sqlplus -s $username/$password << EOF
set pagesize 0 feedback off verify off heading off echo off;
show user
SELECT to_char(sysdate,'DD-MM-YYYY HH24:MI')||' Test passed' from dual;
#ulcase1.sql
exit;
EOF
)
echo $testoutput
Test connect sqlplus
oracle#esmd:~> ./test_Upper_case2.sh
username: "HR"
password: "#!YAu8D=5r#"
USER is "HR" 03-07-2018 12:51 Test passed
oracle#esmd:~> more test_sqlldr.sh
#!/bin/sh
username=\"HR\"
password=\"#!YAu8D=5r#\"
sqlldr userid=$username/$password control=ulcase2.ctl log=log.log
Test SQL*loader
oracle#esmd:~> ./test_sqlldr.sh
LRM-00112: multiple values not allowed for parameter 'userid'
SQL*Loader: Release 11.2.0.3.0 - Production on Tue Jul 3 12:54:42 2018
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
SQL*Loader-100: Syntax error on command-line

sqlplus Dynamic Spool File Name

I need to give the spool file name dynamically and I have to pass the parameters when I call sqlplus. Below is what I tried
echo exit | sqlplus "{{ Oracle_username }}/ {{ Oracle_pwd}} #(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(Host={{ Oracle_HostName }} )(Port=1521))(CONNECT_DATA=(SID= {{Oracle_SID }})))" #Script.sql 'AppName' 'DatabaseName' 'ObjectType'
Over here I tried to pass App Name, Database Name and Object Type dynamically. Prior to running SQLPLUS step, I create folders dynamically (App Name , Database Name , Object Type are all folders and it will vary depending on each application) .Below is how my script.sql looks like :
SPOOL &&AppName/&&DatabaseName/&&ObjectType/Output.csv
<<SQL Script>>
SPOOL OFF
This doenst work . Can someone tell me what needs to be changed.
You are passing the values you want to form your spool file path and name as arguments to your script, but you need to refer to them as positional parameters:
SPOOL &1/&2/&3/Output.csv
Or if you're going to reuse them for something else you could define your own variable, set from the positional parameters:
DEFINE AppName=&1
DEFINE DatabaseName=&2
DEFINE ObjectType=&3
SPOOL &&AppName/&&DatabaseName/&&ObjectType/Output.csv
The spool file path will be relative to the directory you're in when you run the script. If that isn't what you want then put the root before the first substitution variable in the spool command, whichever form you use.
You could also include the exit in your .sql file so you don't have to echo it in; and you could use a TNS alias instead of passing all of the connection information on the command line - or if you can use a service name instead of a SID, you could use the easy connect syntax which is a bit simpler:
sqlplus username/password#//hostname:1521/service_name #Script.sql 'AppName' 'DatabaseName' 'ObjectType'
set your appname,dbname,objecttype's as environmental variables and then Try like below
[oracle#ct-myhost-02 ~]$ export app_name=/stage
[oracle#ct-myhost-02 ~]$ export database_name=PSES
[oracle#ct-myhost-02 ~]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.3.0 Production on Wed Feb 1 12:04:08 2017
Copyright (c) 1982, 2011, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> spool $app_name/$database_name/out.csv
SQL> select * from dual;
D
-
X
SQL> spool off;
SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
[oracle#ct-myhost-02 ~]$ ls -l /stage/PSES/out.csv
-rw-r-----. 1 oracle oinstall 286 Feb 1 12:04 /stage/PSES/out.csv

How to return just the values from sqlplus using set variables?

Can someone please help me here?
Looks like I setup the right values in the set variables, but it's returning lot of things. See below:
################################
# Main
################################
RETVAL=`sqlplus user/pass#DB <<EOF
SET PAGESIZE 0 FEEDBACK OFF VERIFY OFF HEADING OFF ECHO OFF
SELECT process_id, source, destination, type FROM table WHERE process_id IN ('12311','12322');
EXIT;
EOF`
if [ -z "$RETVAL" ]; then
echo "No rows returned from database"
exit 0
else
echo $RETVAL
fi
The output is:
SQL*Plus: Release 9.2.0.8.0 - Production on Thu Jun 27 19:37:39 2013 Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved. Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production With the Partitioning, OLAP, Data Mining and Real Application Testing options SQL> SQL> 12311 ,AAA BBB ,2 12322 ,AAA BBB ,5 SQL> Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production With the Partitioning, OLAP, Data Mining and Real Application Testing options
I just would like:
12311, AAA, BBB, 2,
12322, AAA, BBB, 5,
*the commas is also not right
Use -s option of sqlplus to supress:
sqlplus -s user/pass#DB

Resources