How to find out which object is taking space?Find out which columns must be specified in insert-statementHow can I find out which statistics are evaluated by the optimizer?Database running out of spaceHow to find out the account(s) under which the sql server is running?Incremental statistics: find out which partitions have been resampledHow to find the specific file in a filegroup in which an object residesHow to find out which records are causing an exception in a select statement?Find uncompressed size of all tables in a databaseClustered Index taking huge amount of spaceHow to find out which table/object the KEY or PAGE or EXTENT locks in the sys.dm_tran_locks belong to?
How can I get 2 characters to bond while standing alternate watches?
What happen if some blocks are added simultaneously with same previous hash
Eating Titan's oceans
I am ask to complete my withdrawal transaction with COT fee of 1200 dollars
Partial Relaxation
Is it principled to tip less if a pricey restaurant doesn't accept Visa or Mastercard?
Is there a word/short phrase for "the most" of something (not necessarily the majority)?
Anvil or by-pass pruner?
In a piece for piano and vocals, when I move the vocal part down an octave do I also need to move the piano part down an octave?
Do multimedia speaker systems run on AC power rather than DC?
Is it possible to kill parasitic worms by intoxicating oneself?
What kind of electrical connector is this and how do I remove it?
How to get a bowl with one liter of water
USA fingerprint on arrival
Could the barycenter orbit of our sun be greatly underestimated?
How can I open or identify this lamp?
Is paying for portrait photos good for the people in the community you're photographing?
How to deal with this fundamental problem with the advice: "Don't trust obscure PHP libraries that nobody uses!"?
Advent calendar
Why one result is so wide in this logistic multiple regession
How to view register contents on the PDP-11 console?
Can homotopy colimits recover cohomology sheaves?
Pass on your radiation
Are all red twi'leks dark jedi Twi'leks and vice versa?
How to find out which object is taking space?
Find out which columns must be specified in insert-statementHow can I find out which statistics are evaluated by the optimizer?Database running out of spaceHow to find out the account(s) under which the sql server is running?Incremental statistics: find out which partitions have been resampledHow to find the specific file in a filegroup in which an object residesHow to find out which records are causing an exception in a select statement?Find uncompressed size of all tables in a databaseClustered Index taking huge amount of spaceHow to find out which table/object the KEY or PAGE or EXTENT locks in the sys.dm_tran_locks belong to?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty
margin-bottom:0;
I have database of size 537gb. How can I find out which object is taking space.
I executed sp_spaceused, which showed me unallocated space is 502GB and 88GB used space. How can I release unallocated space to get some free space. My HDD is getting full due to this. Please advise.
Edit: I have checked via below script as well. But total UsedSpaceMB of each table is 47GB. Still I am unable to figure out how DB size is 537 GB.
SELECT t.NAME AS TableName, s.Name AS SchemaName, p.rows AS RowCounts, SUM(a.total_pages) * 8 AS TotalSpaceKB, CAST(ROUND(((SUM(a.total_pages) * 8) / 1024.00), 2) AS NUMERIC(36, 2)) AS TotalSpaceMB, SUM(a.used_pages) * 8 AS UsedSpaceKB, CAST(ROUND(((SUM(a.used_pages) * 8) / 1024.00), 2) AS NUMERIC(36, 2)) AS UsedSpaceMB, (SUM(a.total_pages) - SUM(a.used_pages)) * 8 AS UnusedSpaceKB, CAST(ROUND(((SUM(a.total_pages) - SUM(a.used_pages)) * 8) / 1024.00, 2) AS NUMERIC(36, 2)) AS UnusedSpaceMB
FROM sys.tables t
INNER JOIN sys.indexes i
ON t.OBJECT_ID = i.object_id
INNER JOIN sys.partitions p
ON i.object_id = p.OBJECT_ID
AND i.index_id = p.index_id
INNER JOIN sys.allocation_units a
ON p.partition_id = a.container_id
LEFT OUTER JOIN sys.schemas s
ON t.schema_id = s.schema_id
WHERE t.NAME NOT LIKE 'dt%'
AND t.is_ms_shipped = 0
AND i.OBJECT_ID > 255
GROUP BY t.Name, s.Name, p.Rows
ORDER BY 7 DESC
sql-server
add a comment
|
I have database of size 537gb. How can I find out which object is taking space.
I executed sp_spaceused, which showed me unallocated space is 502GB and 88GB used space. How can I release unallocated space to get some free space. My HDD is getting full due to this. Please advise.
Edit: I have checked via below script as well. But total UsedSpaceMB of each table is 47GB. Still I am unable to figure out how DB size is 537 GB.
SELECT t.NAME AS TableName, s.Name AS SchemaName, p.rows AS RowCounts, SUM(a.total_pages) * 8 AS TotalSpaceKB, CAST(ROUND(((SUM(a.total_pages) * 8) / 1024.00), 2) AS NUMERIC(36, 2)) AS TotalSpaceMB, SUM(a.used_pages) * 8 AS UsedSpaceKB, CAST(ROUND(((SUM(a.used_pages) * 8) / 1024.00), 2) AS NUMERIC(36, 2)) AS UsedSpaceMB, (SUM(a.total_pages) - SUM(a.used_pages)) * 8 AS UnusedSpaceKB, CAST(ROUND(((SUM(a.total_pages) - SUM(a.used_pages)) * 8) / 1024.00, 2) AS NUMERIC(36, 2)) AS UnusedSpaceMB
FROM sys.tables t
INNER JOIN sys.indexes i
ON t.OBJECT_ID = i.object_id
INNER JOIN sys.partitions p
ON i.object_id = p.OBJECT_ID
AND i.index_id = p.index_id
INNER JOIN sys.allocation_units a
ON p.partition_id = a.container_id
LEFT OUTER JOIN sys.schemas s
ON t.schema_id = s.schema_id
WHERE t.NAME NOT LIKE 'dt%'
AND t.is_ms_shipped = 0
AND i.OBJECT_ID > 255
GROUP BY t.Name, s.Name, p.Rows
ORDER BY 7 DESC
sql-server
add a comment
|
I have database of size 537gb. How can I find out which object is taking space.
I executed sp_spaceused, which showed me unallocated space is 502GB and 88GB used space. How can I release unallocated space to get some free space. My HDD is getting full due to this. Please advise.
Edit: I have checked via below script as well. But total UsedSpaceMB of each table is 47GB. Still I am unable to figure out how DB size is 537 GB.
SELECT t.NAME AS TableName, s.Name AS SchemaName, p.rows AS RowCounts, SUM(a.total_pages) * 8 AS TotalSpaceKB, CAST(ROUND(((SUM(a.total_pages) * 8) / 1024.00), 2) AS NUMERIC(36, 2)) AS TotalSpaceMB, SUM(a.used_pages) * 8 AS UsedSpaceKB, CAST(ROUND(((SUM(a.used_pages) * 8) / 1024.00), 2) AS NUMERIC(36, 2)) AS UsedSpaceMB, (SUM(a.total_pages) - SUM(a.used_pages)) * 8 AS UnusedSpaceKB, CAST(ROUND(((SUM(a.total_pages) - SUM(a.used_pages)) * 8) / 1024.00, 2) AS NUMERIC(36, 2)) AS UnusedSpaceMB
FROM sys.tables t
INNER JOIN sys.indexes i
ON t.OBJECT_ID = i.object_id
INNER JOIN sys.partitions p
ON i.object_id = p.OBJECT_ID
AND i.index_id = p.index_id
INNER JOIN sys.allocation_units a
ON p.partition_id = a.container_id
LEFT OUTER JOIN sys.schemas s
ON t.schema_id = s.schema_id
WHERE t.NAME NOT LIKE 'dt%'
AND t.is_ms_shipped = 0
AND i.OBJECT_ID > 255
GROUP BY t.Name, s.Name, p.Rows
ORDER BY 7 DESC
sql-server
I have database of size 537gb. How can I find out which object is taking space.
I executed sp_spaceused, which showed me unallocated space is 502GB and 88GB used space. How can I release unallocated space to get some free space. My HDD is getting full due to this. Please advise.
Edit: I have checked via below script as well. But total UsedSpaceMB of each table is 47GB. Still I am unable to figure out how DB size is 537 GB.
SELECT t.NAME AS TableName, s.Name AS SchemaName, p.rows AS RowCounts, SUM(a.total_pages) * 8 AS TotalSpaceKB, CAST(ROUND(((SUM(a.total_pages) * 8) / 1024.00), 2) AS NUMERIC(36, 2)) AS TotalSpaceMB, SUM(a.used_pages) * 8 AS UsedSpaceKB, CAST(ROUND(((SUM(a.used_pages) * 8) / 1024.00), 2) AS NUMERIC(36, 2)) AS UsedSpaceMB, (SUM(a.total_pages) - SUM(a.used_pages)) * 8 AS UnusedSpaceKB, CAST(ROUND(((SUM(a.total_pages) - SUM(a.used_pages)) * 8) / 1024.00, 2) AS NUMERIC(36, 2)) AS UnusedSpaceMB
FROM sys.tables t
INNER JOIN sys.indexes i
ON t.OBJECT_ID = i.object_id
INNER JOIN sys.partitions p
ON i.object_id = p.OBJECT_ID
AND i.index_id = p.index_id
INNER JOIN sys.allocation_units a
ON p.partition_id = a.container_id
LEFT OUTER JOIN sys.schemas s
ON t.schema_id = s.schema_id
WHERE t.NAME NOT LIKE 'dt%'
AND t.is_ms_shipped = 0
AND i.OBJECT_ID > 255
GROUP BY t.Name, s.Name, p.Rows
ORDER BY 7 DESC
sql-server
sql-server
edited Oct 1 at 7:47
Muhammad Ali Khamis
asked Oct 1 at 7:26
Muhammad Ali KhamisMuhammad Ali Khamis
2091 silver badge7 bronze badges
2091 silver badge7 bronze badges
add a comment
|
add a comment
|
3 Answers
3
active
oldest
votes
It appears that your database data file has empty space.
If you know for sure that the data file will not grow out again, you could shrink the file.
If you have to shrink, the cleanest way is doing this with TRUNCATEONLY
so you don't move any data pages and only release the space back to the OS if it is possible.
You can get the data file(s) with this query, change the databasename to your database.
SELECT [name]
FROM sys.master_files
WHERE database_id = db_id('DatabaseName')
AND type_desc = 'ROWS';
Afterwards you could try shrinking the data page until 100GB without any movement.
Use [DatabaseName]
GO
DBCC SHRINKFILE ('name',102400 ,TRUNCATEONLY);
-- try to shrink until 100GB, without moving data pages
You can read up on shrinking date files and...
- why it sucks here
- why it's bad for performance here
add a comment
|
You can use a script something like this to find tables and their sizes:
SELECT name = OBJECT_SCHEMA_NAME(object_id) + '.' + OBJECT_NAME(object_id),
rows = SUM(CASE
WHEN index_id < 2
THEN row_count
ELSE 0
END),
reserved_mb = 8 * SUM(reserved_page_count) / 1024,
data_mb = 8 * SUM(CASE
WHEN index_id < 2
THEN in_row_data_page_count + lob_used_page_count + row_overflow_used_page_count
ELSE lob_used_page_count + row_overflow_used_page_count
END) / 1024,
index_mb = 8 * (SUM(used_page_count) - SUM(CASE
WHEN index_id < 2
THEN in_row_data_page_count + lob_used_page_count + row_overflow_used_page_count
ELSE lob_used_page_count + row_overflow_used_page_count
END)) / 1024,
unused_mb = 8 * SUM(reserved_page_count - used_page_count) / 1024
FROM sys.dm_db_partition_stats
WHERE object_id > 1024
GROUP BY object_id
ORDER BY reserved_mb DESC;
I have updated. Please check now.
– Muhammad Ali Khamis
Oct 1 at 7:49
add a comment
|
The fastest and simplest way is using a standard report.
Right click on the database:
add a comment
|
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "182"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f249978%2fhow-to-find-out-which-object-is-taking-space%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
It appears that your database data file has empty space.
If you know for sure that the data file will not grow out again, you could shrink the file.
If you have to shrink, the cleanest way is doing this with TRUNCATEONLY
so you don't move any data pages and only release the space back to the OS if it is possible.
You can get the data file(s) with this query, change the databasename to your database.
SELECT [name]
FROM sys.master_files
WHERE database_id = db_id('DatabaseName')
AND type_desc = 'ROWS';
Afterwards you could try shrinking the data page until 100GB without any movement.
Use [DatabaseName]
GO
DBCC SHRINKFILE ('name',102400 ,TRUNCATEONLY);
-- try to shrink until 100GB, without moving data pages
You can read up on shrinking date files and...
- why it sucks here
- why it's bad for performance here
add a comment
|
It appears that your database data file has empty space.
If you know for sure that the data file will not grow out again, you could shrink the file.
If you have to shrink, the cleanest way is doing this with TRUNCATEONLY
so you don't move any data pages and only release the space back to the OS if it is possible.
You can get the data file(s) with this query, change the databasename to your database.
SELECT [name]
FROM sys.master_files
WHERE database_id = db_id('DatabaseName')
AND type_desc = 'ROWS';
Afterwards you could try shrinking the data page until 100GB without any movement.
Use [DatabaseName]
GO
DBCC SHRINKFILE ('name',102400 ,TRUNCATEONLY);
-- try to shrink until 100GB, without moving data pages
You can read up on shrinking date files and...
- why it sucks here
- why it's bad for performance here
add a comment
|
It appears that your database data file has empty space.
If you know for sure that the data file will not grow out again, you could shrink the file.
If you have to shrink, the cleanest way is doing this with TRUNCATEONLY
so you don't move any data pages and only release the space back to the OS if it is possible.
You can get the data file(s) with this query, change the databasename to your database.
SELECT [name]
FROM sys.master_files
WHERE database_id = db_id('DatabaseName')
AND type_desc = 'ROWS';
Afterwards you could try shrinking the data page until 100GB without any movement.
Use [DatabaseName]
GO
DBCC SHRINKFILE ('name',102400 ,TRUNCATEONLY);
-- try to shrink until 100GB, without moving data pages
You can read up on shrinking date files and...
- why it sucks here
- why it's bad for performance here
It appears that your database data file has empty space.
If you know for sure that the data file will not grow out again, you could shrink the file.
If you have to shrink, the cleanest way is doing this with TRUNCATEONLY
so you don't move any data pages and only release the space back to the OS if it is possible.
You can get the data file(s) with this query, change the databasename to your database.
SELECT [name]
FROM sys.master_files
WHERE database_id = db_id('DatabaseName')
AND type_desc = 'ROWS';
Afterwards you could try shrinking the data page until 100GB without any movement.
Use [DatabaseName]
GO
DBCC SHRINKFILE ('name',102400 ,TRUNCATEONLY);
-- try to shrink until 100GB, without moving data pages
You can read up on shrinking date files and...
- why it sucks here
- why it's bad for performance here
edited Oct 1 at 8:49
answered Oct 1 at 8:02
Randi VertongenRandi Vertongen
13k3 gold badges16 silver badges41 bronze badges
13k3 gold badges16 silver badges41 bronze badges
add a comment
|
add a comment
|
You can use a script something like this to find tables and their sizes:
SELECT name = OBJECT_SCHEMA_NAME(object_id) + '.' + OBJECT_NAME(object_id),
rows = SUM(CASE
WHEN index_id < 2
THEN row_count
ELSE 0
END),
reserved_mb = 8 * SUM(reserved_page_count) / 1024,
data_mb = 8 * SUM(CASE
WHEN index_id < 2
THEN in_row_data_page_count + lob_used_page_count + row_overflow_used_page_count
ELSE lob_used_page_count + row_overflow_used_page_count
END) / 1024,
index_mb = 8 * (SUM(used_page_count) - SUM(CASE
WHEN index_id < 2
THEN in_row_data_page_count + lob_used_page_count + row_overflow_used_page_count
ELSE lob_used_page_count + row_overflow_used_page_count
END)) / 1024,
unused_mb = 8 * SUM(reserved_page_count - used_page_count) / 1024
FROM sys.dm_db_partition_stats
WHERE object_id > 1024
GROUP BY object_id
ORDER BY reserved_mb DESC;
I have updated. Please check now.
– Muhammad Ali Khamis
Oct 1 at 7:49
add a comment
|
You can use a script something like this to find tables and their sizes:
SELECT name = OBJECT_SCHEMA_NAME(object_id) + '.' + OBJECT_NAME(object_id),
rows = SUM(CASE
WHEN index_id < 2
THEN row_count
ELSE 0
END),
reserved_mb = 8 * SUM(reserved_page_count) / 1024,
data_mb = 8 * SUM(CASE
WHEN index_id < 2
THEN in_row_data_page_count + lob_used_page_count + row_overflow_used_page_count
ELSE lob_used_page_count + row_overflow_used_page_count
END) / 1024,
index_mb = 8 * (SUM(used_page_count) - SUM(CASE
WHEN index_id < 2
THEN in_row_data_page_count + lob_used_page_count + row_overflow_used_page_count
ELSE lob_used_page_count + row_overflow_used_page_count
END)) / 1024,
unused_mb = 8 * SUM(reserved_page_count - used_page_count) / 1024
FROM sys.dm_db_partition_stats
WHERE object_id > 1024
GROUP BY object_id
ORDER BY reserved_mb DESC;
I have updated. Please check now.
– Muhammad Ali Khamis
Oct 1 at 7:49
add a comment
|
You can use a script something like this to find tables and their sizes:
SELECT name = OBJECT_SCHEMA_NAME(object_id) + '.' + OBJECT_NAME(object_id),
rows = SUM(CASE
WHEN index_id < 2
THEN row_count
ELSE 0
END),
reserved_mb = 8 * SUM(reserved_page_count) / 1024,
data_mb = 8 * SUM(CASE
WHEN index_id < 2
THEN in_row_data_page_count + lob_used_page_count + row_overflow_used_page_count
ELSE lob_used_page_count + row_overflow_used_page_count
END) / 1024,
index_mb = 8 * (SUM(used_page_count) - SUM(CASE
WHEN index_id < 2
THEN in_row_data_page_count + lob_used_page_count + row_overflow_used_page_count
ELSE lob_used_page_count + row_overflow_used_page_count
END)) / 1024,
unused_mb = 8 * SUM(reserved_page_count - used_page_count) / 1024
FROM sys.dm_db_partition_stats
WHERE object_id > 1024
GROUP BY object_id
ORDER BY reserved_mb DESC;
You can use a script something like this to find tables and their sizes:
SELECT name = OBJECT_SCHEMA_NAME(object_id) + '.' + OBJECT_NAME(object_id),
rows = SUM(CASE
WHEN index_id < 2
THEN row_count
ELSE 0
END),
reserved_mb = 8 * SUM(reserved_page_count) / 1024,
data_mb = 8 * SUM(CASE
WHEN index_id < 2
THEN in_row_data_page_count + lob_used_page_count + row_overflow_used_page_count
ELSE lob_used_page_count + row_overflow_used_page_count
END) / 1024,
index_mb = 8 * (SUM(used_page_count) - SUM(CASE
WHEN index_id < 2
THEN in_row_data_page_count + lob_used_page_count + row_overflow_used_page_count
ELSE lob_used_page_count + row_overflow_used_page_count
END)) / 1024,
unused_mb = 8 * SUM(reserved_page_count - used_page_count) / 1024
FROM sys.dm_db_partition_stats
WHERE object_id > 1024
GROUP BY object_id
ORDER BY reserved_mb DESC;
answered Oct 1 at 7:40
George KGeorge K
2,0219 silver badges20 bronze badges
2,0219 silver badges20 bronze badges
I have updated. Please check now.
– Muhammad Ali Khamis
Oct 1 at 7:49
add a comment
|
I have updated. Please check now.
– Muhammad Ali Khamis
Oct 1 at 7:49
I have updated. Please check now.
– Muhammad Ali Khamis
Oct 1 at 7:49
I have updated. Please check now.
– Muhammad Ali Khamis
Oct 1 at 7:49
add a comment
|
The fastest and simplest way is using a standard report.
Right click on the database:
add a comment
|
The fastest and simplest way is using a standard report.
Right click on the database:
add a comment
|
The fastest and simplest way is using a standard report.
Right click on the database:
The fastest and simplest way is using a standard report.
Right click on the database:
answered Oct 1 at 7:51
Denis RubashkinDenis Rubashkin
1,3991 silver badge10 bronze badges
1,3991 silver badge10 bronze badges
add a comment
|
add a comment
|
Thanks for contributing an answer to Database Administrators Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f249978%2fhow-to-find-out-which-object-is-taking-space%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown