How to connect Oracle 19c Database - oracle

I am trying to connect to pluggable databases previously created and could not do it.
Option 1
SQL> conn /as sysdba;
Connected.
SQL> conn system/system
ERROR:
ORA-01033: ORACLE initialization or shutdown in progress
Process ID: 0
Session ID: 0 Serial number: 0
Warning: You are no longer connected to ORACLE.
SQL>
Warning: You are no longer connected to ORACLE.
/
Option 2
SQL> show pdbs;
SQL> conn / as sysdba;
Connected.
SQL> show pdbs;
SQL> alter pluggable database orclpdb open;
alter pluggable database open
*
ERROR at line 1:
ORA-01109: database not open
Previously I had connected using sql developer and worked.
Updated
My database is not mounted and I tried to mount it and shows the below error details.
SQL> conn / as sysdba;
Connected.
SQL> show con_name;
CON_NAME
------------------------------
CDB$ROOT
SQL> select open_mode from v$database;
select open_mode from v$database
*
ERROR at line 1:
ORA-01507: database not mounted
SQL> alter database mount;
alter database mount
*
ERROR at line 1:
ORA-00214: control file
'E:\APP\ORACLE\FAST_RECOVERY_AREA\PROD\CONTROLFILE\O1_MF_JCWYX5LY_.CTL' version
102600 inconsistent with file
'E:\APP\ORACLE\ORADATA\PROD\CONTROLFILE\O1_MF_JCWYX5BQ_.CTL' version 102597
SQL> show parameter control
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
control_file_record_keep_time integer 7
control_files string E:\APP\ORACLE\ORADATA\PROD\CON
TROLFILE\O1_MF_JCWYX5BQ_.CTL,
E:\APP\ORACLE\FAST_RECOVERY_AR
EA\PROD\CONTROLFILE\O1_MF_JCWY
X5LY_.CTL
control_management_pack_access string DIAGNOSTIC+TUNING

This is because the CDB is at MOUNT, not OPEN, you should open the root container before using PDB.
SQL> conn / as sysdba
Connected.
SQL> show con_name
CON_NAME
------------------------------
CDB$ROOT
SQL> select open_mode from v$database;
OPEN_MODE
--------------------
MOUNTED
To open the CDB, you may issue the following SQL command or bounce it.
SQL> alter database open;
Database altered.
Then show pdbs again.
SQL> show pdbs;
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 ORCLPDB READ WRITE NO
If the PDB is still MOUNTED, then you should open it.
SQL> alter pluggable database orclpdb open;
Pluggable database altered.

Related

How do I truncate the Oracle audit table in AWS RDS?

How do I truncate the Oracle audit table in Amazon AWS RDS?
SQL> select count(*) from sys.aud$;
COUNT(*)
----------
1358
SQL> truncate table sys.aud$;
truncate table sys.aud$
*
ERROR at line 1:
ORA-01031: insufficient privileges
Connect as the admin user and run this rdsadmin command:
SQL> exec rdsadmin.rdsadmin_master_util.truncate_sys_aud_table;
PL/SQL procedure successfully completed.
SQL> select count(*) from sys.aud$;
COUNT(*)
----------
0

Pluggable database not showing the users tablespace

I have oracle 19c multitenant and asm installed.
When I create a container and a pluggable database
by graphic view I can see the users tablespace from the database.
sqlplus / as sysdba
SQL> alter session set container=PDBORCL;
SQL> select tablespace_name from dba_tablespaces;
TABLESPACE_NAME
------------------------------
SYSTEM
SYSAUX
UNDOTBS1
TEMP
USERS
But if I create a container and plugable database in silent mode,
I can only see the users tablespace from the container and if I enter the pluggable database, I can't see the users tablespace.
sqlplus / as sysdba
SQL> alter session set container=TESTPDB;
SQL> select tablespace_name from dba_tablespaces;
TABLESPACE_NAME
------------------------------
SYSTEM
SYSAUX
UNDOTBS1
TEMP
I used these commands to create the container and the database
dbca -silent -createDatabase -databaseConfigType SINGLE -databaseType MULTIPURPOSE \
-templateName General_Purpose.dbc -gdbName TEST -sid TEST -createAsContainerDatabase true \
-useLocalUndoForPDBs true -storageType ASM -datafileDestination +DTA01 -recoveryAreaDestination +FRA01 \
-useOMF true -recoveryAreaSize 9000 -memoryMgmtType AUTO_SGA -totalMemory 4000 \
-characterSet AL32UTF8 -nationalCharacterSet AL16UTF16 -emConfiguration NONE -systemPassword Redhat123 \
-sysPassword Redhat123 -redoLogFileSize 200
sqlplus / as sysdba
CREATE PLUGGABLE DATABASE TESTPDB ADMIN USER usradminapp IDENTIFIED BY Redhat123 FILE_NAME_CONVERT = ('+DTA01', '+DTA01 ')

Accessing a function against another owner in oracle?

I am having a function called fn_export and its owner is bhist. I am calling this function from ohist user using bhist.fn_export. While calling like this I am facing the below issue.
ORA-00942: table or view does not exist
ORA-06512: at "bhist.fn_export", line 442
ORA-06512: at line 20
I tried to verify all the tables in that function and I am able to access all those tables from ohist. I have execute grant on bhist.fn_export to ohist. Still I am having this issue. Can any one of you please help in resolving this issue?
Thanks,
Venkat
You need to grant EXECUTE privilege on this function to ohist user.
A syntax is:
GRANT EXECUTE ON function_name TO username;
You can connect as bhist user and grant the privilege using:
GRANT EXECUTE ON fn_export TO ohist;
You can also connect as SYS or SYSTEM, and use this command:
GRANT EXECUTE ON bhist.fn_export TO ohist;
See a below simple example (one user is named TEST and the other is named DEV):
SQL> connect test
Enter password:
Connected.
SQL> CREATE FUNCTION fn_export RETURN number AS
2 BEGIN
3 RETURN 20;
4 END;
5 /
Function created.
SQL> connect dev
Enter password:
Connected.
SQL> SELECT test.fn_export FROM dual;
SELECT test.fn_export FROM dual
*
ERROR at line 1:
ORA-00904: "TEST"."FN_EXPORT": invalid identifier
SQL> connect test
Enter password:
Connected.
SQL> grant execute on fn_export to dev;
Grant succeeded.
SQL> connect dev
Enter password:
Connected.
SQL> SELECT test.fn_export FROM dual;
FN_EXPORT
----------
20
SQL>

Using dollar sign in sqlplus spool file

How to use file name with dollar sign (ie, '$') in unix like below
SQL> spool DIR$work.sql
SP2-0332: Cannot create spool file.
and i tried like below
SQL> spool DIR\$work.sql
SP2-0332: Cannot create spool file.
SQL> spool 'DIR\$work.sql'
SP2-0332: Cannot create spool file.
SQL> spool 'DIR$work.sql'
SP2-0332: Cannot create spool file.
I couldn't succeed in any way to create such file in oracle.
I have oracle 11g version.
In windows sqlplus it works fine.
You can use the set escchar setting to stop Oracle interpreting the dollar sign:
SQL> show escchar
escchar OFF
SQL> spool /tmp/$work.sql
SP2-0332: Cannot create spool file.
SQL> set escchar $
SQL> spool /tmp/$work.sql
SQL>
You are now spooling to that file name.
SQL> select * from dual;
D
-
X
1 row selected.
SQL> spool off
SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
...
$ cat /tmp/\$work.sql
SQL> select * from dual;
D
-
X
1 row selected.
SQL> spool off
Also see My Oracle Support document 761384.1 for more information.

Oracle DB won't allow users to query tables

I am on Windows XP running Oracle 10G XE Edition.
After running a defrag & cleanup process, I have not been able to access any of the objects on the database.
A quick check
set lines110
col strtd hea 'STARTED'
col instance_name for a8 hea 'INSTANCE'
col host_name for a15 hea 'HOSTNAME'
col version for a10
select instance_name, version, host_name, status
, database_status, to_char(startup_time,'DD-MON-YYYY HH:MI:SS') strtd
from v$instance;
returns this
INSTANCE VERSION HOSTNAME STATUS DATABASE_STATUS STARTED
-------- ---------- --------------- ------------ ----------------- ----------------------------------------------------
xe 10.2.0.1.0 DT8775C MOUNTED ACTIVE 03-DEC-2010 11:38:00
If I use this command, it throws the following error.
SQL> ALTER DATABASE OPEN;
ALTER DATABASE OPEN
*
*ERROR at line 1:*
ORA-16014: log 2 sequence# 679 not archived, no available destinations
ORA-00312: online log 2 thread 1:
'D:\ORACLEEXE\APP\ORACLE\FLASH_RECOVERY_AREA\XE\ONLINELOG\O1_MF_2_4JD5RZC0_.LOG'
How can I fix this situation?
There are zero files in the
"D:\ORACLEEXE\APP\ORACLE\FLASH_RECOVERY_AREA\XE\ONLINELOG\" folder.
I'm pretty sure this belongs on SERVERFAULT, but to get you going for now:
It appears the database is in ARCHIVELOG mode and you have not supplied a location to store the archived log files. A quick fix, assuming you don't need the recovery protection that archive logging gives you is to try this:
sqlplus / as sysdba
SQL> shutdown immediate;
SQL> startup mount;
SQL> ALTER DATABASE NOARCHIVELOG;
SQL> ALTER DATABASE OPEN;
If you do want to keep your archived redo logs, then you'll need entries like this in your database parameters:
alter system set log_archive_dest_1='location=d:\oraclexe\app\oracle\...';
alter system set log_archive_dest_state_1=enable;
Sounds like in your cleanup process you may have deleted the .LOG files. I assume you've emptied the trash and can't restore them?

Resources