找出表空间上的可用空间
我们的应用程序因“ORA-01536:超出表空间的空间配额”而失败了几次,我们希望能够通过定期检查表空间上的可用空间并在其低于特定水平时发出警报来防止这种情况发生。
有什么方法可以找出表空间中剩余多少可用空间?
经过一些研究(我不是 DBA),我尝试了以下操作:
select max_bytes-bytes from user_ts_quotas;
select sum(nvl(bytes,0)) from user_free_space;
但这些查询返回完全不同的结果。
Our application has failed a few times because an 'ORA-01536: space quota exceeded for tablespace', and we would like to be able to prevent this by checking regularly the free space on the tablespace and raising an alert when it drops below certain level.
Is there any way to find out how much free space is left in a tablespace?
After some research (I am not a DBA), I tried the following:
select max_bytes-bytes from user_ts_quotas;
select sum(nvl(bytes,0)) from user_free_space;
but those queries return completely different results.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(12)
我用这个查询
I use this query
更准确的 SQL 语句
A much more accurate SQL STATEMENT
有很多方法可以检查大小,但作为开发人员,我们没有太多权限查询元表,我发现这个解决方案非常简单
(注意:如果您收到错误消息 ORA-01653
“ORA-01653 错误是因为您需要向表空间添加空间而引起的。”)
谢谢
There are many ways to check the size, but as a developer we dont have much access to query meta tables, I find this solution very easy
(Note: if you are getting error message ORA-01653
‘The ORA-01653 error is caused because you need to add space to a tablespace.’)
Thanks
这是我遇到的最简单的查询之一,我们也用它来监控:
一篇关于 Oracle 表空间的完整文章:
表空间
This is one of the simplest query for the same that I came across and we use it for monitoring as well:
A complete article about Oracle Tablespace:
Tablespace
这也很不错
输出
this is pretty good as well
output
以下查询将有助于找出表空间的可用空间(以 MB 为单位):
The following query will help to find out free space of tablespaces in MB:
您可以通过以下方式检查表空间可用空间:运行此查询:
在上面的查询中,我们选择了每个表空间的总大小以及以 MB 为单位的可用空间以及以总大小百分比表示的可用空间。因此,您可以使用此百分比列来跟踪并在可用空间百分比达到 20% 或您想要的任何百分比时发出警报。
You can check the tablespace free space by running this query :
In above query we have selected the total size of each tablespace as well as the free space in MB and the free space in percentage from the total size. So you can use this percentage column to track and raising an alert when the free space percentage reachs 20% or whatever the percentage you want to be.
除非我弄错了,否则上面的代码不会考虑未分配的空间,因此如果您确实想知道何时会达到硬限制,则应该使用 maxbytes。
我认为下面的代码可以做到这一点。它将可用空间计算为“可用空间”+未分配空间。
Unless I'm mistaken, the above code does not take unallocated space into account, so if you really want to know when you'll hit a hard limit, you should use maxbytes.
I think the code below does that. It calculates free space as "freespace" + unallocated space.
以下是 Oracle SQL Developer 在其表空间视图中使用的查询
Here is a query used by Oracle SQL Developer in its Tablespaces view
您还可以通过查看磁盘上文件的大小来粗略了解表空间的使用情况。
我的数据库是用最大范围创建的,每个 dbf 文件只能增长到 32gigs - 所以当最后一个达到 32gigs 时,您知道您即将用完空间并需要添加另一个。
You can also get a rough idea of table space usage by looking at the size of the files on your disk.
My DB is created with max extents, and each dbf file can only grow to 32gigs - so when the last one reaches 32gigs, you know you're about to run out of room and need to add another.
您可以在这个有用的包中使用名为 tablespaces.sh 的脚本:
http://dba-tips.blogspot.com/2014 /02/oracle-database-administration-scripts.html
You can use a script called tablespaces.sh inside this helpful bundle:
http://dba-tips.blogspot.com/2014/02/oracle-database-administration-scripts.html