Dealing with ORA-01652

As I'm not terribly familiar with Oracle (I'm working to learn more) I ran into this particular error code which had me confused as to the cause. Eventually we narrowed down the cause and have a better idea as to why and I'll try my best to explain here. At least in my particular project. There may be differences on other environments. I'm still learning so hopefully there's no inaccuracies. Anyway when you run across the error it likely shows up like this:

ORA-1652: unable to extend temp segment by 128 in tablespace TEMP

On the surface you'd assume you're running out of space from somewhere and that's more or less in the right direction. If you're running into this error often you probably have some very expensive queries being executed far too often for the database itself to keep up. In this particular case "TEMP" - the temporary tablespace is being used up. The database uses this space for various operations most likely joins. I don't know if they are used in COUNT()s but they were the most problematic in my case. If your queries are performing complex joins with massive result sets and they occur too often you're probably going to run into this issue.

In conclusion, check your queries. You'll want to investigate joins on very large tables that are not employing indexes. That would most likely drive the tablespace to get filled up very quickly especially if these are queries that are being called more often than the database can handle. I'm no DBA so do not know the best methods to identify those. However I think this article right here can help.