数据库的存储结构
[每日一题] 11gOCP 1z0-052 :2013-08-31 数据库的存储结构....................................................A8 http://blog.csdn.net/guoyjoe/article/details/10784599 、 正确答案:A 将逻辑存储与物理存储分开是关系数据库范例的必要部分。关系数据
[每日一题] 11gOCP 1z0-052 :2013-08-31 数据库的存储结构....................................................A8
http://blog.csdn.net/guoyjoe/article/details/10784599
、
正确答案:A
将逻辑存储与物理存储分开是关系数据库范例的必要部分。关系数据库范例表明:编程人员只处理逻辑结构,而让数据库去管理到物理结构的映射。这意味着,可以重新组织物理存储,也可以将整个数据库移动到完全不同的硬件和操作系统上,而应用程序意识不到任何更改。
如下图展示Oracle存储模型,逻辑结构在左,物理结构在右。
注释:
从图示可以看出,数据库的存储结构可以分成两条路线去理解:
一是逻辑结构,即数据库由各个表空间组成,表空间由各个段组成,段由各个区段组成,区段由各个oracle块组成;
二是物理结构,即数据库由各个表空间组成,表空间由各个操作系统级别的文件组成,(操作系统级别的)文件由各个操作系统块组成。
疑问:一个段只能存放在一个操作系统级别的文件上吗?还是可以跨文件存放?
1、Oracle数据库逻辑结构
(1)DATABASE:一个数据库可划分为多个称为表空间的逻辑存储单元。
如下查询一个数据库中有七个表空间
[html] view plaincopy
- gyj@OCM> select tablespace_name from dba_tablespaces;
- TABLESPACE_NAME
- ------------------------------
- SYSTEM
- SYSAUX
- UNDOTBS1
- TEMP
- USERS
- EXAMPLE
- GYJ
(2)TABLESPACE:只能属一个数据库,包括一个或多个文件。如下表空间GYJ下有两个数据文件。
[html] view plaincopy
- gyj@OCM> col tablespace_name for a20
- gyj@OCM> col file_name for a50
- gyj@OCM> select tablespace_name,file_name from dba_data_files where tablespace_name='GYJ';
- TABLESPACE_NAME FILE_NAME
- -------------------- --------------------------------------------------
- GYJ /u01/app/oracle/oradata/ocm/gyj01.dbf
- GYJ /u01/app/oracle/oradata/ocm/gyj02.dbf
(3)SEGMENT:存在于表空间中,包含一个或多个区。
包括:表段、表分区段、索引段、索引分区段、临时段、撤销段、BLOB、CLOB
[html] view plaincopy
- gyj@OCM> select distinct segment_type from dba_segments;
- SEGMENT_TYPE
- ------------------
- LOBINDEX
- INDEX PARTITION
- TABLE SUBPARTITION
- ROLLBACK
- TABLE PARTITION
- NESTED TABLE
- LOB PARTITION
- LOBSEGMENT
- INDEX
- TABLE
- TYPE2 UNDO
- CLUSTER
查T1段所在的表空间、区的信息。
[html] view plaincopy
- gyj@OCM> select TABLESPACE_NAME,EXTENTS,BYTES/1024/1024||'M',BLOCKS from user_segments where segment_name='T1';
- TABLESPACE_NAME EXTENTS BYTES/1024/1024||'M' BLOCKS
- -------------------- ---------- ----------------------------------------- ----------
- GYJ 1 .0625M 8
(4)EXTENT:由相邻的数据块的组成,这意味着每个区只能存在于一个数据文件中。
[html] view plaincopy
- gyj@OCM> select TABLESPACE_NAME,EXTENT_ID,FILE_ID,BLOCK_ID,BYTES,BLOCKS from dba_extents where segment_name='T1' and owner='GYJ';
- TABLESPACE_NAME EXTENT_ID FILE_ID BLOCK_ID BYTES BLOCKS
- -------------------- ---------- ---------- ---------- ---------- ----------
- GYJ 0 6 176 65536 8
(5)BLOCK:是数据库中最小的I/O单元,db_block_size
[html] view plaincopy
- gyj@OCM> show parameter db_block_size
- NAME TYPE VALUE
- ------------------------------------ ----------- ------------------------------
- db_block_size integer 8192
2、Oracle数据库物理结构
(1)、OS文件
A、仅属于一个表空间
B、是构成表空间的基础文件
(2)、OS块
A、 tune2fs-l /dev/sda1
[html] view plaincopy
- [root@mydb ~]# tune2fs -l /dev/sda1
- tune2fs 1.39 (29-May-2006)
- Filesystem volume name: /boot
- Last mounted on: not available>
- Filesystem UUID: 866e46b9-cb84-4271-b694-4ca3d25dc621
- Filesystem magic number: 0xEF53
- Filesystem revision #: 1 (dynamic)
- Filesystem features: has_journal ext_attr resize_inode dir_index filetype needs_recovery sparse_super
- Default mount options: user_xattr acl
- Filesystem state: clean
- Errors behavior: Continue
- Filesystem OS type: Linux
- Inode count: 26104
- Block count: 104388
- Reserved block count: 5219
- Free blocks: 89230
- Free inodes: 26070
- First block: 1
- Block size: 1024
- Fragment size: 1024
- Reserved GDT blocks: 256
- Blocks per group: 8192
- Fragments per group: 8192
- Inodes per group: 2008
- Inode blocks per group: 251
- Filesystem created: Mon Aug 12 19:59:14 2013
- Last mount time: Sat Aug 31 20:35:07 2013
- Last write time: Sat Aug 31 20:35:07 2013
- Mount count: 16
- Maximum mount count: -1
- Last checked: Mon Aug 12 19:59:14 2013
- Check interval: 0 (none>)
- Reserved blocks uid: 0 (user root)
- Reserved blocks gid: 0 (group root)
- First inode: 11
- Inode size: 128
- Journal inode: 8
- Default directory hash: tea
- Directory Hash Seed: 12499f4f-6bd0-40d2-8a7a-6224b8f449dd
- Journal backup: inode blocks
B、扇区:512字节操作系统一次IO的大小
[html] view plaincopy
- [root@mydb ~]# fdisk -l
- Disk /dev/sda: 26.8 GB, 26843545600 bytes
- 255 heads, 63 sectors/track, 3263 cylinders
- Units = cylinders of 16065 * 512 = 8225280 bytes
- Device Boot Start End Blocks Id System
- /dev/sda1 * 1 13 104391 83 Linux
- /dev/sda2 14 144 1052257+ 82 Linux swap / Solaris
- /dev/sda3 145 3263 25053367+ 83 Linux

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











Apple's latest releases of iOS18, iPadOS18 and macOS Sequoia systems have added an important feature to the Photos application, designed to help users easily recover photos and videos lost or damaged due to various reasons. The new feature introduces an album called "Recovered" in the Tools section of the Photos app that will automatically appear when a user has pictures or videos on their device that are not part of their photo library. The emergence of the "Recovered" album provides a solution for photos and videos lost due to database corruption, the camera application not saving to the photo library correctly, or a third-party application managing the photo library. Users only need a few simple steps

To handle database connection errors in PHP, you can use the following steps: Use mysqli_connect_errno() to obtain the error code. Use mysqli_connect_error() to get the error message. By capturing and logging these error messages, database connection issues can be easily identified and resolved, ensuring the smooth running of your application.

How to use MySQLi to establish a database connection in PHP: Include MySQLi extension (require_once) Create connection function (functionconnect_to_db) Call connection function ($conn=connect_to_db()) Execute query ($result=$conn->query()) Close connection ( $conn->close())

Lambda expression is an anonymous function without a name, and its syntax is: (parameter_list)->expression. They feature anonymity, diversity, currying, and closure. In practical applications, Lambda expressions can be used to define functions concisely, such as the summation function sum_lambda=lambdax,y:x+y, and apply the map() function to the list to perform the summation operation.

JSON data can be saved into a MySQL database by using the gjson library or the json.Unmarshal function. The gjson library provides convenience methods to parse JSON fields, and the json.Unmarshal function requires a target type pointer to unmarshal JSON data. Both methods require preparing SQL statements and performing insert operations to persist the data into the database.

Using the database callback function in Golang can achieve: executing custom code after the specified database operation is completed. Add custom behavior through separate functions without writing additional code. Callback functions are available for insert, update, delete, and query operations. You must use the sql.Exec, sql.QueryRow, or sql.Query function to use the callback function.

MySQL is an open source relational database management system. 1) Create database and tables: Use the CREATEDATABASE and CREATETABLE commands. 2) Basic operations: INSERT, UPDATE, DELETE and SELECT. 3) Advanced operations: JOIN, subquery and transaction processing. 4) Debugging skills: Check syntax, data type and permissions. 5) Optimization suggestions: Use indexes, avoid SELECT* and use transactions.

Through the Go standard library database/sql package, you can connect to remote databases such as MySQL, PostgreSQL or SQLite: create a connection string containing database connection information. Use the sql.Open() function to open a database connection. Perform database operations such as SQL queries and insert operations. Use defer to close the database connection to release resources.
