Tuesday 3 July 2018

Interview Q and A for Oracle Remain Topic Part - 3

ORACLE SQL*NET/NETWORKING

139.  WHAT IS SQL*NET?
SQL*NET is an Oracle remote data access software which is used for client/server and server/server communications across networks. It is a networking software which enables communication between the client and the server (where the Oracle database resides). When a client or a server machine makes a request to the Oracle database, SQL*NET captures the request and passes the request to its underlying layer TNS, the Transparent Network Substrate. TNS transmits the request to the appropriate server using an appropriate communications protocol.

140. Is SQL*Net V2 compatible with SQL*Net V1?
No. SQL*Net V2 and SQL*Net V1 are not compatible on the line. A SQL*Net V1 client or server cannot talk to a SQL*Net V2 client or server across different SQL*Net versions. When I say "on the line" I am referring to the data packets that get sent between client and server.

141. Is SQL*Net V2 compatible with Net8?
Yes. A SQL*Net V2 client can talk to a Net8 listener and a Net8 client can talk to a SQL*Net V2 Listener.

142. SQL*Net is Network Transparent. What does this mean?
Oracle applications developed with a local database can be distributed across a network to access the same, or a similarly formatted, Oracle database with no changes to the application. SQL*Net is responsible for forwarding application requests
for data from an Oracle client or server to a server and returning the results to the initiator of the query. From the application developer's or application user's perspective, all data interaction using SQL*Net is invisible to the user or the application. Additionally, it is possible to change the network structure beneath the application without changing the application. This quality of being invisible is known as network transparency.

143. Is SQL*Net protocol dependent?
No. SQL*Net provides protocol independence to its applications. An application using SQL*Net can run over any network protocol. Any application built on any computer running any protocol can be distributed without change to other computers running other
protocols.
Oracle's client-server and server-server models provide the capability for connectivity across multiple network protocols, each in a manner appropriate to its function.

144. Is SQL*Net media or topology dependent?
No. When SQL*Net passes control of a connection to the underlying protocol, all media and/or topologies supported by that network protocol on that platform are indirectly inherited by SQL*Net. SQL*Net allows the network protocol to use any means of data
transmission, such as Ethernet, Token Ring, FDDI, or SDLC, to accomplish the low-level data link transmission between the two computers.

145. What is TNS?
Transparent Network Substrate . Forming the basis for Oracle networking products, the Transparent Network Substrate (TNS) enables Oracle to provide a network of applications above all existing networks of computers. With TNS, peer-to-peer application
connectivity is possible where no direct machine-level connectivity exists.

146. What does the listener.ora file look like?
SAMPLE LISTENER.ORA FILE FOR UNIX
=================================
The LISTENER.ORA file is only used by the SQL*Net listener to determine the configuration of the listeners run on the machine. LSNRCTL and TNSLSNR reference the file for startup, configuration and shutdown of the listeners defined in this file.
The LISTENER.ORA file is only needed on the server itself. The file is machine-specific so it should not be "copied" from one machine to another.
Only the Network Manager program should generate this file once a configuration change has been made to the listener(s) on that server.
###########
# FILENAME: LISTENER.ORA
# TIME....: 94-08-04 10:26:27
# NETWORK.: SAMPLE
# NODE....: SERVER
# SERVICE.: LISTENER
###########
LISTENER =
(ADDRESS_LIST =
(ADDRESS=
(PROTOCOL=IPC)
(KEY= <service name>)
)
(ADDRESS=
(PROTOCOL=IPC)
(KEY= <SID>)
)
(ADDRESS =
(PROTOCOL = TCP)
(HOST = <Server>)
(PORT = 1521)
)
)
STARTUP_WAIT_TIME_LISTENER = 0
CONNECT_TIMEOUT_LISTENER = 10
LOG_DIRECTORY_LISTENER = <$Oracle_Home>/network/log

LOG_FILE_LISTENER = listener
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = <SID>)
(ORACLE_HOME = <$Oracle_Home>)
)
)
TRACE_LEVEL_LISTENER = OFF
Note: some UNIX platforms do not support the IPC protocol.
-
For SQL*Net v2.1, there are a few additional parameters.
LISTENER.ORA Control Parameters
The third section of the LISTENER.ORA file contains a list of parameters that control the behavior of the listener. The parameters and their defaults (if any) follow:
PASSWORDS_listener_name=(password[,...password])
This optional parameter allows one or more passwords. If this parameter is specified with one or more passwords, then the use of
one of these passwords is required to perform certain DBA tasks against the listener using the Listener Control Utility. If this
parameter is not included in the file, then anyone can access the Listener Control Utility to stop or alter the listener.
You may choose to have the Network Manager encrypt the password in this file. If you choose to have the password encrypted, unauthorized people cannot see it in the LISTENER.ORA file and use it to manipulate the listener. However, if you want the password to be encrypted, you can enter only one password. The default is to encrypt the password.
If you do not care about encryption, you can enter more than one password. If more than one password is entered, all of them must be surrounded by parentheses. For example:
PASSWORDS_LISTENER=(super32, sly51)
The Network Manager creates the parentheses automatically.
STARTUP_WAIT_TIME_listener_name=number
This parameter sets the number of seconds that the listener sleeps before responding to the first listener control status command. This feature assures that a listener with a slow protocol will have had time to start up before responding to a status request. Default is 0.
For example, in the case of SPX, if you use the Listener Control Utility to request a STATUS immediately after the START command, and if this parameter is set to 0, you will get an error stack indicating that the listener is not available. If this parameter is set to 2, however, the Listener Control Utility will wait briefly, and the STATUS command will return a message showing that the listener is available and listening.
CONNECT_TIMEOUT_listener_name=number
This parameter sets the number of seconds that the listener waits to get a valid SQL*Net V2 connection request (at to the port it
redirected the client to) after a connection has been started (client has contacted the listener asking for a database connection). The
listener drops the connection if the timeout is reached. Default is 10; if set to 0, it will wait forever.
TRACE_LEVEL_listener_name=OFF|USER|ADMIN
This parameter indicates the level of detail the trace facility records for listener events. Choices are OFF, USER,or ADMIN. Default
is OFF. Selecting USER provides a limited level of tracing; ADMIN provides a more detailed trace.
TRACE_DIRECTORY_listener_name=path_to_trace_directory
This parameter sets the directory where the trace file is placed. Default is operating system specific. On UNIX, for example, it is
$ORACLE_HOME/network/trace.
TRACE_FILE_listener_name=trace_filename
This parameter establishes the name of the file to which trace information is written. Default is listener_name.trc on most platforms.
LOG_DIRECTORY_listener_name=path_to_log_directory
This parameter indicates the directory in which to find the log file that is automatically generated for listener events. Default is
operating system specific. On UNIX, for example, it is $ORACLE_HOME/network/log.
LOG_FILE_listener_name=log_filename
This parameter sets the name of the log file for the listener. Default is listener_name.log on most platforms.

Linguistic Sorting

147. Why is a sort order different on one client than on another?
This depends on the setting of NLS_SORT parameter. If this parameter is not set then it's derived from the session NLS_LANGUAGE:
NLS_LANGUAGE = PORTUGUESE
or
NLS_LANG = PORTUGUESE_BRAZIL.WE8MSWIN1252
All known sorts in a certain version of Oracle can be found in
select unique VALUE from V$NLS_VALID_VALUES where PARAMETER ='SORT';
The used NLS_SORT is client depending, the value seen in NLS_SESSION_PARAMETERS will be used for a certain session, not the one specified in the init.ora.
For more info on how and where to set the NLS_SORT parameter please see: Note 241047.1 The Priority of NLS Parameters Explained.
Note that the Sessions NLS_SORT value is always used for "ORDER BY" clauses, even if the NLS_COMP is set to BINARY.
Other SQL Functions that are always affected by NLS_SORT are NLS_INITCAP, NLS_LOWER, NLS_UPPER, NLSSORT, REGEXP_INSTR, REGEXP_LIKE, REGEXP_REPLACE, REGEXP_SUBSTR.
Note 13882.1 Linguistic Sorting of Data in Oracle7 and Oracle8

148. Why are strings like a-a ab- and a-c so strange sorted or "punctuation" characters ( /.;,-_ etc) sometimes ignored ?
You can get another sort order behavior if needed by following: Note 109200.1 Linguistic Sort of Non-Letters : Usage of NLS_SORT=PUNCTUATION
Under multilingual case insensitive setting (= all %_M_CI or %_M_AI sorts), all punctuation characters are treated as ignorable characters, which means their existence is not important when doing string matching or sorting and the punctuation characters are being ignored for comparisons. This may lead to some correct, but surprising results:
SQL> alter session set nls_comp='LINGUISTIC';


SQL> alter session set nls_sort='GENERIC_M_CI';
Session altered.
SQL> select INSTR('.' , '@', 1, 1) from dual
2 /
INSTR('.','@',1,1)

1
SQL> -- result is 1 - correct but surprising
SQL> select * from test;
COL1
--
ab
a_b
_ab
!!ab
!!abc
SQL> select * from test where col1='ab';
COL1
--
ab
a_b
_ab
!!ab
SQL> select * from test where col1='a_b';
COL1
--
ab
a_b
_ab
!!ab
SQL> -- here is clearly seen then _ and ! characters are simply ignored.
This is true for all %_M_AI or %_M_CI sorts. A list of the punctuation characters is found in the sort definition , you can see this using Locale builder ( see Note 227339.1) File - open - by object name - choose for example generic_m and then open the "punctuation characters" tab.
This is a partial list of those punctuation characters (the most commonly seen )
"US7ASCII range" punctuation characters are: <space> !"#%&'()*+,-./:;<=>?@[\]^_`{|}~
For other Character sets one can use Locale builder to see the punctuation characters defined for that character set. Note:223706.1 Using Locale Builder to view the definition of character sets
To ensure the NLS_SORT is always binary one can do for example something like this in an own function:
create or replace function instr_bin ( p_str varchar2,p_substr varchar2, p_pos number default 1, p_occ number default 1) return number is
v_nls_sort varchar2(40);
v_instr number;
begin
select value into v_nls_sort from nls_session_parameters where parameter = 'NLS_SORT';
execute immediate ('alter session set NLS_SORT=BINARY');
v_instr := instr(p_str,p_substr,p_pos,p_occ);
execute immediate ('alter session set NLS_SORT='||v_nls_sort||' ');
return v_instr;
end;
/
When using _M sorts (and not _M_CI or _M_CI) then you might also encounter bug 5262526 , see point 10) for more info about bug 5262526

149. What SQL operations are influenced by NLS_SORT and NLS_COMP?
When NLS_COMP is set to BINARY the NLS_SORT parameter is basically ignored and a BINARY sorting will be used for comparison operators (!).
Note that if NLS_SORT is not BINARY and NLS_COMP is set to BINARY the NLS_SORT value is still used for ORDER BY clauses (and more , see point 1).
Sorting a result set with a non-binary NLS_SORT will always be slower then when using NLS_SORT=BINARY.
By setting NLS_COMP to ANSI or LINGUISTIC, you indicate that queries (both select *and* insert/update) should use the linguistic sort specified in the NLS_SORT parameter for comparison operators.
When NLS_COMP is set to ANSI the non binary NLS_SORT setting affect the follow seven SQL comparison operators only:
WHERE ( = , > , < etc.) , START WITH , IN/OUT , BETWEEN , CASE WHEN , HAVING and (also) ORDER BY.
The new 10.2 NLS_COMP setting LINGUISTIC extends the range of affected SQL operations, for example it will then also affect the LIKE operator.
A complete overview of what is affected by setting NLS_COMP to BINARY, ANSI or LINGUISTIC
can be found in Oracle􀳦 Database Globalization Support Guide 11g Release 1 (11.1)
Chapter 5 Linguistic Sorting and String Searching -> "Performing Linguistic Comparisons"
http://download.oracle.com/docs/cd/B28359_01/server.111/b28298/ch5lingsort.htm#CIHBFIID
In 8i and 9i NLS_COMP *cannot* be set as environment variable (unlike documented in the manual). All Oracle8i and Oracle9 versions use NLS_COMP from INIT.ORA or from explicit ALTER SESSION.
Bug 2155062 NLS_COMP cannot be set in the client ENVIRONMENT
From 10g onward you can set NLS_COMP as client variable, NLS_COMP will then also default to BINARY (when NLS_LANG is used - which is recommended) in the session parameters if not set explicitly as client variable and will NOT be derived from a other NLS_PARAMETER.
The value in the init.ora is also not used - unlike 9i/8i.
If you want to set NLS_COMP to LINGUISTIC for example you need to set it explicit at the client side or use a after logon trigger.
You can always "force" a WHERE clause to use a linguistic sort using the NLSSORT function (see question 4). See also point 10. Problems using LIKE and NLS_COMP=LINGUISTIC

150. Are indexes used with NLS_SORT set to anything else than BINARY?
No, standard Oracle indexes are built using binary sort mode. Therefore "normal" indexes are not always used when the used sorting is *not* BINARY. Note that when NLS_COMP is set to BINARY then the sorting of an "order by" clause is not BINARY but the session's NLS_SORT value.
To improve performance you can , when using linguistic sorting, build a function based index on the table using the NLSSORT (no "-" between NLS and SORT ) function:
CREATE INDEX nls_index ON my_table (NLSSORT(<column>, 'NLS_SORT = <your NLS_SORT>'));
Further examples on how to use this method can be found in: Note 109118.1 GENERIC_BASELETTER Linguistic Definition.
Note that:
* it is mandatory to have good statistics, use after the creation of the indexes dbms_stats with cascade =>TRUE, for example EXEC
dbms_stats.gather_schema_stats(’SCOTT’, cascade=>TRUE);
* using a Case insensitive (or any linguistic) index for the LIKE operator is a 11g new feature. There is however (internal) Bug 6495630 (fixed in R11.2) making the index usage failing in a lot of cases.
* "linguistic" indexes are in fact Function based indexes, you can find the used function for an index in DBA_IND_EXPRESSIONS
If you want to use the a linguistic sort functionality regardless of the session's sorting setting you can do that by explicit using the NLSSORT in the select.
The NLSSORT function gives you the 'sort' value for a string, for example you can :
SELECT NLSSORT('eric','NLS_SORT=german') FROM dual;
That means that even if NLS_SORT itself is left at BINARY we can construct a WHERE clause that uses the linguistic sort functionality in this way:
SELECT name FROM my_table WHERE NLSSORT(name,'NLS_SORT=german') > NLSSORT('eric','NLS_SORT=german');
This will return the rows that are greater than 'eric' using the GERMAN linguistic definition, even if NLS_SORT itself is still set to BINARY.
Note that because nlssort doesn't return a string but a sort value you have to use the function on both sides of the equation.
Same for an order by
SELECT name FROM my_table ORDER BY NLSSORT(name,'NLS_SORT=german');
If you get when creating a linguistic index ORA-01450: maximum key length (6398) exceeded be ware that the max length of NLSSORT result is
LENGTH(NLSSORT(x)) = MIN( 2000, LENGTH(x) * 8 + 10)
1. The logic is not related to database character set; the logic is applicable to WE8MSWIN1252 as well as AL32UTF8.
2. LENGTH in the logic is byte length not character length. If a column is defined as "char" such as varchar2(240 char), the "x" in the logic will be multiplied depending on the character set.

151. Why do Accent- and Case Insensitive (_AI and _CI) SORTs not appear in V$NLS_VALID_VALUES?
In Oracle10g you can append any valid SORT name with _AI or _CI so that it behaves in a accent- or case-insensitive way.
Append _CI to an Oracle sort name for a case-insensitive sort.
Append _AI to an Oracle sort name for an accent-insensitive and case-insensitive sort.
These values do not appear in the V$NLS_VALID_VALUES view because this view only shows the "base" SORT names that can be used.
The _CI and _AI settings are extensions to the existing sort names, which is why they are not listed in the valid values list. Listing them would just mean every value would appear 3 times: 1 time as the base, 1 time extended with _AI and 1 time extended with _CI.
For monolingual sorts, the CI/AI definition is derived using the Unicode case-folding table and the base letter definitions in the sort itself.
For multilingual sorts ("_M" sorts), the sorts are defined based on ISO14651 with the collation keys structured at 3 levels - primary, secondary, and tertiary.
The "_CI" variation of the sort simply ignores the tertiary-level collation key difference while the "_AI" variation ignores the second-level and tertiary-level collation key difference. You can see the collation key level definitions in locale builder.

152. Are there Asian Linguistic Sorts available?
With the introduction of Multilingual Linguistic sorts and the support for differentiating characters now in 3 distinct levels, complex Asian sorts have been added in Oracle9i
to cover the need of ordering Asian data in a way that users are custom to.
These sorts are all based on the GENERIC_M multilingual linguistic sort, so that the order of the Latin, Cyrillic, Greek characters and other European characters will also be sorted according to the ISO 14651 standard.
Here is a list of the Asian Multilingual Linguistic Sorts supported in Oracle9i:
JAPANESE_M Japanese sort supports SJIS character set order and EUC characters which are not included in SJIS
KOREAN_M Korean sort: Hangul characters are based on Unicode binary order. Hanja characters based on pronunciation order. All Hangul characters are before Hanja characters
THAI_M Thai sort supports swap characters for some vowels and consonants
SCHINESE_STROKE_M Simplified Chinese sort uses number of strokes as primary order and radical as secondary order
SCHINESE_PINYIN_M Simplified Chinese PinYin sorting order
TCHINESE_RADICAL_M Traditional Chinese sort based on radical as primary order and number of strokes order as secondary order
TCHINESE_STROKE_M Traditional Chinese sort uses number of strokes as primary order and radical as secondary order

153. Why is a Case Insensitive sort not working on a (N)CLob?
To use a Case Insensitive sort on a (n)Clob you need to use a to_char for the clob column
SQL> drop table scott.sortt;
Table dropped.
SQL> create table scott.sortt (col1 clob, col2 char(20));
Table created.
SQL> insert into scott.sortt values ('J','J');
1 row created.
SQL> insert into scott.sortt values ('j','j');
1 row created.
SQL> commit;
Commit complete.
SQL> alter session set NLS_SORT=BINARY_CI;
Session altered.
SQL> alter session set NLS_COMP=LINGUISTIC;
Session altered.
SQL> select col1 from scott.sortt where col1 like 'J%';
COL1
-
J
SQL> select col1 from scott.sortt where col2 like 'J%';
COL1
-
Jj
SQL> select col1 from scott.sortt where to_char(col1) like 'J%';
COL1
-
Jj

154. What is new in 11g Diagnosability?
Beginning with Release 11g, Oracle Database includes an advanced fault diagnosability infrastructure for collecting and managing diagnostic data. Diagnostic data includes the trace files, dumps, and core also present in previous releases, plus new types of diagnostic data that enable customers and Oracle Support to identify, investigate, track, and resolve problems quickly and effectively.

155. What is ADR?
The Automatic Diagnostic Repository (ADR) is a file-based repository for storing diagnostic data. Because this repository is stored outside the database, the diagnostic data is available even when the database As of Release 11g, the alert log, all trace and dump files, and other diagnostic data are also stored in the ADR.

156. What is an ADR HOME?
An ADR HOME is the root directory for all diagnostic data—traces, dumps, the alert log, and so on—for a particular instance of a particular Oracle product or component.
The location of an ADR home is given by the following path, which starts at the ADR base directory:
diag/product_type/product_id/instance_id
Example of ADR HOMES:
diag/rdbms/orcl/ORCL1 (Product=rdbms, product_id=db_name=orcl, instance_id=ORACLE_SID=ORCL)
diag/asm/+asm/+ASM (Product=asm, product_id=+asm, instance_id=ORACLE_SID=+ASM)
diag/tnslsnr/node1/listener (Product=tnslsnr - SQL*NET Listener, product_id=hostname=node1, instance_id=listener name=listener)

157. What is a Problem?
A problem is a critical error in the database. Critical errors manifest as internal errors, such as ORA-600, and other severe errors, such as ORA-7445 or ORA-4031. Problems are tracked in the Automatic Repository (ADR).

158. What is an Incident?
An incident is a single occurrence of a problem. When a problem occurs multiple times, an incident is created for each occurrence. Incidents are time stamped and tracked in the Automatic Diagnostic Repository

159. What is ADRCI?
The ADR Command Interpreter (ADRCI) is a utility that enables you to investigate problems, view health check reports, and package and upload first-failure diagnostic data to Oracle Support, all within a environment. ADRCI also enables you to view the names of the trace files in the ADR, and to view the alert log with XML tags stripped, with and without content filtering

160. Where are the trace files and alert log Compared to 10g?
Diagnostic Data Previous Location ADR Location
Foreground Process Traces user_dump_dest ADR HOME/trace
Background Process Traces background_dump_dest ADR HOME/trace
Alert Log File background_dump_dest
ADR HOME/alert/log.xml
ADR HOME/trace/alert_<SID>.log
SQL*Net Listener Log File log_directory_listener ADR HOME/alert /log.xml
Core Dump Files core_dump_dest ADR HOME/cdump
Incident Dump Files <user/background>_dump_dest ADR HOME/incident/incdir_n

161. What Oracle Errors can create an Incident?
The next errors will automatically produce an Incident:
Internal errors:
ORA-00600 "internal error code, arguments: [%s], [%s], [%s], [%s], [%s], [%s], [%s], [%s]"
ORA-00700 "soft internal error, arguments: [%s], [%s], [%s], [%s], [%s], [%s], [%s], [%s]"
ORA-07445 "exception encountered: core dump [%s] [%s] [%s] [%s] [%s] [%s]"
Some of the External Errors are:
ORA-04030 "out of process memory when trying to allocate %s bytes (%s,%s)"
ORA-04031 "unable to allocate %s bytes of shared memory (\"%s\",\"%s\",\"%s\",\"%s\")"
ORA-29740 "evicted by member %s, group incarnation %s"
ORA-01578 "ORACLE data block corrupted (file # %s, block # %s)"
ORA-00353 "log corruption near block %s change %s time %s"
ORA-00355 "change numbers out of order"
ORA-00356 "inconsistent lengths in change description"

162. Can The Diagnosability Framework be configured to create an Incident for other errors?
No, only a set of predefined errors are automatically tracked by the diagnosability framework.

163. What is EM Support Workbench?
The Enterprise Manager Support Workbench (Support Workbench) is a facility that enables you to investigate, report, and in some cases, repair problems (critical errors), all with an easy-to-use graphical Support Workbench provides a self-service means for you to gather first-failure diagnostic data, obtain a support request number, and upload diagnostic data to Oracle Support with a minimum of effort and time, thereby reducing time-to-resolution for problems. The Support Workbench also recommends and provides easy access to Oracle advisors that help you repair SQL-related problems, data corruption more.

164. Which options are there to change the database or national character set?
There 2 basic ways, you can:
a. Export the contents of the database, create a new database with a different character set and import the data into that database.
b. Use the ALTER DATABASE CHARACTER SET (8i/9i) or Csalter (10g and up) to change the character set of the current database.
There are a lot more restrictions on method (b) than there are on method (a).

165. What is a superset/subset?
Oracle defines a superset/subset pair as 2 character sets that defineexactly the same characters at the same codepoints and on top of that one(and only one) of them defines some additional characters (that is thesuperset).
If a character set defines the same characters (and some more) as anothercharacter set but uses different codepoints to define these characters theyare NOT classed as a superset/subset pair.
An strict superset means that in addition to above all characters from oneuse the same codepoints in the other.
For example AL32UTF8 is a superset of WE8MSWIN1252 but not a strictsuperset seen there are characters who are known in both but use a differentcodepoint.
WE8MSWIN1252 is a strict superset of WE8ISO8859P1 seen all characters inWE8ISO8859P1 are known with the same codepoint in WE8MSWIN1252.

166. Why do I get ORA-01679: "database must be mounted EXCLUSIVE and not open to activate" when I use the ALTER DATABASE CHARACTER SET command?
This error message is misleading, you get this message
- if you do not enable restricted session
- if you startup the instance in PARALLEL/SHARED mode
- if you do not set the number of queue processes to 0
- if you do not set the number of AQ time manager processes to 0
- if anybody is logged in apart from you.