I have been dealing with oracle database for two days due to work reasons, and I have stepped on many holes. Now I want to write some thoughts and share them with you. There are some incorrect points. Please correct them!
1. Query tablespace information
select * from dba_tablespaces
2. View the relationship between users and tablespaces
select username,default_tablespace from user_users;
3. Query table space size, surplus, utilization, including temporary table space
SELECT
*
FROM
(
SELECT
A .tablespace_name,
TO_CHAR (
A .bytes / 1024 / 1024,
'99,999.999'
) total_bytes,
TO_CHAR (
b.bytes / 1024 / 1024,
'99,999.999'
) free_bytes,
TO_CHAR (
A .bytes / 1024 / 1024 - b.bytes / 1024 / 1024,
'99,999.999'
) use_bytes,
TO_CHAR (
(1 - b.bytes / A .bytes) * 100,
'99.99'
) || '%' USE
FROM
(
SELECT
tablespace_name,
SUM (bytes) bytes
FROM
dba_data_files
GROUP BY
tablespace_name
) A,
(
SELECT
tablespace_name,
SUM (bytes) bytes
FROM
dba_free_space
GROUP BY
tablespace_name
) b
WHERE
A .tablespace_name = b.tablespace_name
UNION ALL
SELECT
c.tablespace_name,
TO_CHAR (
c.bytes / 1024 / 1024,
'99,999.999'
) total_bytes,
TO_CHAR (
(c.bytes - D .bytes_used) / 1024 / 1024,
'99,999.999'
) free_bytes,
TO_CHAR (
D .bytes_used / 1024 / 1024,
'99,999.999'
) use_bytes,
TO_CHAR (
D .bytes_used * 100 / c.bytes,
'99.99'
) || '%' USE
FROM
(
SELECT
tablespace_name,
SUM (bytes) bytes
FROM
dba_temp_files
GROUP BY
tablespace_name
) c,
(
SELECT
tablespace_name,
SUM (bytes_cached) bytes_used
FROM
v$temp_extent_pool
GROUP BY
tablespace_name
) D
WHERE
c.tablespace_name = D .tablespace_name
)
4. Expand temporary tablespace capacity
alter database tempfile 'tempFilePath' resize 2048M;
5. Expand tablespace capacity
alter database datafile 'filePath' resize 4000m
6. Query tablespace file path, including temporary tablespace
SELECT TABLESPACE_NAME, FILE_ID, FILE_NAME, BYTES/1024/1024 AS "BYTES(M)"
FROM DBA_DATA_FILES
SELECT TABLESPACE_NAME, FILE_ID, FILE_NAME, BYTES/1024/1024 AS "SPACE(M)"
FROM DBA_TEMP_FILES
7. Query the table size of the table space
Select Segment_Name,Sum(bytes)/1024/1024 From User_Extents Group By Segment_Name