DATABASE is mounted but 11g doesn't recognize that it's not - oracle

I'm trying to enable archivelog on a database with
ALTER DATABASE ARCHIVELOG;
And then get
ORA-01126: database must be mounted in this instance and not open in
any instance
So I ran
ALTER DATABASE MOUNT
and get
ORA-01100: database already mounted

After configuring archival destination shut down the database gracefully and mount it in order to enable the archive log mode.
SQL> shutdown immediate
SQL> Startup mount
SQL> alter database archivelog;
SQL> alter database open;

Related

How to clone a pluggable database in Oracle

I'm new to Oracle's pluggable databases (we still use Oracle 11.2 at work). For a test of partitions and subpartitions, I'll need to create a couple of dozen tablespaces. I thought, I'd quickly clone my current database, do the tests, and drop the database afterwards.
I was able to clone the database:
CREATE PLUGGABLE DATABASE ora193p2 FROM ora193p1
FILE_NAME_CONVERT = (
'/opt/oracle/oradata/ORA193C/ORA193P1/',
'/opt/oracle/oradata/ORA193C/ORA193P2/');
Pluggable database ORA193P2 created.
but got an error ORA-01109: database not open when trying to connect to it.
I've tried to open it, but get an error message, too (ora193c is the name of the cdb):
ALTER DATABASE ora193p2 OPEN;
ORA-01509: specified name 'ORA193P2' does not match actual 'ORA193C'
I used the database from vagrant-boxes.
For pluggable databases you need to add key word pluggable database followed by pdb name
SQL> create pluggable database pdbclone from orclpdb;
Pluggable database created.
SQL> show pdbs
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 ORCLPDB READ WRITE NO
4 PDBCLONE MOUNTED
SQL> alter pluggable database pdbclone open;
Pluggable database altered.
SQL> show pdbs
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 ORCLPDB READ WRITE NO
4 PDBCLONE READ WRITE NO
SQL> alter pluggable database pdbclone save state;
Pluggable database altered.
From 12.1.0.2 onward, you can preserve the PDB startup state through CDB restart. The 12.1.0.2 patchset introduced SAVE STATE and DISCARD STATE options:
ALTER PLUGGABLE DATABASE pdb_name OPEN;
ALTER PLUGGABLE DATABASE pdb_name SAVE STATE;
To discard the saved state:
ALTER PLUGGABLE DATABASE pdb_name DISCARD STATE;
For 12.1.0.1 and before, you could create an after startup trigger:
CREATE OR REPLACE TRIGGER open_pdbs
AFTER STARTUP ON DATABASE
BEGIN
EXECUTE IMMEDIATE 'ALTER PLUGGABLE DATABASE ALL OPEN';
END open_pdbs;
/
It creates a after startup system level trigger in CDB.
See Oracle 12c Post Installation Mandatory Steps

Oracle 10G copy schema using impdp, trigger owner and table owner are not the same

We have base schema HSE in oracle 10g XE database. For UAT and other purposes we create the duplicate of HSE in the same database with HSE_UAT (using expdp & impdp). All 60 triggers are imported without issues. But for 12 triggers OWNER is HSE_UAT but table owner is HSE. Then every time we are manually dropping the trigger in HSE and re-run the trigger in HSE_UAT with correct table owner.
Just curious to know why this is happening only for 12 triggers not for others...

How to start Oracle 12c database when table space file was accidentally deleted

I've accidentally deleted a tablespace file and now Oracle 12c will not open.
How can I remove this tablespace from oracle without the database being open?
If you have deleted the datafiles then you have to restore it from the physical backup if you don't want loose data.
Performing Complete Recovery of a Tablespace
The datafiles information is checked by Oracle during open database process. It means you can mount the database and make the datafile offline.
ALTER DATABASE DATAFILE 'path to datafile' OFFLINE;
ALTER DATABASE OPEN;
ALTER DATABASE DATAFILE '/u02/oracle/rbdb1/stuff01.dbf' OFFLINE;

ORA-03113 Error while opening the database

I am trying to restore a database. The job was hung do to some issue, so I have restarted the Oracle service (Windows). I'm now getting an error while connecting to DB:
ORA-03113 end-of-file on communication channel
Process ID :9716
Session ID: 237 serial number :5
How can I solve this error?
ORA-03113 is a generic error. Please read this excellent post here for some information as to the root cause analysis of this error.
As a workaround for your case, assuming you can afford to reset the logs, you can probably do an incomplete database recovery and then open the database with RESETLOGS option:
SQL> STARTUP MOUNT;
SQL> ALTER DATABASE RECOVER DATABASE UNTIL CANCEL;
SQL> ALTER DATABASE RECOVER CANCEL;
SQL> ALTER DATABASE OPEN RESETLOGS;
try this
SQL> STARTUP MOUNT;
SQL> ALTER DATABASE RECOVER DATABASE UNTIL CANCEL;
SQL> ALTER DATABASE OPEN RESETLOGS;
it helped to me.
SQL> STARTUP MOUNT;
SQL> ALTER DATABASE RECOVER DATABASE UNTIL CANCEL;
SQL> ALTER DATABASE OPEN RESETLOGS;

Why do I need a common account in Oracle?

Why do I need a common account in Oracle 12c? A common means a CDB account. When I create an account using enterprise manager express it's creating only common accounts. Could I create a non-common account there? A common user also appears in every container I ever switch/connect to. What's the purpose of this common account to access all those pluggable databases?
Why do I need a common account in Oracle 12c?
What's the purpose of this common account to access all those pluggable databases?
You need a common account(common user) to perform administrative operations on CDB(container database) such as changing the state of a pluggable database, plugging and unplugging pluggable databases (PDBs) and so forth, which local user cannot do. Well, in fact, a local user can change state of pluggable database as well, but only PDB it connected to as sysdba or sysoper.
Could I create a non-common account there(in CDB)?
No, non-common account(Local user) cannot be created in the root - can only be created and operate within a pluggable database(PDB) and wont have access(you cannot use it to log in to) CDB or other PDBs.
Find out more
about commonality and common and local users.
Edit
CDB$ROOT is root container. PDB$SEED is just a template needed to create a pluggable databases. You cannot create or modify objects in it. PDBORCL is a pluggable database, which you should use for your development.
Oracle will throw the ORA-01033 error if you are trying to connect to a closed PDB as non sysdba user. Usually, PDBs database are not open by default, just mounted (unless your have automated that process by creating a trigger, for example, that will do it for you upon starting up CDB) and you need to explicitly open it while connecting as a common user (SYS or other common user that has the privilege to startup/alter pluggable database) and issue:
SQL> alter pluggable database <<name_of_PDB>> open;
or
SQL> startup pluggable database <<name_of_PDB>>
After that you should be able to connect to your PDB as common or local user. Of course they have to have appropriate privileges(create session) to be able to do so.
Edit #2 Automating starting up of pluggable database(s) on startup of CDB using system event(after startup on database) trigger. Unfortunately there is no native way to startup PDs automatically.
SQL> conn / as sysdba
Connected.
SQL> show con_name
CON_NAME
------------------------------
CDB$ROOT
SQL> show pdbs
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 NKRASNOV READ WRITE NO
This specific trigger opens one pluggable database. If you have more than one PDs and want to open them all, the alter statement can be modified as follows ALTER PLUGGABLE DATABASE ALL OPEN;
SQL> create or replace trigger open_pdb
2 after startup on database
3 begin
4 execute immediate 'alter pluggable database nkrasnov open';
5 end;
6 /
Trigger created.
SQL> shutdown
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup
ORACLE instance started.
Database mounted.
Database opened.
SQL> show pdbs
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 NKRASNOV READ WRITE NO
SQL> conn hr/hr#nkrasnov_pdb
Connected.
SQL> spool off;

Resources