Thursday, 16 February 2017

Startup and Shutdown Databases

Startup and Shutdown Container Databases (CDB) and Pluggable Databases (PDB) in Oracle Database 12c Release 1 (12.1)
The multitenant option introduced in Oracle Database 12c allows a single container database (CDB) to host multiple separate pluggable databases (PDB). This article demonstrates how to startup and shutdown container databases (CDB) and pluggable databases (PDB).
Container Database (CDB)
Startup and shutdown of the container database is the same as it has always been for regular instances. The SQL*Plus STARTUP and SHUTDOWN commands are available when connected to the CDB as a privileged user. Some typical values are shown below.
STARTUP [NOMOUNT | MOUNT | RESTRICT | UPGRADE | FORCE | READ ONLY]
SHUTDOWN [IMMEDIATE | ABORT]
Pluggable Database (PDB)
Pluggable databases can be started and stopped using SQL*Plus commands or the ALTER PLUGGABLE DATABASE command.
SQL*Plus Commands
STARTUP FORCE;
STARTUP OPEN READ WRITE [RESTRICT];
STARTUP OPEN READ ONLY [RESTRICT];
STARTUP UPGRADE;
SHUTDOWN [IMMEDIATE];

Some examples are shown below.
STARTUP FORCE;
SHUTDOWN IMMEDIATE;

STARTUP OPEN READ WRITE RESTRICT;
SHUTDOWN;

STARTUP;
SHUTDOWN IMMEDIATE;
ALTER PLUGGABLE DATABASE
The ALTER PLUGGABLE DATABASE command can be used from the CDB or the PDB.
The following commands are available to open and close the current PDB when connected to the PDB as a privileged user.
ALTER PLUGGABLE DATABASE OPEN READ WRITE [RESTRICTED] [FORCE];
ALTER PLUGGABLE DATABASE OPEN READ ONLY [RESTRICTED] [FORCE];
ALTER PLUGGABLE DATABASE OPEN UPGRADE [RESTRICTED];
ALTER PLUGGABLE DATABASE CLOSE [IMMEDIATE];
Some examples are shown below.
ALTER PLUGGABLE DATABASE OPEN READ ONLY FORCE;
ALTER PLUGGABLE DATABASE CLOSE IMMEDIATE;

ALTER PLUGGABLE DATABASE OPEN READ WRITE;
ALTER PLUGGABLE DATABASE CLOSE IMMEDIATE;

The following commands are available to open and close one or more PDBs when connected to the CDB as a privileged user.
ALTER PLUGGABLE DATABASE <pdb-name-clause> OPEN READ WRITE [RESTRICTED] [FORCE];
ALTER PLUGGABLE DATABASE <pdb-name-clause> OPEN READ ONLY [RESTRICTED] [FORCE];
ALTER PLUGGABLE DATABASE <pdb-name-clause> OPEN UPGRADE [RESTRICTED];
ALTER PLUGGABLE DATABASE <pdb-name-clause> CLOSE [IMMEDIATE];
The<pdb-name-clause> clause can be any of the following:
  • One or more PDB names, specified as a comma-separated list.
  • The ALL keyword to indicate all PDBs.
  • The ALL EXPECT keywords, followed by one or more PDB names in a comma-separate list, to indicate a subset of PDBs.
Some examples are shown below.
ALTER PLUGGABLE DATABASE pdb1, pdb2 OPEN READ ONLY FORCE;
ALTER PLUGGABLE DATABASE pdb1, pdb2 CLOSE IMMEDIATE;

ALTER PLUGGABLE DATABASE ALL OPEN;
ALTER PLUGGABLE DATABASE ALL CLOSE IMMEDIATE;

ALTER PLUGGABLE DATABASE ALL EXCEPT pdb1 OPEN;
ALTER PLUGGABLE DATABASE ALL EXCEPT pdb1 CLOSE IMMEDIATE;
Pluggable Database (PDB) Automatic Startup
The 12.1.0.2 patchset has introduced the ability to preserve the startup state of PDBs, so you probably shouldn't be implementing a trigger in the manner discussed in this section.
Prior to 12.1.0.2, when the CDB is started, all PDBs remain in mounted mode. There is no default mechanism to automatically start them when the CDB is started. The way to achieve this is to use a system trigger on the CDB to start some or all of the PDBs.
CREATE OR REPLACE TRIGGER open_pdbs
  AFTER STARTUP ON DATABASE
BEGIN
   EXECUTE IMMEDIATE 'ALTER PLUGGABLE DATABASE ALL OPEN';
END open_pdbs;/
You can customise the trigger if you don't want all of your PDBs to start.
Preserve PDB Startup State (12.1.0.2 onward)
The 12.1.0.2 patchset introduced the ability to preserve the startup state of PDBs through a CDB restart. This is done using the ALTER PLUGGABLE DATABASE command.
We will start off by looking at the normal result of a CDB restart. Notice the PDBs are in READ WRITE mode before the restart, but in MOUNTED mode after it.
SELECT name, open_mode FROM v$pdbs;
NAME                           OPEN_MODE
------------------------------ ----------
PDB$SEED                       READ ONLY
PDB1                           READ WRITE
PDB2                           READ WRITE
SQL>
SHUTDOWN IMMEDIATE;                   
STARTUP;

SELECT name, open_mode FROM v$pdbs;
NAME                           OPEN_MODE
------------------------------ ----------
PDB$SEED                       READ ONLY
PDB1                           MOUNTED
PDB2                           MOUNTED

SQL>
Next, we open both pluggable databases, but only save the state of PDB1.
ALTER PLUGGABLE DATABASE pdb1 OPEN;
ALTER PLUGGABLE DATABASE pdb2 OPEN;
ALTER PLUGGABLE DATABASE pdb1 SAVE STATE;
The DBA_PDB_SAVED_STATES view displays information about the saved state of containers.
COLUMN con_name FORMAT A20
COLUMN instance_name FORMAT A20

SELECT con_name, instance_name, state FROM dba_pdb_saved_states;

CON_NAME             INSTANCE_NAME        STATE
-------------------- -------------------- --------------
PDB1                 cdb1                 OPEN

SQL>




Restarting the CDB now gives us a different result.
SELECT name, open_mode FROM v$pdbs;

NAME                           OPEN_MODE
------------------------------ ----------
PDB$SEED                       READ ONLY
PDB1                           READ WRITE
PDB2                           READ WRITE

SQL>


SHUTDOWN IMMEDIATE;
STARTUP;


SELECT name, open_mode FROM v$pdbs;

NAME                           OPEN_MODE
------------------------------ ----------
PDB$SEED                       READ ONLY
PDB1                           READ WRITE
PDB2                           MOUNTED

SQL>




The saved state can be discarded using the following statement.
ALTER PLUGGABLE DATABASE pdb1 DISCARD STATE;

COLUMN con_name FORMAT A20
COLUMN instance_name FORMAT A20

SELECT con_name, instance_name, state FROM dba_pdb_saved_states;

no rows selected

SQL>
  • The state is only saved and visible in the DBA_PDB_SAVED_STATES view if the container is in READ ONLY or READ WRITE mode. The ALTER PLUGGABLE DATABASE... SAVE STATE command does not error when run against a container In MOUNTED mode, but nothing is recorded, as this is the default state after a CDB restart.
  • Like other examples of the ALTER PLUGGABLE DATABASE command, PDBs can be identified individually, as a comma separated list, using the ALL or ALL EXPECT keywords.
  • The INSTANCES clause can be added when used in RAC environments. The clause can identify instances individually, as a comma separated list, using the ALL or ALL EXPECT keywords. Regardless of the INSTANCES clause, the SAVE/DISCARD STATE commands only affect the current instance.

Identifying Host Names and IP Addresses

Identifying Host Names and IP Addresses
This article presents a mixed bag of Oracle functionality relating to the identification of host names and IP addresses for Oracle clients and servers.
UTL_INADDR
The UTL_INADDR package was introduced in Oracle 8.1.6 to provide a means of retrieving host names and IP addresses of remote hosts from PL/SQL.
The GET_HOST_ADDRESS function returns the IP address of the specified host name.
SQL> SELECT UTL_INADDR.get_host_address('bart') FROM dual;

UTL_INADDR.GET_HOST_ADDRESS('BART')
--------------------------------------------------------------------------------
192.168.2.4

SQL>
The IP address of the database server is returned if the specified host name is NULL or is omitted.
SQL> SELECT UTL_INADDR.get_host_address from dual;

GET_HOST_ADDRESS
--------------------------------------------------------------------------------
192.168.2.5

SQL>

An error is returned if the specified host name is not recognized.
SQL> SELECT * UTL_INADDR.get_host_address('banana') from dual;
SELECT * UTL_INADDR.get_host_address('banana') from dual
ERROR at line 1:
ORA-29257: host banana unknown
ORA-06512: at "SYS.UTL_INADDR", line 19
ORA-06512: at "SYS.UTL_INADDR", line 40
ORA-06512: at line 1
SQL>
The GET_HOST_ADDRESS function returns the host name of the specified IP address.
SQL> SELECT UTL_INADDR.get_host_name('192.168.2.4') FROM dual;

UTL_INADDR.GET_HOST_NAME('192.168.2.4')
--------------------------------------------------------------------------------
bart

SQL>
The host name of the database server is returned if the specified IP address is NULL or omitted.
SQL> SELECT UTL_INADDR.get_host_name FROM dual;
GET_HOST_NAME
--------------------------------------------------------------------------------
C4210gR2                                                                     
1 row selected.                                                            
SQL>

An error is returned if the specified IP address is not recognized.
SQL> SELECT * UTL_INADDR.get_host_name('1.1.1.1') FROM dual;
SELECT * UTL_INADDR.get_host_name('1.1.1.1') FROM dual;
ERROR at line 1:
ORA-29257: host 1.1.1.1 unknown
ORA-06512: at "SYS.UTL_INADDR", line 4
ORA-06512: at "SYS.UTL_INADDR", line 35
ORA-06512: at line 1
SQL>
SYS_CONTEXT
The SYS_CONTEXT function is able to return the following host and IP address information for the current session:
  • TERMINAL - An operating system identifier for the current session. This is often the client machine name.
  • HOST - The host name of the client machine.
  • IP_ADDRESS - The IP address of the client machine.
  • SERVER_HOST - The host name of the server running the database instance.
The following examples show the typical output for each variant.
SQL> SELECT SYS_CONTEXT('USERENV','TERMINAL') FROM dual;
SYS_CONTEXT('USERENV','TERMINAL')
--------------------------------------------------------------------
marge
1 row selected.
SQL> SELECT SYS_CONTEXT('USERENV','HOST') FROM dual;
SYS_CONTEXT('USERENV','HOST')
--------------------------------------------------------------------
marge
1 row selected.

SQL> SELECT SYS_CONTEXT('USERENV','IP_ADDRESS') FROM dual;

SYS_CONTEXT('USERENV','IP_ADDRESS')
--------------------------------------------------------------------
192.168.2.3
1 row selected.
SQL> SELECT SYS_CONTEXT('USERENV','SERVER_HOST') FROM dual;
SYS_CONTEXT('USERENV','SERVER_HOST')
--------------------------------------------------------------------
C4210gr2
1 row selected.
SQL>
V$INSTANCE
The HOST_NAME column of the V$INSTANCE view contains the host name of the server running the instance.
SQL> SELECT host_name FROM v$instance;

HOST_NAME
------------------------------------------------
C4210gR2

1 row selected.

SQL>



V$SESSION
The V$SESSION view contains the following host information for all database sessions:
  • TERMINAL -The operating system terminal name for the client. This is often set to the client machine name.
  • MACHINE -The operating system name for the client machine. This may include the domain name if present.
The following examples show the typical output for each column.
SQL> SELECT terminal, machine FROM v$session WHERE username = 'TIM_HALL';

TERMINAL                       MACHINE
------------------------------ ----------------------------------------------------
MARGE                          ORACLE-BASE\MARGE

1 row selected.                                                            

SQL>

Tuesday, 10 January 2017

Adding a Component in 11g or 12c

Create New Report Server in Oracle 12c and 11g
Oracle 12c Methods:
1.    Create a reports tools instance (Mandatory, if you are planning to use the same box for reports development)
2.    Create a reports server instance (OPTIONAL, only if you want to host a standalone reports instance)
3.    Goto‘C:\Oracle\Middleware\Oracle_Home\user_projects\domains\Classic_domain\bin>
startComponent<Report Server name>’
Start WLST(Weblogic Scripting Tool) console, and execute the below commands one after another (Make sure the node manager & the Weblogic admin server services are already started)
connect("weblogic","weblogic password", "hostname:7001")
my weblogic password :weblogic123
my hostname : localhost
createReportsToolsInstance(instanceName='reptools1', machine='AdminServerMachine')
createReportsServerInstance(instanceName='repserver', machine='AdminServerMachine')
exit()
Oracle 11g Methods:
For running reports, if you need to create a new standalone report server, you can do so by the following steps:
1.     Go to %ORACLE_INSTANCE%\bin ($ORACLE_INSTANCE/bin in Unix)
2.     Type in “opmnctl status” to see if opmn is running. If not, run “opmnctl startall”.
3.     Type in the following to create a new standalone reports server: 
opmnctl createcomponent -adminUsername weblogic -adminHost full_computer_hostname -adminPort 7001 -oracleHome C:\Oracle\Middleware\as_1 -oracleInstance C:\Oracle\Middleware\asinst_1 -instanceName asinst_1 -componentName name_of_report_server -componentType ReportsServerComponent
Example : opmnctl createcomponent –adminUsername weblogic –adminhost localhost –adminport 7001 –oracleHome C:\Oracle\Middleware\FRMHome_1 –oracleInstance  C:\Oracle\Middleware\asinst_1 –instanceName asinst_1 –componentName repserver –componentType ReportServerComponent
4.     Start the server “opmnctl startproc ias-component=name_of_report_server”

REP-51019: System user authentication is missing.

Error:
REP-51019: System user authentication is missing.
Solution:
First take a back/rename up of your rwserver.conf original file.

Some changes required in rwserver.conf
remove security tag from

<job jobType="report" engineId="rwEng" securityId="rwJaznSec"/>
to
<job jobType="report" engineId="rwEng"/>

And
Comment the line below from
<security id="rwJaznSec" class="oracle.reports.server.RWJAZNSecurity"/> to <!--security id="rwJaznSec" class="oracle.reports.server.RWJAZNSecurity"/-->

You will find the rwserver.conf file from the below path.

C:\Oracle\Middleware\Oracle_Home\user_projects\domains\Classic_domain\config\fmwconfig\components\ReportsServerComponent\Your_report_server_name\rwserver.conf

C:\Oracle\Middleware\Oracle_Home\user_projects\domains\Classic_domain\config\fmwconfig\servers\WLS_REPORTS\applications\reports_12.2.1\configuration\rwserver.conf

C:\Oracle\Middleware\Oracle_Home\user_projects\domains\Classic_domain\config\fmwconfig\components\ReportsToolsComponent\reptools1\rwserver.conf


1)    Make single signon yes
2)      Add the below <webcommandaccess>L2</webcommandaccess> 

Path may be different from machine to machine.

Check with your path.

Restart your Report Server….

Displaying Icon on Button in Oracle Forms 12c


Icons Buttons in 12c Fusion Middleware.
1. Start the following Services
     Start Weblogic Admin Server
     Start Weblogic Server WLS_FORMS
2. copy the icon folder in following path
    C:\Oracle\Middleware\<ORACLE_HOME>\forms\java

3. Switch to command Prompt
   cd C:\Oracle\Middleware\<ORACLE_HOME>\forms\java\icons
   now apply the following command
   C:\Oracle\Middleware\<ORACLE_HOME>\forms\java\icons>C:\Oracle\Middleware\<ORACLE_HOME>\oracle_common\jdk\bin\jar -cvf frmicons.jar *.gif


4.copy the icons.jar file into C:\Oracle\Middleware\<ORACLE_HOME>\forms\java

5. Edit/update formsweb.cfg file: (Don’t Forget to take back up File)
Path=C:\Oracle\Middleware\<ORACLE_HOME>\user_projects\domains\<my_domain>\config\fmwconfig\servers\WLS_FORMS\applications\formsapp_12.1.1\config\formsweb.cfg  …to update/include:
Forms applet parameter
codebase=/forms/java
# Forms applet parameter
imageBase=codebase
# Forms applet archive setting for other clients (Sun Java Plugin…etc)
archive=frmall.jar,frmicons.jar
# Forms applet archive setting for JInitiator
archive_jini=frmall_jinit.jar,frmicons.jar[/text]

6. Edit/update Registry.dat file: (Don’t Forget to take back up File)
Path=C:\Oracle\Middleware\<ORACLE_HOME>\user_projects\domains\<my_domain>\config\fmwconfig\servers\WLS_FORMS\applications\formsapp_12.1.1\config\forms\registry\oracle\forms\registry\Registry.dat
[text]default.icons.iconpath=icons/
default.icons.iconextension=gif[/text]

7. At the end of CLASSPATH in DEFAULT.env add the following value
  ;C:\Oracle\Middleware\<ORACLE_HOME>\forms\java\icons.jar
8. a block message appear from java, press do not block
9. now run your forms.

The path and drive i used to this practical its created on my PC, but you must change the path and drive where you install the oracle forms.

Character Set Change


--------------Steps to change the database character set------------


To change the database character set, perform the following steps:

1. Shut down the database, using either a SHUTDOWN IMMEDIATE or a SHUTDOWN NORMAL statement.

2. Do a full backup of the database because the ALTER DATABASE CHARACTER SET statement cannot be rolled back.

3. Startup Oracle database

SQL> startup mount;
SQL> ALTER SYSTEM ENABLE RESTRICTED SESSION;
SQL> ALTER SYSTEM SET JOB_QUEUE_PROCESSES=0;
SQL> ALTER SYSTEM SET AQ_TM_PROCESSES=0;
SQL> ALTER DATABASE OPEN;
SQL> ALTER DATABASE CHARACTER SET AL32UTF8;
If you get the error ORA-12712, please update the following table.

"ORA-12712: new character set must be a superset of old character set"

SQL> update sys.props$ set VALUE$='AL32UTF8' where NAME='NLS_CHARACTERSET';
SQL> commit;
If you get the error ORA-12721, please login as DBA user.

"ORA-12721: operation cannot execute when other sessions are active"

4. shutdown immediate; or shutdown normal;

5. startup oracle database

SQL> startup mount;
SQL> ALTER SYSTEM ENABLE RESTRICTED SESSION;
SQL> ALTER SYSTEM SET JOB_QUEUE_PROCESSES=0;
SQL> ALTER SYSTEM SET AQ_TM_PROCESSES=0;
SQL> ALTER DATABASE OPEN;
SQL> ALTER DATABASE CHARACTER SET AL32UTF8;
select open_mode from v$database;
SQL> shutdown immediate;
SQL> startup;

--------------------Check the NLS parameters--------------------------

SQL> SELECT PARAMETER, VALUE FROM NLS_DATABASE_PARAMETERS WHERE PARAMETER IN ('NLS_CHARACTERSET', 'NLS_NCHAR_CHARACTERSET');