Tải bản đầy đủ

Bài tập làm quen với hệ quản trị cơ sở dữ liệu Informix

DAY 1
The DB-Access Utiltiy
1. Creating the demonstration database

2. Putting the DB-Access utility to work
2.1 Invoke DB-Access and connect to the stores database.

2.2 To look at the list of tables in the database. To look at the columns in the orders table:


2.3 Running a simple query against the table to view data.

2.4 This switches from editing mode to interactive mode.

Creating Simple Test Data
1. Start the dbaccess utility, and select the stores_demo database.


2. Create a table called big

3. Insert one row of data into the table:


4. Select the data from the table. Which values are assigned to the columns?


5. Change the insert statement by choosing the Use-Editor option from the menu. Change the
editor from vi to gedit. Insert more data in to the table big by executing the following statement

6. Select the data from the table. Which values are assigned to the columns? What is the meaning
of the data type serial(1) ?

- Ý nghĩa của kiểu dữ liệu serial(1): mỗi lần insert trường id sẽ tăng thêm 1 đơn vị
7. Execute the insert statement from exercise 5 again. Count the number of rows in the table.

8. Execute the insert statement until you have a table with about 3 million rows.
9. Leave dbaccess and create a file called sumbig.sql which contains the following statement


10. Execute the SQL script from exercise 9 in batch mode using the command

11. Using the Unix tool time you can also measure the execution time of the select statement:

DAY 2
Module ‘Memory in an DBMS’ Exercises
1. Open a terminal window. Restart the DBMS using onmode and oninit to empty thebuffer pool.
Use the onstat-utility to verify that your DBMS is up and running.


2. What is the page size of your buffer pool pages?
3. How many pages can be cached in the buffer pool of your DBMS?
4. Use onstat –z to reset the values that are shown to you by the onstat-utility. The values reported
by onstat –g buf should now be 0.


5. Open a second terminal window. Start dbaccess. Execute the following SQL statement:
select sum(id)
from big

6. Monitor the number of pages read from disk by the select-statement in the other terminal
window


7. Use onstat –z again to reset the values that are shown to you by the onstat-utility. The values
shown by onstat –g buf should be 0 again.


8. Re-run the select-statement from exercise 5.

9. Monitor the number of pages read from disk and the cache-hit rate in the other terminal. There
should by a significant change. Explain the reasons for this change


Module ‘Disks in a DBMS’ Exercises
1. Open a terminal window. Which dbspaces exist in your DBMS?


2. Open a second terminal window and start dbaccess. Connect to the demo database
and create a table friends

3. Insert some rows of data so that both dbspaces are used.

4. Go to the other terminal window and clear the reported numbers using onstat –z.
Using onstat –D we can monitor how many pages are read from which dbspace.
Execute the command and convince yourself. Since we cleared statistics, everything
should by zero.


5. Switch to your dbaccess terminal. Write a select-statement, that only selects
records of friends, whose last name start with a letter between ‘N’ to ‘Z’.

6. Switch to the other window and execute onstat –D. What output did you expect?

7. We should avoid caching in the current case. We bounce (shut down and restart) the
DBMS:
onmode –yuk
shuts the DBMS down
oninit
restarts it


8. Reset the onstat-results again by using onstat –z.
9. Try to execute the following SQL statement:
10. Try to use the internet to resolve this problem.

DAY 3
Module ‘Sequential Reads’ Exercises
1. Create a table of significant size, as you did in the lab ‘Creating Simple Test Data’.


2. Monitor the current status of the allocated extents using oncheck –pt like we did in the lecture.
Review the following information
• Number of extents 4
• First extent size 8
• Next extent size 2048
• Number of rows 3263442
3. Read the chapters ‘Extent size doubling’ and ‘Merge of Extents for the Same Table’ in the IBM
documentation. This should make things clearer.
4. Use the tools that we discussed in the lecture to reorganize the table into one extent.

5. The previous exercises demonstrated, that it is not that simple, to create tables with multiple
extents. Create and populate a table with three extents.


Module ‘Index’ Exercises
1. Copy and paste the following SQL statements to a file called fill.sql:

2. Run the script and measure the time that is used for execution:
time dbaccess stores_demo fill.sql
Write down the resulting time.


3. Edit the SQL script and change the line

4. Create an SQL script access.sql that contains the following statement
select * from big where id=1000000
Bounce the database server, run the script and measure the time that is used for
execution. Write down the execution time.

5. Open dbaccess and navigate in the menu to Query-Language->Info. Choose the
table big. Go to the Constraints->Primary menu and write down the name of the
primary key constraint. Go to Query Language and execute following statement
alter table big drop constraint


6. Bounce the database server, run the script access.sql again and measure the time
that is used for execution. Write down the execution time. Compare it with result from 4.
and explain the difference.
Does it make sense if the DBMS uses the index in the following query?
select sum(number)
from big
where mod(id,2)=0
Explain!
Assume we have an index on the column number:
create index idx1 on big(number)
Does it make sense if the DBMS uses this index in the following query?
select count(id)
from big
where number=0
Explain!


DAY 4
Module 1: Overview of IBM Informix Dynamic Server Exercise
Match the term on the left with the correct definition on the right.
_D_ chunk
A. Physical contiguous pages on a disk that are assigned to a specific
tblspace.
_H_ virtual processors
B. Largestdata from disk.part of shared memory that is dedicated to
holding
_A_ extent
C. Area on disk that holds before-images of pages.
_G_ logical log
D. A unit of disk space that is assigned to a dbspace.
_B_ buffer pool
E. System event in which modified buffers are copied to disk.
_E_ checkpoint
F. Basic unit of storage and I/O in a server system.


_F_ page
_C_ physical log
_K_ resident portion
__J dbspaces
_I_ virtual portion

G. Space on disk that holds transaction information.
H. Processes that make up the database server.
I. Shared-memory component that contains thread and session data.
J. A logical collection of chunks that forms a pool of disk space used by
tables and databases
K. Shared-memory component that contains the buffer pool.

Module 3 ‘Configuring Client-Server Connectivity’ Exercises
1. Check your environment using the Unix command env.
- INFORMIXDIR: /opt/IBM/informix
- ONCONFIG: onconfig.ol_informix1170_1
- INFORMIXSQLHOSTS:/opt/IBM/informix/etc/sqlhosts.ol_informix1170_1
2. Use Nautilus to locate the file referenced by the environment variable ONCONFIG in
the directory INFORMIXDIR/etc and open it in a text editor.

3. Locate the parameter DBSERVERALIASES in the configuration file and add the alias
shm_informix1170 to this parameter. Save your configuration file.

4. Locate the file referenced by the environment variable INFORMIXSQLHOSTS. Add the
appropriate connectivity information in a second line of the file. Remember: The syntax of the
sqlhosts file requires an entry in the last column of a rows, although it is not needed for the shared
memory configuration.


5. To make your new server alias become effective shutdown and restart your database server.

6. Start dbaccess and choose the menu item Connection. Choose your new alias shm_informix1170
and press the return key, when asked for the user name. The connection should be established.

DAY 5
Module ‘Configuring a Database Server’ Exercises
In this exercise, you will configure and initialize a database server from scratch. Since
you already have a configured server on your machine, this exercise will also provide
practice in configuring in a multiple-residency environment. Multiple residency is simply
running multiple database servers on a single machine.
1. To reduce load from your virtual machine shutdown your current server instance using
onmode –yuk.

2. Check your environment and write the values of the variables INFORMIXDIR and
ONCONFIG.
ONFORMIXDIR: /opt/IBM/informix
ONCONFIG=onconfig.ol_informix1170_1
3. Locate the file referenced by the environment variable ONCONFIG in the directory


INFORMIXDIR/etc using Nautilus and open it in a text editor. This is the configuration
file of your current pre-configured DBMS. Locate the parameter SERVERNUM and write it
down. Close the file.

4. The environment of your current DBMS is defined in the script.bashrc, which is
automatically executed every time a terminal is opened. In your home directory, create a
new file yourname.sh to set environment variables for your new server. Use the
following settings:
export ONCONFIG=onconfig.yourname
export INFORMIXSERVER=yourname
export INFORMIXSQLHOSTS=/sqlhosts.yourname
The remaining variables, like INFORMIXDIR, are inherited.


5. Go to your terminal window and execute the script using the command
. ./yourname.sh
The changes to your environment should now show up, if you use the env command.


6. In your home directory, create a cooked file called rootchunk to be used as the first
chunk in your root dbspace. Use the
chmod 660
command to make sure that owner, group, and permissions on this file are properly set.


7. Since we want to configure network connection using TCP we should add an entry to
the /etc/services file. This file can only be changed by the Unix super user ‘root’.
You can edit the file with root permissions with the following command:
sudo gedit /etc/services
Add a TCP service to the bottom of the file and use new unused port.


8. In your home directory, create the file sqlhosts.yourname. Add a line to the file
that configures network connectivity for your new server.


9. Use Nautilus to locate the $INFORMIXDIR/etc directory. Copy the file
onconfig.std to your configuration file onconfig.yourname. Open this file using a
text editor.
We have to change some configuration parameters:
♣ Set ROOTPATH to the full path and filename of the rootchunk file you created in
step 5. Do not change the ROOTNAME, ROOTSIZE, or ROOTOFFSET parameters.
♣ Set the MSGPATH configuration parameter to /online.log.
Substitute your home directory for the pathname. Do not change the CONSOLE
parameter.
♣ Set SERVERNUM to a number that is different from the number you found in 3. Remember: The
SERVERNUM is the key to distinguish the old and to new server
instance from each other.
♣ Set DBSERVERNAME to the same value as INFORMIXSERVER (which should be
yourname).
♣ Set the TAPEDEV and LTAPEDEV parameters to /dev/null. These parameters
specify the name of the devices to use for backing up the database server and
logical logs, respectively, using the ontape command. They will be discussed
further in a later module.


Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Tải bản đầy đủ ngay

×