The Oracle database provides an abstraction of logical storage from physical.. The datafiles can exist as files in a file system or from release 10g onward on Automatic Storage Manageme
Trang 1Self Test
1 Which protocols can Oracle Net 11g use? (Choose all correct answers.)
A TCP
B UDP
C SPX/IPX
D SDP
E TCP with secure sockets
F Named Pipes
G LU6.2
H NetBIOS/NetBEUI
2 Where is the division between the client and the server in the Oracle environment? (Choose the best answer.)
A Between the instance and the database
B Between the user and the user process
C Between the server process and the instance
D Between the user process and the server process
E The client-server split varies depending on the stage of the execution cycle
3 Which of the following statements about listeners is correct? (Choose the best answer.)
A A listener can connect you to one instance only
B A listener can connect you to one service only
C Multiple listeners can share one network interface card
D An instance will only accept connections from the listener specified
on the local_listener parameter
4 You have decided to use Local Naming Which files must you create on the client machine? (Choose the best answer.)
A tnsnames.ora and sqlnet.ora
B listener.ora only
C tnsnames.ora only
D listener.ora and sqlnet.ora
E None—you can rely on defaults if you are using TCP and your listener is running on port 1521
Trang 25 If you stop your listener, what will happen to sessions that connected through
it? (Choose the best answer.)
A They will continue if you have configured failover
B They will not be affected in any way
C They will hang until you restart the listener
D You cannot stop a listener if it is in use
E The sessions will error out
6 Study this tnsnames.ora file:
test =
(description =
(address_list =
(address = (protocol = tcp)(host = serv2)(port = 1521))
)
(connect_data =
(service_name = prod)
)
)
prod =
(description =
(address_list =
(address = (protocol = tcp)(host = serv1)(port = 1521))
)
(connect_data =
(service_name = prod)
)
)
dev =
(description =
(address_list =
(address = (protocol = tcp)(host = serv2)(port = 1521))
)
(connect_data =
(service_name = dev)
)
)
Which of the following statements is correct about the connect strings test,
prod, and dev? (Choose all correct answers.)
A All three are valid
B All three can succeed only if the instances are set up for dynamic instance
registration
C The test connection will fail, because the connect string doesn’t match the
service name
D There will be a port conflict on serv2, because prod and dev try to use the
same port
Trang 37 Consider this line from a listener.ora file:
L1=(description=(address=(protocol=tcp)(host=serv1)(port=1521)))
What will happen if you issue this connect string?
connect scott/tiger@L1 (Choose the best answer)
A You will be connected to the instance L1
B You will only be connected to an instance if dynamic instance registration
is working
C The connection attempt will fail
D If you are logged on to the server machine, IPC will connect you to the local instance
E The connection will fail if the listener is not started
8 Which of these memory structures is not stored in the SGA for a shared server session? (Choose the best answer.)
A Cursor state
B Sort space
C Stack space
9 Match the object to the function:
10 Which of the following is true about dispatchers? (Choose all correct answers.)
A Dispatchers don’t handle the work of users’ requests; they only interface between user processes and queues
B Dispatchers share a common response queue
C Dispatchers load-balance connections between themselves
D Listeners load-balance connections across dispatchers
E You can terminate a dispatcher, and established sessions will continue
Trang 411 Which of the following statements about shared servers are true? (Choose the
best answer.)
A All statements in a multistatement transaction will be executed by the
same server
B If one statement updates multiple rows, the work may be shared across
several servers
C The number of shared servers is fixed by the SHARED_SERVERS parameter
D Oracle will spawn additional shared servers on demand
Self Test Answers
1 þ A, D, E, and F TCP, SDP, TCPS, and NMP are the supported protocols
with the current release
ý B, C, G, and H B and H are wrong because UDP and NetBIOS/NetBEUI
have never been supported C and G are wrong because SPX and LU6.2 are no
longer supported
2 þ D The client-server split is between user process and server process.
ý A, B, C, and E These all misrepresent the client-server architecture.
3 þ C Many listeners can shared one address, if they use different ports.
ý A, B, and D A is wrong because one listener can launch sessions against
many instances B is wrong because a listener can connect you to a registered
service D is wrong because the local_listener parameter controls
which listener the instance will register with dynamically; it will also accept
connections from any listener that has it statically registered
4 þ C This is the only required client-side file for local naming.
ý A, B, D, and E A is wrong because sqlnet.ora is not essential B and
D are wrong because they refer to server-side files E is wrong because some
configuration is always necessary for local naming (though not for Easy
Connect)
5 þ B The listener establishes connections but is not needed for their
maintenance
ý A, C, D, and E These are all incorrect because they assume that the
listener is necessary for the continuance of an established session
6 þ A and B All three are valid but will only work if the services are registered
with the listeners
ý C and D C is wrong because there need be no connection between the
alias used in a connect string and the service name D is wrong because many
services can be accessible through a single listening port
Trang 57 þ C The CONNECT_DATA that specifies a SID or service is missing.
ý A, B, D, and E A is wrong because L1 is the connect string, not an instance or service name B is wrong because dynamic registration is not enough to compensate for a missing CONNECT_DATA clause D is wrong because the use of IPC to bypass the listener is not relevant E is wrong
because (while certainly true) it is not the main problem
8 þ C Stack space is not part of the UGA and therefore does not go into
the SGA
ý A and B These are UGA components and therefore do go into the SGA.
9 þ a – B, b – E, c – F, d – A, e – D, f – C
These are the correct mappings of objects to functions
10 þ A and D Dispatchers maintain the connection to user processes, place
requests on the common queue, and retrieve result sets from response queues
ý B, C, and E B is wrong because each dispatcher has its own response queue C is wrong because it is the listener that load-balances, not the dispatchers E is wrong because the connections to a dispatcher are persistent:
if it dies, they will be broken
11 þ D To prevent queueing on the common queue, Oracle will launch
additional shared servers—but only up to the max_shared_servers value
ý A, B, and C A is wrong because each statement may be picked up by a different server B is wrong because any one statement can be executed by only one server C is wrong because this parameter controls the number of servers
initially launched, which may change later
Trang 6CHAPTER 5
Oracle Storage
Exam Objectives
In this chapter you will learn to
• 052.6.1 Work with Tablespaces and Datafiles
• 052.6.2 Create and Manage Tablespaces
• 052.6.3 Handle Space Management in Tablespaces
171
Trang 7The preceding two chapters dealt with the instance and the sessions against it: processes and memory structures This chapter begins the investigation of the database itself All data processing occurs in memory, in the instance, but data storage occurs in the database on disk The database consists of three file types: the controlfile, the online redo log files, and the datafiles Data is stored in the datafiles
Users never see a physical datafile All they see are logical segments System administrators never see a logical segment All they see are physical datafiles The Oracle database provides an abstraction of logical storage from physical This is one
of the requirements of the relational database paradigm As a DBA, you must be aware
of the relationship between the logical and the physical storage Monitoring and
administering these structures, a task often described as space management, used to
be a huge part of a DBA’s workload The facilities provided in recent releases of the database can automate space management to a certain extent, and they can certainly let the DBA set up storage in ways that will reduce the maintenance workload
considerably
Overview of Tablespaces and Datafiles
Data is stored logically in segments (typically tables) and physically in datafiles The
tablespace entity abstracts the two: one tablespace can contain many segments and be
made up of many datafiles There is no direct relationship between a segment and a
datafile The datafiles can exist as files in a file system or (from release 10g onward)
on Automatic Storage Management (ASM) devices
The Oracle Data Storage Model
The separation of logical from physical storage is a necessary part of the relational database paradigm The relational paradigm states that programmers should address only logical structures and let the database manage the mapping to physical structures This means that physical storage can be reorganized, or the whole database moved
to completely different hardware and operating system, and the application will not
be aware of any change
Figure 5-1 shows the Oracle storage model sketched as an entity-relationship diagram, with the logical structures to the left and the physical structures to the right There is one relationship drawn in as a dotted line: a many-to-many relationship between segments and datafiles This relationship is dotted, because it shouldn’t be there As good relational engineers, DBAs do not permit many-to-many relationships Resolving this relationship into a normalized structure is what the storage model is all about The following discussion takes each of the entities in Figure 5-1 one by one
The tablespace entity resolves the many-to-many relationship between segments
and datafiles One tablespace can contain many segments and be made up of many datafiles This means that any one segment may be spread across multiple datafiles, and any one datafile may contain all of or parts of many segments This solves many storage challenges Some older database management systems used a one-to-one
Trang 8relationship between segments and files: every table or index would be stored as a
separate file This raised two dreadful problems for large systems First, an application
might well have thousands of tables and even more indexes; managing many
thousands of files was an appalling task for the system administrators Second, the
maximum size of a table is limited by the maximum size of a file Even if modern
operating systems do not have any practical limits, there may well be limitations
imposed by the underlying hardware environment Use of tablespaces bypasses both
these problems Tablespaces are identified by unique names in the database
The segment entity represents any database object that stores data and therefore
requires space in a tablespace Your typical segment is a table, but there are other
segment types, notably index segments (described in Chapter 7) and undo segments
(described in Chapter 8) Any segment can exist in only one tablespace, but the
tablespace can spread it across all the files making up the tablespace This means that
the tables’ sizes are not subject to any limitations imposed by the environment on
maximum file size As many segments can share a single tablespace, it becomes
possible to have far more segments than there are datafiles Segments are schema
objects, identified by the segment name qualified with the owning schema name
Note that programmatic schema objects (such as PL/SQL procedures, views, or
sequences) are not segments: they do not store data, and they exist within the data
dictionary
The Oracle block is the basic unit of I/O for the database Datafiles are formatted
into Oracle blocks, which are consecutively numbered The size of the Oracle blocks
is fixed for a tablespace (generally speaking, it is the same for all tablespaces in the
database); the default (with release 11g) is 8KB A row might be only a couple
hundred bytes, and so there could be many rows stored in one block, but when
Logical view
Tablespace
Segment
Extent
Oracle block Operating
system block
Datafile
Physical view
Figure 5-1
The Oracle storage
model
Trang 9a session wants a row, the whole block will be read from disk into the database buffer cache Similarly, if just one column of one row has been changed in the database buffer cache, the DBWn will (eventually) write the whole block back into the datafile from which it came, overwriting the previous version The size of an Oracle block can range from 2KB to 16KB on Linux or Windows, and to 32KB on some other operating systems The block size is controlled by the parameter DB_BLOCK_SIZE This can never be changed after database creation, because it is used to format the datafile(s) that make up the SYSTEM tablespace If it becomes apparent later on that the block size is inappropriate, the only course of action is to create a new database and transfer everything into it A block is uniquely identified by its number within a datafile Managing space one block at a time would be a crippling task, so blocks are
grouped into extents An extent is a set of consecutively numbered Oracle blocks
within one datafile Every segment will consist of one or more extents, consecutively numbered These extents may be in any and all of the datafiles that make up the tablespace An extent can be identified from either the dimension of the segment (extents are consecutively numbered per segment, starting from zero) or the
dimension of the datafile (every segment is in one file, starting at a certain Oracle block number)
A datafile is physically made up of a number of operating system blocks How
datafiles and the operating system blocks are structured is entirely dependent on the operating system’s file system Some file systems have well-known limitations and are therefore not widely used for modern systems (for example, the old MS-DOS FAT file system could handle files up to only 4GB, and only 512 of them per directory) Most databases will be installed on file systems with no practical limits, such as NTFS
on Windows or ext3 on Linux The alternatives to file systems for datafile storage are raw devices or Automatic Storage Management (ASM) Raw devices are now very rarely used for datafile storage because of manageability issues ASM is detailed in Chapter 20
An operating system block is the basic unit of I/O for your file system A process might
want to read only one byte from disk, but the I/O system will have to read an operating system block The operating system block size is configurable for some file systems (for example, when formatting an NTFS file system you can choose from 512B to 64KB), but typically system administrators leave it on default (512B for NTFS, 1KB for ext3) This is why the relationship between Oracle blocks and operating system blocks
is usually one-to-many, as shown in Figure 5-1 There is no reason not to match the operating system block size to the Oracle block size if your file system lets you do this The configuration that should always be avoided would be where the operating system blocks are bigger than the Oracle blocks
Segments, Extents, Blocks, and Rows
Data is stored in segments The data dictionary view DBA_SEGMENTS describes every segment in the database This query shows the segment types in a simple database:
Trang 10SQL> select segment_type,count(1) from dba_segments group by segment_type
2 order by segment_type;
SEGMENT_TYPE COUNT(1)
-
-CLUSTER 10
INDEX 3185
INDEX PARTITION 324
LOB PARTITION 7
LOBINDEX 760
LOBSEGMENT 760
NESTED TABLE 29
ROLLBACK 1
TABLE 2193
TABLE PARTITION 164
TYPE2 UNDO 10
11 rows selected.
SQL>
In brief, and in the order they are most likely to concern a DBA, these segments
types are
• TABLE These are heap-structured tables that contain rows of data Even
though a typical segment is a table segment, never forget that the table is not
the same as the segment, and that there are more complex table organizations
that use other segment types
• INDEX Indexes are sorted lists of key values, each with a pointer, the
ROWID, to the physical location of the row The ROWID specifies which
Oracle block of which datafile the row is in, and the row number within
the block
• TYPE2 UNDO These are the undo segments (no one refers to them as “type2
undo” segments) that store the pre-change versions of data that are necessary
for providing transactional integrity: rollback, read consistency, and isolation
• ROLLBACK Rollback segments should not be used in normal running from
release 9i onward Release 9i introduced automatic undo management, which
is based on undo segments There will always be one rollback segment that
protects the transactions used to create a database (this is necessary because
at that point no undo segments exist), but it shouldn’t be used subsequently
• TABLE PARTITION A table can be divided into many partitions If this is
done, the partitions will be individual segments, and the partitioned table
itself will not be a segment at all: it will exist only as the sum total of its
partitions Each table partition of a heap table is itself structured as a heap
table, in its own segment These segments can be in different tablespaces,
meaning that it becomes possible to spread one table across multiple
tablespaces
• INDEX PARTITION An index will by default be in one segment, but indexes
can also be partitioned If you are partitioning your tables, you will usually
partition the indexes on those tables as well