Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:01,310 --> 00:00:02,890
In this lesson, we'll
be taking a look
2
00:00:02,890 --> 00:00:04,720
at the data dictionary,
particularly
3
00:00:04,720 --> 00:00:08,200
the data dictionary views,
as we refer to them.
4
00:00:08,200 --> 00:00:11,590
The data dictionary is an
extremely important part
5
00:00:11,590 --> 00:00:14,620
of any DBA's tool
kit because it is
6
00:00:14,620 --> 00:00:18,550
their source for nearly all the
information in the database.
7
00:00:18,550 --> 00:00:22,270
Anything that you want to know
about the Oracle database,
8
00:00:22,270 --> 00:00:24,490
other than error
log information,
9
00:00:24,490 --> 00:00:27,430
would be found in
the data dictionary.
10
00:00:27,430 --> 00:00:31,180
So that could be anything
from information about tables,
11
00:00:31,180 --> 00:00:36,360
the columns on tables, the
constraints on tables, indexes,
12
00:00:36,360 --> 00:00:39,720
PL SQL objects, even
the PL SQL code.
13
00:00:39,720 --> 00:00:42,360
All of that's stored in the
data dictionary, as well
14
00:00:42,360 --> 00:00:46,140
as structural information,
like table space information,
15
00:00:46,140 --> 00:00:49,530
data files, redo
logs, archive logs.
16
00:00:49,530 --> 00:00:51,960
All of that is in
the data dictionary.
17
00:00:51,960 --> 00:00:54,540
And learning to leverage
the data dictionary
18
00:00:54,540 --> 00:00:58,380
is really a career-long
effort for a DBA
19
00:00:58,380 --> 00:01:01,350
because the data
dictionary is vast.
20
00:01:01,350 --> 00:01:05,310
It is huge, and there are many,
many hundreds, even thousands
21
00:01:05,310 --> 00:01:07,110
of data dictionary views.
22
00:01:07,110 --> 00:01:09,270
But it's important
that we understand
23
00:01:09,270 --> 00:01:12,960
that we don't have to master
all of the data dictionary views
24
00:01:12,960 --> 00:01:16,530
in order to get useful
information from it.
25
00:01:16,530 --> 00:01:18,600
There are the basic
data dictionary
26
00:01:18,600 --> 00:01:21,870
views that we sort of
pick up through experience
27
00:01:21,870 --> 00:01:25,140
and a little bit of
research and some learning,
28
00:01:25,140 --> 00:01:27,630
and that can help us
with a lot of information
29
00:01:27,630 --> 00:01:29,780
just right there.
30
00:01:29,780 --> 00:01:32,630
So I wanted to say a word
about GUI tools at this point
31
00:01:32,630 --> 00:01:34,850
and give kind of
my opinion on this.
32
00:01:34,850 --> 00:01:37,700
There's always the
question between GUI tools
33
00:01:37,700 --> 00:01:40,580
and command line,
one of them having
34
00:01:40,580 --> 00:01:43,370
more ease of use in the
GUI tool and the other
35
00:01:43,370 --> 00:01:46,230
having more power
in the command line.
36
00:01:46,230 --> 00:01:47,600
So what we are
talking about here
37
00:01:47,600 --> 00:01:49,270
when we are learning
the data dictionary
38
00:01:49,270 --> 00:01:51,560
is primarily
command-line information
39
00:01:51,560 --> 00:01:54,980
because we're going to use
SELECT statements to gather
40
00:01:54,980 --> 00:01:58,120
information from
the data dictionary.
41
00:01:58,120 --> 00:02:01,990
In my experience, the use
of GUI tools has its place
42
00:02:01,990 --> 00:02:07,070
and can allow a DBA to do
things quicker and easier.
43
00:02:07,070 --> 00:02:08,800
But they should not be a crutch.
44
00:02:08,800 --> 00:02:12,580
They should not be something
that a DBA relies on solely,
45
00:02:12,580 --> 00:02:15,220
and I have seen that
in my career, DBAs
46
00:02:15,220 --> 00:02:17,710
that were really limited
because they could only
47
00:02:17,710 --> 00:02:20,140
use a certain tool to
gather the information
48
00:02:20,140 --> 00:02:24,430
they needed to do, at least
in any kind of effective way.
49
00:02:24,430 --> 00:02:28,150
The data dictionary has the
benefit over the GUI tools,
50
00:02:28,150 --> 00:02:31,450
I think, for this reason,
because a GUI tool will always
51
00:02:31,450 --> 00:02:34,750
be limited by the
designer of it.
52
00:02:34,750 --> 00:02:38,230
So it will only be able to
do the things, the tasks
53
00:02:38,230 --> 00:02:41,980
and find the information,
that the creator intended,
54
00:02:41,980 --> 00:02:45,520
whereas the data dictionary
itself, though much more
55
00:02:45,520 --> 00:02:49,780
complex, is unlimited in the
information that we can get.
56
00:02:49,780 --> 00:02:52,930
So learning to rely
on the data dictionary
57
00:02:52,930 --> 00:02:55,390
can be an important
thing for DBAs,
58
00:02:55,390 --> 00:02:57,520
and both have their place.
59
00:02:57,520 --> 00:02:59,380
But the data
dictionary should never
60
00:02:59,380 --> 00:03:04,600
be neglected just because it's
somewhat more complex to learn.
61
00:03:04,600 --> 00:03:06,120
So what is the
data dictionary now
62
00:03:06,120 --> 00:03:07,990
that we've outlined
its importance?
63
00:03:07,990 --> 00:03:09,780
Well, the data dictionary
is a set of views
64
00:03:09,780 --> 00:03:12,520
that overlay Oracle base tables.
65
00:03:12,520 --> 00:03:15,720
So the Oracle base tables
are the actual tables
66
00:03:15,720 --> 00:03:18,720
that store the information
in the database.
67
00:03:18,720 --> 00:03:22,860
So they store everything about
the database that's going on,
68
00:03:22,860 --> 00:03:25,980
that exists in the database,
that occurs in the database.
69
00:03:25,980 --> 00:03:29,580
All of those things are stored
in the Oracle base tables.
70
00:03:29,580 --> 00:03:32,590
But the base tables are
definitely not user friendly.
71
00:03:32,590 --> 00:03:34,050
They're not something
we would want
72
00:03:34,050 --> 00:03:36,840
to query directly
primarily because they're
73
00:03:36,840 --> 00:03:38,950
very difficult to read.
74
00:03:38,950 --> 00:03:44,340
They begin with names like
X$ or end with dollar signs,
75
00:03:44,340 --> 00:03:47,170
and their column names
are not descriptive.
76
00:03:47,170 --> 00:03:49,620
The data, even, that's
in the tables themselves,
77
00:03:49,620 --> 00:03:52,740
it can be very difficult
to make any sense of that.
78
00:03:52,740 --> 00:03:55,170
And so that's why Oracle
created the data dictionary
79
00:03:55,170 --> 00:03:58,890
as a set of views that
overlay that information.
80
00:03:58,890 --> 00:04:01,750
And while not easy
to use in every case,
81
00:04:01,750 --> 00:04:04,470
the data dictionary views
are much more user friendly
82
00:04:04,470 --> 00:04:06,610
and much easier to
get information.
83
00:04:06,610 --> 00:04:10,710
So there's two types of data
dictionary view, static views
84
00:04:10,710 --> 00:04:11,720
and dynamic views.
85
00:04:14,540 --> 00:04:16,850
When we talk about static
data dictionary views,
86
00:04:16,850 --> 00:04:19,130
we're primarily
talking about views
87
00:04:19,130 --> 00:04:23,600
that hold information that does
not change moment to moment.
88
00:04:23,600 --> 00:04:25,940
So information about
tables and indexes,
89
00:04:25,940 --> 00:04:28,430
database objects,
those kinds of things
90
00:04:28,430 --> 00:04:31,130
we would find in static
data dictionary views.
91
00:04:31,130 --> 00:04:34,550
Now, obviously, that
information does change.
92
00:04:34,550 --> 00:04:35,420
Tables are added.
93
00:04:35,420 --> 00:04:36,500
Indexes are added.
94
00:04:36,500 --> 00:04:37,970
Columns are removed.
95
00:04:37,970 --> 00:04:40,520
Things do change in static
data dictionary views,
96
00:04:40,520 --> 00:04:42,170
so they're not truly static.
97
00:04:42,170 --> 00:04:45,680
But we wouldn't normally think
of the structure of tables
98
00:04:45,680 --> 00:04:49,830
and the existence of tables
as changing moment by moment.
99
00:04:49,830 --> 00:04:52,610
So those are usually what we
classify under the static data
100
00:04:52,610 --> 00:04:54,080
dictionary views.
101
00:04:54,080 --> 00:04:57,320
There is some gray
areas and some overlap.
102
00:04:57,320 --> 00:04:59,300
But for the most
part, that's the kind
103
00:04:59,300 --> 00:05:03,470
of data that would be in a
static data dictionary view.
104
00:05:03,470 --> 00:05:07,220
So the first type of static
data dictionary view would be
105
00:05:07,220 --> 00:05:09,560
the USER_ views.
106
00:05:09,560 --> 00:05:13,670
So the USER_ views are going to
contain information primarily
107
00:05:13,670 --> 00:05:17,910
about database objects owned
by the user that logs in.
108
00:05:17,910 --> 00:05:21,080
So for instance, if I
logged in as the Scott user
109
00:05:21,080 --> 00:05:24,950
and selected star
from user_tables,
110
00:05:24,950 --> 00:05:28,460
I will get a list of table
information about the tables
111
00:05:28,460 --> 00:05:31,670
that I own or that
the Scott user owns.
112
00:05:31,670 --> 00:05:34,970
So we could say that
those user_views
113
00:05:34,970 --> 00:05:37,580
are going to be
schema-specific information.
114
00:05:37,580 --> 00:05:40,700
If you log in as Kara, you
would see Kara's tables.
115
00:05:40,700 --> 00:05:44,290
If you log in as Scott, you
would see Scott's tables.
116
00:05:44,290 --> 00:05:48,030
The second type of static data
dictionary view are the ALL_
117
00:05:48,030 --> 00:05:49,270
views.
118
00:05:49,270 --> 00:05:53,070
And the ALL_ views are
sort of like a superset
119
00:05:53,070 --> 00:05:57,600
of the user_views because the
ALL views will give you access
120
00:05:57,600 --> 00:06:01,890
to all of the information
about objects, generally,
121
00:06:01,890 --> 00:06:04,840
that you have access to.
122
00:06:04,840 --> 00:06:10,110
So if the Scott user logs in
and selects from the ALL_ views,
123
00:06:10,110 --> 00:06:13,170
he would see not only
the tables that he owns,
124
00:06:13,170 --> 00:06:16,050
but information about tables
that he has access to, that
125
00:06:16,050 --> 00:06:19,730
he's been granted access to.
126
00:06:19,730 --> 00:06:23,240
The third type of static data
dictionary views are the DBA_
127
00:06:23,240 --> 00:06:23,960
views.
128
00:06:23,960 --> 00:06:28,400
And the DBA_ views are limited
only to those users with
129
00:06:28,400 --> 00:06:29,960
the DBA role.
130
00:06:29,960 --> 00:06:33,350
So they have to have been
granted the DBA role in order
131
00:06:33,350 --> 00:06:36,620
to see the information
in the DBA_ views.
132
00:06:36,620 --> 00:06:39,080
So they are powerful
views, and they
133
00:06:39,080 --> 00:06:41,690
tend to contain all
of the information
134
00:06:41,690 --> 00:06:43,560
about a particular object.
135
00:06:43,560 --> 00:06:46,760
So if we select star
from dba_tables,
136
00:06:46,760 --> 00:06:51,340
we see a list of all of
the tables in the database.
137
00:06:51,340 --> 00:06:53,160
The second type of
data dictionary view
138
00:06:53,160 --> 00:06:55,550
is the dynamic data
dictionary views,
139
00:06:55,550 --> 00:06:57,720
and these are called
dynamic because they
140
00:06:57,720 --> 00:07:00,810
tend to have
information that changes
141
00:07:00,810 --> 00:07:02,910
on a moment-by-moment basis.
142
00:07:02,910 --> 00:07:06,570
So there is no V$ tables view.
143
00:07:06,570 --> 00:07:10,190
That information is more
reserved for the static views.
144
00:07:10,190 --> 00:07:15,080
V$ views would have information
like session information,
145
00:07:15,080 --> 00:07:17,030
process information.
146
00:07:17,030 --> 00:07:19,760
They are formally
referred to, and sometimes
147
00:07:19,760 --> 00:07:23,450
still are, as the
dynamic performance views
148
00:07:23,450 --> 00:07:25,280
because they tend to
have information that's
149
00:07:25,280 --> 00:07:27,770
used in performance
tuning, so information
150
00:07:27,770 --> 00:07:30,470
about what various
sessions are waiting
151
00:07:30,470 --> 00:07:34,190
on in the database, the various
actions and activities that
152
00:07:34,190 --> 00:07:38,640
are occurring on a system level,
all of those types of things.
153
00:07:38,640 --> 00:07:42,800
And the GV$ views, and
the G standing for Global,
154
00:07:42,800 --> 00:07:46,970
are the V$ views
that are used in RAC.
155
00:07:46,970 --> 00:07:51,020
So in any given instance
of a RAC system,
156
00:07:51,020 --> 00:07:53,180
you would have V$ views.
157
00:07:53,180 --> 00:07:57,710
But you also have GV$ views
that look over the entire RAC,
158
00:07:57,710 --> 00:08:00,170
so all of the
instances together.
159
00:08:00,170 --> 00:08:04,400
So while V$ session would allow
you to see the sessions on one
160
00:08:04,400 --> 00:08:09,500
particular instance, the
GV$ view, for GV$ session,
161
00:08:09,500 --> 00:08:12,830
would allow you to see all of
the sessions across the RAC
162
00:08:12,830 --> 00:08:13,890
itself.
163
00:08:13,890 --> 00:08:17,420
So let's take a look at
some data dictionary views.
164
00:08:17,420 --> 00:08:20,480
First, I'm going to
connect with the Kara user.
165
00:08:23,140 --> 00:08:28,150
I'm going to select
star from user_tables.
166
00:08:28,150 --> 00:08:30,140
So this is going
to be a USER_ view.
167
00:08:33,690 --> 00:08:37,740
And we show that Kara has
one table called TEST_TAB.
168
00:08:37,740 --> 00:08:40,200
But let's take a look at the
information that we have here.
169
00:08:40,200 --> 00:08:43,800
There's much more than maybe
we would need at this point.
170
00:08:43,800 --> 00:08:47,390
But it does serve to show the
scope that the data dictionary
171
00:08:47,390 --> 00:08:48,530
views have.
172
00:08:48,530 --> 00:08:52,820
So we have the name of the
table, TABLESPACE_NAME,
173
00:08:52,820 --> 00:08:56,390
things like the status,
the percent free,
174
00:08:56,390 --> 00:09:04,260
the initial extent size, the
next extent, number of rows,
175
00:09:04,260 --> 00:09:05,660
number of blocks.
176
00:09:05,660 --> 00:09:09,180
And this information, you can
see, goes on and on and on.
177
00:09:09,180 --> 00:09:12,420
And over time and experience,
we learn to leverage
178
00:09:12,420 --> 00:09:15,480
this information more and
more, and for every query
179
00:09:15,480 --> 00:09:17,160
that we want, we
won't always need
180
00:09:17,160 --> 00:09:21,090
to know all of this information,
but some of it is here.
181
00:09:21,090 --> 00:09:23,940
And sometimes the
information that we want
182
00:09:23,940 --> 00:09:26,070
is in those data
dictionary views.
183
00:09:26,070 --> 00:09:28,290
So that's an example of Kara.
184
00:09:28,290 --> 00:09:30,600
And just as a point
of information here,
185
00:09:30,600 --> 00:09:34,700
when we expand the tables list
for Kara in SQL Developer,
186
00:09:34,700 --> 00:09:37,950
notice that we see
TEST_TAB there, as well,
187
00:09:37,950 --> 00:09:42,620
because these are the
objects that Kara owns.
188
00:09:42,620 --> 00:09:45,470
So let's do select
star from all_tables.
189
00:09:49,140 --> 00:09:52,210
And I'll do, for
simplicity, order by owner.
190
00:09:55,560 --> 00:09:57,900
So here we see a
new column that's
191
00:09:57,900 --> 00:09:59,700
added that's different
than user_tables.
192
00:09:59,700 --> 00:10:03,240
So the user_tables all
pertain to a particular owner,
193
00:10:03,240 --> 00:10:05,340
so they don't need
to delineate that.
194
00:10:05,340 --> 00:10:07,050
But all_tables
actually needs to just
195
00:10:07,050 --> 00:10:09,300
be able to specify what
the owner of the table
196
00:10:09,300 --> 00:10:11,850
is because it's
all of the tables
197
00:10:11,850 --> 00:10:14,820
that Kara has access to see.
198
00:10:14,820 --> 00:10:18,990
So we see her TEST_TAB, and then
we also see a number of tables
199
00:10:18,990 --> 00:10:22,170
that she had access to
from the Scott schema.
200
00:10:22,170 --> 00:10:25,570
And the Scott user
created those objects.
201
00:10:25,570 --> 00:10:29,310
So ALL views are going
to be the ones that
202
00:10:29,310 --> 00:10:32,370
give us information
about all the objects
203
00:10:32,370 --> 00:10:34,990
that we have access to.
204
00:10:34,990 --> 00:10:38,360
So let's try to do a select
star from dba_tables.
205
00:10:42,160 --> 00:10:45,130
Well, the user Kara is going
to get an error in this case
206
00:10:45,130 --> 00:10:48,460
because it's just simply going
to say table or view does not
207
00:10:48,460 --> 00:10:51,460
exist, but that's because
Kara doesn't have the DBA
208
00:10:51,460 --> 00:10:52,630
role granted to her.
209
00:10:52,630 --> 00:10:56,380
So she cannot see
those DBA views.
210
00:10:56,380 --> 00:10:58,720
What if we tried another
one of the V$ views?
211
00:11:03,520 --> 00:11:06,080
We get the same
kind of error here.
212
00:11:06,080 --> 00:11:09,740
So she does not have access
to these V$ dynamic views,
213
00:11:09,740 --> 00:11:11,030
as well.
214
00:11:11,030 --> 00:11:13,450
So in order to find
someone who does,
215
00:11:13,450 --> 00:11:18,360
we'll need to connect
as system and then
216
00:11:18,360 --> 00:11:24,580
select star from dba_tables,
which Kara could not do.
217
00:11:24,580 --> 00:11:27,260
And then we have a list of all
of the tables in the database.
218
00:11:27,260 --> 00:11:31,330
A number of them are
going to be owned by SYS.
219
00:11:31,330 --> 00:11:33,460
So it's a very extensive list.
220
00:11:33,460 --> 00:11:36,730
Again, the data dictionary
is owned by SYS,
221
00:11:36,730 --> 00:11:39,020
those objects are.
222
00:11:39,020 --> 00:11:44,310
What if we start with a select
star from v$session for the V$
223
00:11:44,310 --> 00:11:46,200
views.
224
00:11:46,200 --> 00:11:48,400
Well, the system user
can see those, as well,
225
00:11:48,400 --> 00:11:54,340
as what a DBA, a user that's
been granted the DBA privilege.
226
00:11:54,340 --> 00:11:55,960
We have session
information here.
227
00:11:55,960 --> 00:11:57,800
And this is dynamic information.
228
00:11:57,800 --> 00:11:59,810
It changes moment to moment.
229
00:11:59,810 --> 00:12:02,920
New sessions connect in,
old sessions disconnect.
230
00:12:02,920 --> 00:12:06,880
That's the type of information
we'll have in the V$ views.
231
00:12:06,880 --> 00:12:08,530
So that's some
examples, at least,
232
00:12:08,530 --> 00:12:12,310
of the static data dictionary
views and the dynamic data
233
00:12:12,310 --> 00:12:14,130
dictionary views.
19388
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.