ORACLE SQLSERVER and query the database file size

SQLSERVER:

SQLSERVER library file into a data file (line data) and log files two files, the details can attribute database -> File View.

 

Open the path to the file in Explorer, you can see both files directly

 

However, most of the time our database is installed on a remote server, without the remote, you can use the following SQL statement:

1, the query remaining space of each disk partition (that is, how much disk space C, D drive, how many ...):

Exec master.dbo.xp_fixeddrives

2, the related information query the database data file and the log file (including document, the current file size, file maximum file growth set, the logical file name, file path, etc.):

. select * from [database name] [dbo] [sysfiles]. 
- convert the file size in units of MB: 
. the SELECT name, Convert For (float, size) * (8192.0 / 1024.0) / 1024 from [database name] .dbo. sysfiles

3, check the current disk usage of the database:

Exec sp_spaceused

database_size: Database size (that is, the size of the data files and log), which is above the value of the added size (in terms of mega bytes)

unallocated space: unallocated space.

4, query size and utilization of database server log files each database:

DBCC SQLPERF(LOGSPACE)

5, view the data file occupies (the larger the required permissions):

DBCC showfilestats  

6, a comprehensive SQL:

复制代码
SELECT a.name [文件名称]  
    ,cast(a.[size]*1.0/128 as decimal(12,1)) AS [文件设置大小(MB)]  
    ,CAST( fileproperty(s.name,'SpaceUsed')/(8*16.0) AS DECIMAL(12,1)) AS [文件所占空间(MB)]  
    ,CAST( (fileproperty(s.name,'SpaceUsed')/(8*16.0))/(s.size/(8*16.0))*100.0  AS DECIMAL(12,1)) AS [所占空间率%]  
    ,CASE WHEN A.growth =0 THEN '文件大小固定,不会增长' ELSE '文件将自动增长' end [增长模式]  
    ,CASE WHEN A.growth > 0 AND is_percent_growth = 0 THEN '增量为固定大小'  
        WHEN A.growth > 0 AND is_percent_growth = 1 THEN '增量将用整数百分比表示'  
        ELSE '文件大小固定,不会增长' END AS [增量模式]  
    ,CASE WHEN A.growth > 0 AND is_percent_growth = 0 THEN cast(cast(a.growth*1.0/128as decimal(12,0)) AS VARCHAR)+'MB'  
        WHEN A.growth > 0 AND is_percent_growth = 1 THEN cast(cast(a.growth AS decimal(12,0)) AS VARCHAR)+'%'  
        ELSE '文件大小固定,不会增长' end AS [增长值(%或MB)]  
    ,a.physical_name AS [文件所在目录]  
    ,a.type_desc AS [文件类型]  
FROM sys.database_files  a  
INNER JOIN sys.sysfiles AS s ON a.[file_id]=s.fileid  
LEFT JOIN sys.dm_db_file_space_usage b ON a.[file_id]=b.[file_id]  
复制代码

其中的文件设置大小就是该数据库的文件大小

ORACLE:

在PL/SQL中我没有找到有关于数据库文件的信息,有可能还没找到吧。所以直接采用查询的方式

1、SYS.DBA_DATA_FILES:

select * from dba_data_files;

这边的FILE_NAME就是文件路径,BYTES就是所占空间了。

根据这个路径找到数据文件:

2、一个全面的SQL:

按 Ctrl+C 复制代码
按 Ctrl+C 复制代码

Guess you like

Origin www.cnblogs.com/Jeely/p/11386881.html