How to clone a pluggable database in Oracle - 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

Related

ORA-65096: invalid common user or role name

Hi I've tried to create a new user in Oracle 18c XE, but I get
ORA-65096: invalid common user or role name error when writing
create user student identified by "student";
I've tried to change the container to PDB by
SQL> alter session set container =PDB;
as I've understood that you should set that when trying to create a local user but I get the following error:
ORA-65011: Pluggable database PDB does not exist.
Do you have any idea how could I create a new user with all privileges from the command prompt?
A user cannot be created on a container for a DB with vers. 12c+.
So, need to alter as you did, but should display which pluggable databases are available :
SQL> select name, pdb from v$services order by pdb, name;
NAME PDB
----------------------------------------------- ----------
SYS$BACKGROUND CDB$ROOT
SYS$USERS CDB$ROOT
pdb1 PDB1
pdb2 PDB2
and check out the container by
SQL>show con_name
CON_NAME
——————————
CDB$ROOT
and check for the pluggable databases
SQL> select name,open_mode from v$pdbs;
NAME OPEN_MODE
------------------- ----------
PDB$SEED READ ONLY
PDB1 MOUNTED
PDB2 MOUNTED
change container to a pluggable database
SQL> alter session set container=pdb1;
Session altered.
and open it
SQL> alter pluggable database pdb1 open;
Now, you can apply
SQL> create user student identified by student;
as an example.
First run the following command:
SQL> alter session set "_ORACLE_SCRIPT"=true;
After that, create the user:
SQL> create user student identified by student;

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

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;

connecting to pluggable database using administrator user

I have a question about connecting to pluggable database using a user(scott/tiger).Lets say,I am connected as
sqlplus / as sysdba
Then I want to open my pluggable database:
alter pluggable database ORC open;
And then,I want to connect as user scott to my pluggable db (ORC) using this:
connect scott/tiger#ORC;
However,I got this error:
ORA-01031(INSUFFICIENT PRIVILEGES).
My question is should I have made scott as my administrator user while creating this pluggable db in order for scott to connect to this pdb?
Some help is appreciated.
Most probably user scott does not have CONNECT or CREATE SESSION privileges.
Regardless, you can effectively connect to a PDB from sqlplus by issuing
alter session set container = PDB_NAME;
Example:
$ sqlplus / as sysdba
SQL> select name, open_mode from v$containers;
NAME OPEN_MODE
------------------------------ ----------
CDB$ROOT READ WRITE
PDB$SEED READ ONLY
...........
TEST12C MOUNTED
TESTCAT READ WRITE
7 rows selected.
SQL> show con_name
CON_NAME
------------------------------
CDB$ROOT
SQL> alter session set container = TESTCAT;
Session altered.
SQL> show con_name
CON_NAME
------------------------------
TESTCAT
Also check the official documentation:
Administering a CDB with SQL*Plus
Viewing Information About CDBs and PDBs with SQL*Plus

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