ORA-12560: Tns Protocol Adapter Error + ORA-01034: ORACLE not available - oracle

I am trying to run a bat script which should perform the automatic deployment of a database, along with other structures, but I have several problems when I run the file.
I have installed Oracle 19, set my ORACLE_HOME to the folder path and also ORACLE_SID is set to "orcl". I have also started the OracleServiceORCL from services and when I run my bat script, I get more errors:
>>> STEP 0 => Running prerequisites with dba role user <<<
_____________________________________________________________
BEGIN dbms_output.put_line('Connected user is '||USER); END;
*
ERROR at line 1:
ORA-01034: ORACLE not available
Process ID: 0
Session ID: 0 Serial number: 0
The file looks like this:
SET serveroutput on
SET pagesize 5000
SET long 5000
SET pages 500
SET linesize 300
SET echo on
SET serveroutput on
WHENEVER SQLERROR EXIT
prompt ##########################################
prompt ###### Start deploying SABD project ######
prompt ##########################################
prompt
-- Setting deploy variables
define srcDB_path='C:\Users\mihaelad\WSOP\main\main\src\database'
define adminSABD='SABDADM'
define userSABD='SABDUSER'
define passAdmSABD='SABDADM'
define passUserSABD='SABDUSER'
prompt _____________________________________________________________
prompt >>> STEP 0 => Running prerequisites with dba role user <<<
prompt _____________________________________________________________
SET feedback off
EXECUTE dbms_output.put_line('Connected user is '||USER);
--SET feedback on
#runWithDba.sql
prompt
prompt
SET feedback off;
EXECUTE dbms_lock.sleep(2);
SET feedback on;
connect &&adminSABD/&&passAdmSABD
SET serveroutput on
prompt ______________________________________________
prompt >>> STEP 1 => Creating SABDADM objects <<<
prompt ______________________________________________
SET feedback off
EXECUTE dbms_output.put_line('Connected user is '||USER);
SET feedback on
#sabdadm/master.sql
connect &&userSABD/&&passUserSABD
SET serveroutput on
prompt ______________________________________________
prompt >>> STEP 2 => Creating SABDUSER objects <<<
prompt ______________________________________________
SET feedback off
EXECUTE dbms_output.put_line('Connected user is '||USER);
SET feedback on
#sabduser/master.sql
exit
and also the error regarding TNS: ORA-12560. I will also provide my listener.ora:
# This is a sample listener.ora that contains the NET8 parameters that are
# needed to connect to an HS Agent
LISTENER =
(ADDRESS_LIST=
(ADDRESS=(PROTOCOL=tcp)(HOST=0.0.0.0)(PORT=1521))
)
SID_LIST_LISTENER=
(SID_LIST=
(SID_DESC=
(SID_NAME=dg4odbc)
(ORACLE_HOME=C:\Users\mihaelad\Downloads\WINDOWS.X64_193000_db_home)
(PROGRAM=dg4odbc)
)
)
#CONNECT_TIMEOUT_LISTENER = 0
and also the tnsnames.ora:
# This is a sample tnsnames.ora that contains the NET8 parameters that are
# needed to connect to an HS Agent
dg4odbc =
(DESCRIPTION=
(ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT=1521))
(CONNECT_DATA=(SID=dg4odbc))
(HS=OK)
)
I also tried to set ORACLE_SID with "dg4odbc", as mentioned in the tnsnames, but same errors appeared.
Does anyone know what I am doing wrong?

Related

Oracle RDS Logminer ORA-01291 Missing Log File?

I have an Oracle RDS database I manage, and I need to be able to pull changes from the database for replication to another system. Once connect to the database, below is the commands I run.
EXEC rdsadmin.rdsadmin_util.create_directory(p_directory_name => 'logminerlogs');
set heading off;
set echo off;
set space 0;
set pagesize 0;
set linesize 10000;
set termout off;
set trimout on;
SET TRIMSPOOL ON;
set feedback off;
set newpage NONE;
set define on;
exec dbms_stats.gather_dictionary_stats;
EXEC rdsadmin.rdsadmin_util.alter_supplemental_logging('ADD','PRIMARY KEY');
EXEC rdsadmin.rdsadmin_util.alter_supplemental_logging('ADD','UNIQUE');
BEGIN
dbms_logmnr.add_logfile(
logfilename=> 'rdsdbdata/db/ORCL_A/arch?redolog-99999-9-9999999999.arc');
*** REPEAT for all redo logs ***
END
/
EXECUTE dbms_logmnr.start_logmnr(STARTTIME=>SYSDATE-1,ENDDATE=>SYSDATE,OPTIONS=>DBMS_LOGMNR.DICT_FROM_REDO_LOGS+DBMS_LOGMNR.COMMITTED_DATA_ONLY+DBMS_LOGMNR.PRINT_PRETTY_SQL);
Doing all of that gives me the error
ORA-01291: missing log file
ORA-06512: at "SYS.DBMS_LOGMNR", line 72
ORA-06512: at line 1
I get all of the 'arc' files by querying
SELECT name FROM v$archived_log WHERE first_time > SYSDATE-1 and first_time < systdate ORDER BY 1;
I ran all of these scripts once and I was able to query v$logmnr_contents and get the results I wanted. When I opened another SQLPlus window and ran all of the scripts again, I get the error of Missing Log File mentioned above.
I'm not exactly sure what I am doing wrong here. I have also tried
DBMS_LOGMNR_D.BUILD(dictionary_filename=>'lgmnrdict.ora',dictionary_location=>'LOGMNRLOGS');
where LOGMNRLOGS is a dictionary folder I created previously, and then instead of the redologs when calling add_logfile I point to the 4 onlinelogs .log files that exist on the database and then run command
EXECUTE DBMS_LOGMNR.START_LOGMNR(dictfilename=>'/rdsdbdata/userdirs/o1/logmnrdict.ora');
This will start Logminer, but when I make any changes and commit to the database, when I query v$logmnr_contents those changes are not being returned.
I realize I might be rambling at this point, but I feel like I am very close to the solution; I'm just missing something. Any help is appreciated.
The problem was that for each add_logfile command, I was setting options for dbms_logmnr.new for each rather than for the first and all remaining redologs using dbms_logmnr.addfile.

Error trying to start Oracle 12c on Solaris 11

After the installation of Oracle 12c under Solaris 11 .. Im running SQLPlus and after typing startup i get this error :
SQL> startup
ORA-01078: failure in processing system parameters
LRM-00109: could not open parameter file '/u01/app/oracle/product/12.1.0.2/db_1/dbs/initDB12C.ora'
Any ideas guys ? i've tried everything i found on the net
.profile File
ORACLE_HOSTNAME=solaris; export ORACLE_HOSTNAME
ORACLE_BASE=/u01/app/oracle; export ORACLE_BASE
ORACLE_HOME=$ORACLE_BASE/product/12.1.0.2/db_1; export ORACLE_HOME
ORACLE_SID=DB12C; export ORACLE_SID
LD_LIBRARY_PATH=$ORACLE_HOME/lib:$CRS_HOME/lib
PATH=$ORACLE_HOME/bin:$PATH; export PATH
init.ora File :
# Change '<ORACLE_BASE>' to point to the oracle base (the one you specify at
# install time)
db_name='ORCL'
memory_target=1G
processes = 150
audit_file_dest='<ORACLE_BASE>/admin/orcl/adump'
audit_trail ='db'
db_block_size=8192
db_domain=''
db_recovery_file_dest='<ORACLE_BASE>/fast_recovery_area'
db_recovery_file_dest_size=2G
diagnostic_dest='<ORACLE_BASE>'
dispatchers='(PROTOCOL=TCP) (SERVICE=ORCLXDB)'
open_cursors=300
remote_login_passwordfile='EXCLUSIVE'
undo_tablespace='UNDOTBS1'
# You may want to ensure that control files are created on separate physical
# devices
control_files = (ora_control1, ora_control2)
compatible ='11.2.0'

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

SQLPLUS connection to different dbs

Hello i want to connect to following dbs in loop and execute statements on each:
conn support/support#sp0666to
conn support/support#sp0667to
conn support/support#sp0668to
Is there any way to do this in sqlplus?
Thank you for your answers in advance!
Create one script (doWork.sql) that contains the majority of what you want to do:
conn &1/&2#&3
select EMPLOYEE, AUTHORIZED, TIME, DAT, WORKSTATION
from EMPLOYEE
where status = 25;
In a separate script (goToWork.sql):
set lines 1500 pages 10000
set colsep ';'
set sqlprompt ''
set heading on
set headsep off
set newpage none column tm new_value file_time noprint
select to_char(sysdate, 'DDMMYYYY_HH24.MI') tm from dual;
accept user
accept pass
spool C:\Users\NANCHEV\Desktop\parked.csv
##doWork &user &pass sp0666to
##doWork &user &pass sp0667to
##doWork &user &pass sp0668to
spool off;
exit
If you want separate files, then move the two spool commands to the doWork.sql file.
Assuming you want to run the same set of queries for each database, I'd create a script file (e.g. main_statements.sql) containing those statements.
Then, if the list of databases was static, I'd create a second script file (e.g. run_me.sql) in the same directory, with contents along the lines of:
connect &&user/&&password#db1
##main_statements.sql
connect &&user/&&password#db2
##main_statements.sql
connect &&user/&&password#db3
##main_statements.sql
...
If, however, the databases are static but the list is contained in a database somewhere, then I'd write a script (e.g. run_me.sql) that generates a script, something like:
set echo off
set feedback off
set verify off
spool databases_to_run_through.sql
select 'connect '||username||'/'||password||'#'||database_name||chr(10)||
'##main_statements.sql'
from list_of_databases_to_query;
spool off;
##databases.run_through.sql
N.B. untested. Also, I have assumed that your table contains the usernames and passwords for each db that needs to be connected to; if that's not the case, you'll have to work out how to handle them; maybe they're all the same (in which case, you can hardcode them - or better yet, use substitution variables (e.g. &&username) to avoid having to store them in a plain file. You'd then have to enter them at runtime.
You'll also need to run the script from the same directory, otherwise you could end up with the generated script not being created in the same directory as your main_statements.sql equivalent script.
Yes it's possible, you can use oracle DBLink to connect to different dbs just like your example.

How to export half a million records from PL/SQL

I've a table with around 500,000 records. I need all records to be exported in excel. When I query I'm not able to get all as I was said as Out Of memory
Table doesn't have any primary key/Index.
Is there any way to extract?
it would be very easy in to write file output form sqlplus .
mycsv.sql:
SET DEFINE OFF
SET ECHO OFF
SET SERVEROUTPUT OFF
SET TERMOUT OFF
SET VERIFY OFF
SET FEEDBACK OFF
SET PAGESIZE 10000
SET ARRAYSIZE 5000
REM SET HEAD OFF
SET LINE 500
spool /tmp/mycsvfile.csv;
select * from MY_table;
spool off;
exit;
and from Linux prompt you can run like
$> sqlplus username/password #/tmp/mycsv.sql

Resources