Oracle 估算数据库大小的方法
根据对表大小的估算,进而可以估算出整个数据库的大
一.说明
一网友问我将一个查询的结果集存放到临时表里,如果估算临时表的大小,当时想的方法是通过统计block来计算。后来想,此方法的操作性也不是很高。 最好是能在查询操作执行之前就能估算出大小。
查看了一下ALL_TABLES 表,其中有个字段:avg_row_len. 该值单位为bytes。 可以一句这个字段来进行一个估算。
AVG_ROW_LEN*
NUMBER
Average length of a row in the table (in bytes)
.com/docs/cd/E11882_01/server.112/e17110/statviews_2117.htm#i1592091
根据对表大小的估算,进而可以估算出整个数据库的大小。 在项目测试阶段,可以根据所有对象进行估算,从而可以估算出系统上线以后数据库的大小,根据这些数据可以规划存储。这里要注意一点,要给备份留足存储空间。 一般备份需要的空间是DB的2-3倍。 如果DB 是100G,那么给备份的空间最好是200G以上。
根据dba_segments视图可以查看数据库中占用存储空间的对象:
SYS@anqing2(rac2)> select distinctsegment_type from dba_segments;
SEGMENT_TYPE
------------------
LOBINDEX
INDEX PARTITION
TABLE PARTITION
NESTED TABLE
ROLLBACK
LOB PARTITION
LOBSEGMENT
INDEX
TABLE
CLUSTER
TYPE2 UNDO
11 rows selected.
这里主要就是表和索引。把所有表和索引的大小估算出来,在相加就可以估算出DB的大小了。
二. 估算表的大小
表的大小=记录数*平均字段大小(avg_row_len)
Avg_row_len 可以通过如下SQL 查询。 其单位为bytes。
SYS@anqing2(rac2)> selecttable_name,avg_row_len from all_tables where table_name='T1';
TABLE_NAME AVG_ROW_LEN
------------------------------ -----------
T1 93
如果T1 表未来估计为1000万行,那么其大小就是1000w*93bytes。
三.估算表上索引的大小
All_indexes 视图没有all_tables 上的avg_row_len 字段,不过我们可以通过视图和表大小的一个比率进行估算。 表的大小我们可以估算出来,,索引的大小可以通过这个比率进行估算。
SQL>create index idx_t1_created on t1(created)
SQL>exec dbms_stats.gather_table_stats('SYS','T1',cascade=>TRUE)
SYS@anqing2(rac2)> selectsegment_name,segment_type,bytes,blocks from dba_segments where segment_namein ('T1','IDX_T1_CREATED');
SEGMENT_NAME SEGMENT_TYPE BYTES BLOCKS
--------------- ---------------------------- ----------
T1 TABLE 6291456 768
IDX_T1_CREATED INDEX 2097152 256
计算索引和表的比率:
SYS@anqing2(rac2)> select (2097152/6291456)*100,(256/768)*100 from dual;
(2097152/6291456)*100 (256/768)*100
--------------------- -------------
33.3333333 33.3333333
从bytes 和 blocks 的比率是一样,即索引是表的33%。 那么如果估算表以后的大小是1000M,那么对应的索引大小就是1000M*33%=330M。
把所有表和索引的大小加起来,就是整个数据库大小的估算值。

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

AI Hentai Generator
Generate AI Hentai for free.

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



Go language is an efficient, concise and easy-to-learn programming language. It is favored by developers because of its advantages in concurrent programming and network programming. In actual development, database operations are an indispensable part. This article will introduce how to use Go language to implement database addition, deletion, modification and query operations. In Go language, we usually use third-party libraries to operate databases, such as commonly used sql packages, gorm, etc. Here we take the sql package as an example to introduce how to implement the addition, deletion, modification and query operations of the database. Assume we are using a MySQL database.

Hibernate polymorphic mapping can map inherited classes to the database and provides the following mapping types: joined-subclass: Create a separate table for the subclass, including all columns of the parent class. table-per-class: Create a separate table for subclasses, containing only subclass-specific columns. union-subclass: similar to joined-subclass, but the parent class table unions all subclass columns.

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

HTML cannot read the database directly, but it can be achieved through JavaScript and AJAX. The steps include establishing a database connection, sending a query, processing the response, and updating the page. This article provides a practical example of using JavaScript, AJAX and PHP to read data from a MySQL database, showing how to dynamically display query results in an HTML page. This example uses XMLHttpRequest to establish a database connection, send a query and process the response, thereby filling data into page elements and realizing the function of HTML reading the database.

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())

PHP is a back-end programming language widely used in website development. It has powerful database operation functions and is often used to interact with databases such as MySQL. However, due to the complexity of Chinese character encoding, problems often arise when dealing with Chinese garbled characters in the database. This article will introduce the skills and practices of PHP in handling Chinese garbled characters in databases, including common causes of garbled characters, solutions and specific code examples. Common reasons for garbled characters are incorrect database character set settings: the correct character set needs to be selected when creating the database, such as utf8 or u

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.
