Practice+34+ +Optimizing+Database+Connection
Practice+34+ +Optimizing+Database+Connection
Practice 34
Practice Target
In this practice, you will perform the recommended steps to optimize database connections.
2. Open Putty, login as oracle to srv1. In the rest of this practice, this session will be referred to as
the monitoring window.
3. Run the following code to create a SQL*Plus script file named as display_sqlnet.sql
The script retrieves the total 'SQL*Net%' wait events for specific current sessions.
4. In the hosting PC, open a command-line window. In the rest of this practice, this window will be
referred to as the client window.
5. In the client window, issue the following command to open notepad and create a SQL*Plus script
file named as run_query.sql. Enter the code that follows to the script file.
The script runs a single query. It also sets the session module/action, enables tracing on the
query, and displays the trace file of the session that runs the script file.
notepad run_query.sql
SELECT P.TRACEFILE
FROM V$SESSION S
JOIN V$PROCESS P ON S.PADDR = P.ADDR
WHERE S.USERNAME = 'SOE';
6. In the monitoring window, open the sqlnet.ora file and set the parameter
TRACE_LEVEL_SERVER to 16.
cat $TNS_ADMIN/sqlnet.ora
sqlplus soe/soe@oradb
8. In the client window, check out the value of the SQL*Plus parameter ARRAYSIZE
ARRAYSIZE sets the number of rows fetched at one time. The default value is 15.
SHOW ARRAYSIZE
10. In the monitoring window, determine the SDU size used by the connection between the client
SQL*Plus and the database listener.
Obtain the trace file full name from the output of the preceding step.
The default SDU is 8KB.
cat <trace_file> | grep nsconneg
11. In the monitoring window, use tkprof utility to convert the trace file into a text file.
tkprof <trace_file> output1.log SYS=no waits=yes
12. Open the generated text file and observe the count value of the fetch operation for the query.
It should be very close to the value 6667. Can you explain why?
Observe the 'elapsed seconds in trace file' is nearly the same as the execution time noted
earlier.
vi output1.log
13. In the monitoring window, invoke SQL*Plus, connect to the database as sysdba. Then run the
script display_sqlnet.sql. Take a note of the output.
sqlplus / as sysdba
@ display_sqlnet
In the previous steps, you ran the query and gather statistics about it. In the following steps, you will
perform changes on the database connection parameters.
14. In the monitoring window, exit from SQL*Plus then obtain the bandwidth of the network
adapter eth0
In our practice environment, the bandwidth is 1000Mb/s (this is Mb/s not MB/s).
ethtool eth0 | grep Speed
15. In the client window, exit from SQL*Plus then obtain the latency of its connection to the
database machine. Use either of the following commands.
Substitute the IP address with the IP address in your environment.
The round trip time is less than 1 ms. Consider the latency is 1 ms in this case.
ping -l 9000 192.168.1.133
tracert -4 192.168.1.133
16. Using the following formula, calculate the recommended socket size.
The recommended socket size = bandwidth * latency * 3
17. In the hosting PC, open the tnsnames.ora file with the notepad. Make the changes on the
ORADB connection descriptor so that is appears as follows.
The SDU size is increased to 512 KB.
The socket size increased to 375,000 byte.
Note: Do not copy the code from the PDF file. Take it from the attached tnsnames.ora file or
manually add them.
ORADB =
(DESCRIPTION =
(SDU=524288)
(SEND_BUF_SIZE=375000)
(RECV_BUF_SIZE=375000)
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.159)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = ORADB.localdomain)
))
18. In the monitoring window, open the sqlnet.ora file and add the following lines to it.
Note: Do not copy the code from the PDF file. Take it from the attached sqlnet.ora file or
manually add them.
vi $TNS_ADMIN/sqlnet.ora
DEFAULT_SDU_SIZE=524288
SEND_BUF_SIZE=375000
RECV_BUF_SIZE=375000
TRACE_LEVEL_SERVER=16
21. In the client window, invoke SQL*Plus, connect to ORADB as soe, then set the value of the
SQL*Plus parameter ARRAYSIZE to 100.
sqlplus soe/soe@oradb
set ARRAYSIZE 100
In the following steps, you will run the query and gather statistics about its execution. You will
compare them with the statistics noted before the changes.
23. In the monitoring window, verify that the SDU size used by the connection between the client
SQL*Plus is 524288 byte.
cat <trace_file> | grep nsconneg
24. In the monitoring window, use tkprof utility to convert the trace file into a text file.
tkprof <trace_file> output2.log SYS=no waits=yes
25. Open the generated text file and observe the count value of the fetch operation for the query.
It should be very close to the value 1000.
vi output2.log
26. In the monitoring window, invoke SQL*Plus, connect to the database as sysdba. Then run the
script display_sqlnet.sql. Compare the value of 'SQL*Net message to client' with its noted
value.
SQL*Net message to client is less after increasing the array size.
sqlplus / as sysdba
@ display_sqlnet
Cleanup
29. In the monitoring window, open the sqlnet.ora file and remove the following added code from
it.
vi $TNS_ADMIN/sqlnet.ora
DEFAULT_SDU_SIZE=524288
SEND_BUF_SIZE=375000
RECV_BUF_SIZE=375000
TRACE_LEVEL_SERVER=16
30. In the hosting PC, open the tnsnames.ora file with the notepad and remove the following added
code from it.
(SDU=524288)
(SEND_BUF_SIZE=375000)
(RECV_BUF_SIZE=375000)
Summary