unable to extend temp segment on CTAS - oracle11gr2

Before i start if someone know a better way to do this please Share as i having massive problems with data pump as it hangs on tablespace and when i check the tablespaces repot i see nothing being filled.
I am trying to CTAS few tables ( create table as select from a#database link) from production to PRE_PRED at the same time.
table sizes are 29 GB, 29GB, 35GB
indexes size are 10GB ,11GB ,13GB
Temp tablespace is 256 GB
tablespace the data is beging copied to has 340 GB.
pseudo code
create table A
compress basic
nologging
nomonitoring
tablespace PRE_PRED.A
parallel (degree defasult instances default)
as select * from B#database link;
i keep getting unable to extend temp segment in PRE_PRED.A tablespace where as i can see there is more than enough space in TEMP and specified tablespace.
the questions please let me know...thanks

The best way to do this is with datapump, which should not be difficult.
First export the tables that you need to a file on the target database server
expdp system dumpfile=MY_TABLES.dmp logfile=MY_TABLES.log exclude=statistics tables=owner.a, owner.b, owner.c
Now copy this file to the source database server and then import the tables, changing the owner and tablespace if needed (if you don't need that remove the remap options).
impdp system dumpfile=MY_TABLES.dmp logfile=MY_TABLES_IMPORT.log tables=owner.a, owner.b, owner.c remap_schema=owner:newowner remap_tablespace=tablespace:newtbspce
This will be faster and have much less load on your network and databases.
You can also just grab the tables with impdb directly from the source database using a database link if you want (but I wouldn't use this myself unless the table was very small and then CTAS would work anyway).
impdp system logfile=MY_TABLES_IMPORT.log tables=owner.a, owner.b, owner.c remap_schema=owner:newowner remap_tablespace=tablespace:newtbspce network_link=dblink

Related

Specify the datafile to create a table partition In a tablespace spanning multiple datafiles

Say that I have two datafiles created on two separate drives (a SSD and a Nomal HDD). I can create a tablespace which will include both the datafiles. In a typical scenario oracle will handle where each schema object for the tablespace will go and manage the storage accordingly.
But i want to take advantage of the the two datafiles in different drives and use the datafile in the SSD for a table partition which contains data i use more frequently and use the datafile in the normal HDD to create the second partition of the same table which will hold data which are not frequently used.
Can this be achieved?
On a side note: Is there any other way to do this other than partitioning?
There is no option to specify datafiles for a partition of a table. Instead we can specify tablespace for a partition. So you can create two different tablespaces, one's datafiles resides in SSD and another's in normal HDD. And you can use these tablespaces as your IO requirements.
Reference

Unallocate unused space in tempdb sql server

any script in sql server to find space used by temporary tables + the database name where that temp table was created in tempdb?
The size of my tempDb has grown up to 100 gb and i am not able to recover the space and am unsure what is occupying so much of space.
Thanks for any help.
Temporary tables always gets created in TempDb. However, it is not necessary that size of TempDb is only due to temporary tables. TempDb is used in various ways
Internal objects (Sort & spool, CTE, index rebuild, hash join etc)
User objects (Temporary table, table variables)
Version store (AFTER/INSTEAD OF triggers, MARS)
So, as it is clear that it is being use in various SQL operations so size can grow due to other reasons also
You can check what is causing TempDb to grow its size with below query
SELECT
SUM (user_object_reserved_page_count)*8 as usr_obj_kb,
SUM (internal_object_reserved_page_count)*8 as internal_obj_kb,
SUM (version_store_reserved_page_count)*8 as version_store_kb,
SUM (unallocated_extent_page_count)*8 as freespace_kb,
SUM (mixed_extent_page_count)*8 as mixedextent_kb
FROM sys.dm_db_file_space_usage
if above query shows,
Higher number of user objects then it means that there is more usage of Temp tables , cursors or temp variables
Higher number of internal objects indicates that Query plan is using a lot of database. Ex: sorting, Group by etc.
Higher number of version stores shows Long running transaction or high transaction throughput
based on that you can configure TempDb file size. I've written an article recently about TempDB configuration best practices. You can read that here
Perhaps you can use following SQL command on temp db files seperately
DBCC SHRINKFILE
Please refer to https://support.microsoft.com/en-us/kb/307487 for more information

When and from Where to call or use temporary tablespace in database

In my project we have used temporary tablespace say X_TEMP ,assume below is tablepsace code , I have found this code in tablespace section
CREATE TEMPORARY TABLESPACE X_TEMP
TEMPFILE '/oradata/mytemp_01.tmp' SIZE 800M
EXTENT MANAGEMENT LOCAL UNIFORM SIZE 1M;
Now I want to check how it is getting called and where I have used this X_TEMP in my procedure,functions,code anywhere where ?
Any idea how can find where We have used it ?
The question doesn't make a whole lot of sense.
Unless you happened to create temporary tables in that tablespace (which would be unusual in Oracle but which would let you tie some usage to particular pieces of code), your user's temporary tablespace (I assume that after creating this temporary tablespace you made it the temporary tablespace for some user) would be used whenever Oracle needed to page data to disk. A query that needs to sort data, for example, might use temporary tablespace. Or it might not, execution to execution, depending on data volumes, how much PGA the session is able to get, the query plan used, etc. Any query this user executes could use temporary tablespace at any time. Or none of its queries might use temporary tablespace because they can all be done in memory. Or they might not use temporary tablespace today and start using it tomorrow because someone else is running some code that limits how much PGA Oracle can give the user's sessions.

DB2 - Reclaiming disk space used by dropped tables

I have an application that logs to a DB2 database. Each log is stored in a daily table, meaning that I have several tables, one per each day.
Since the application is running for quite some time, I dropped some of the older daily tables, but the disk space was not reclaimed.
I understand this is normal in DB2, so I goggled and found out that the following command can be used to reclaim space:
db2 alter tablespace <table space> reduce max
Since the tablespace that store the daily log tables is called USERSPACE1, I executed the following command successfully:
db2 alter tablespace userspace1 reduce max
Unfortunately the disk space used by DB2 instance is still the same...
I've read somewhere that the REORG command can be executed, but what I've seen it is used to reorganize tables. Since I dropped the tables, how can I use REORG?
Is there any other way to do this?
Thanks
Reduce the size of a tablespace is very complex. The extents (set of contiguous pages; unit of tablespace allocation) of the tables are not distributed sequentially for a same table. When you reorg a table, the rows will be organized in pages, and the new pages will be written normally at the end of the tablespace. Sometimes, the high watermark will be increased, and your tablespace will be bigger.
You need to reorg all tables from a tablespace in order to "defrag" all tables. Then, you have to perform a new reorg in order to use the previous space, because it should be an empty space in the tablespace.
However, there are many criteria that impacts the organization of the tables in a tablespace: New extents are created (new rows, rows overflow due to updates); compression could be activated after reorg.
What you can do is to assign few or just one table per tablespace; however, you will waste a lot of space (overhead, empty pages, etc.)
The command that you are using is an automatic way to do that, but it does not always work as desired: http://www-01.ibm.com/support/knowledgecenter/SSEPGG_10.5.0/com.ibm.db2.luw.admin.dbobj.doc/doc/c0055392.html
If you want to see the distribution of the tables in your tablespace, you can use db2dart. Then, you can have an idea of which table to reorg (move).
Sorry guys,
The command that I mentioned on the original post works after all, but the space was retrieved very slowly.
Thanks for the help

Oracle 10g temp tables

I'm trying to convert the permanent tables used in a stored procedure to global temp tables. I've looked at the stats on these permanent tables and some have tens of millions of rows of data and are on the order if gigabytes in size (up to 10 GB).
So,
CREATE TABLE my_table (
column1 NUMBER,
column2 NUMBER,
etc...
)
TABLESPACE BIGTABLESPACE
NOLOGGING
NOCOMPRESS
NOCACHE
NOPARALLEL
MONITORING;
should become
CREATE GLOBAL TEMPORARY TABLE my_table (
column1 NUMBER,
column2 NUMBER,
etc..
)
ON COMMIT PRESERVE ROWS;
I'm creating an equivalent global temporary table with rows that should be preserved until the end of the session for each existing permanent table. This global temp table will be used in the procedure instead of the permanent table.
(EXECUTE IMMEDIATE 'TRUNCATE ...' at the start, and INSERT /*+ APPEND */ INTO at some later point)
All of the permanent tables have been created in a big tablespace BIGTABLESPACE
The Oracle docs state that the global temporary table will be created in the user's temp tablespace (I assume this is TEMP). The problem with this is that the TEMP tablespace is small and the extents are not set to grow to the size I need them to grow during the procedure.
The TEMP tablespace was created during the database creation
create database "$oracle\_sid"
user sys identified by "$sys\_password"
user system identified by "$system\_password"
set default bigfile tablespace
controlfile reuse
maxdatafiles 256
maxinstances $maxinstances
maxlogfiles 16
maxlogmembers 3
maxloghistory 1600
noarchivelog
character set WE8MSWIN1252
national character set AL16UTF16
datafile
'$oracle\_home/oradata/$oracle\_sid/system01.dbf' size 512M
logfile
'$oracle\_home/oradata/$oracle\_sid/redo01.log' size 1G,
'$oracle\_home/oradata/$oracle\_sid/redo02.log' size 1G,
'$oracle\_home/oradata/$oracle\_sid/redo03.log' size 1G
sysaux datafile
'$oracle\_home/oradata/$oracle\_sid/sysaux01.dbf' size 256M
default temporary tablespace temp tempfile
'$oracle\_home/oradata/$oracle\_sid/temp01.dbf' size 5G
undo tablespace "UNDOTBS1" datafile
'$oracle\_home/oradata/$oracle\_sid/undotbs01.dbf' size 5G;
The permanent tables (that I'm planning to replace) were originally created in tablespace BIGTABLESPACE
-- 50G bigfile datafile size
create bigfile tablespace "BIGTABLESPACE"
datafile '$oracle\_home/oradata/$oracle\_sid/bts01.dbf' size 50G
extent management local
segment space management auto;
The permanent table indexes were originally created in tablespace BIGTABLESPACE
-- 20G bigfile datafile size
create bigfile tablespace "BIGINDXSPACE"
datafile '$oracle\_home/oradata/$oracle\_sid/btsindx01.dbf' size 20G
extent management local
segment space management auto;
Is replacing these permanent tables with global temporary tables feasable?
The TEMP tablespace will run into a problem extending the TEMP tablespace. Is there a way to create global temporary tables and their indexes in tablespaces BIGTABLESPACE and BIGINDXSPACE?
If not, how can I make the TEMP tablespace behave like a bigfile tablespace and achieve index/table separation?
Can I create two TEMP bigfile tablespaces and create indexes into one and tables into another?
I want to use global temporary tables, but the volume of data I am handling in the procedure would seem to be above and beyond the indended design of global temporary tables.
Any suggestions?
There is no benefit to separating data and indexes into separate tablespaces other than potentially making DBAs more comfortable that similar objects are grouped together. There is a long-standing myth that separating indexes and data was beneficial for performance reasons-- that is not correct.
Temporary objects should (and must) be stored in a temporary tablespace. You could increase the size of your TEMP tablespace or create a separate temporary tablespace just for the user(s) that will own these objects if you wanted to segregate these large temporary tables into a separate tablespace. You can't (and wouldn't want to) store them in your permanent tablespaces.
Architecturally, though, I would be very curious about why temporary tables were necessary in your system. If you have sessions that are writing 10's of GB into temporary tables, then presumably reading those 10's of GB out again in order to write the data somewhere else, I would tend to suspect that there were more efficient solutions. It is very rare in Oracle to even need temporary tables-- it is far more common in other databases where readers can block writers to need to copy data out of tables before working on it. Oracle has no such limitations.
I don't think that there's anything in your description that makes GTT's unattractive. You obviously need very large temporary tablespaces but you're not consuming more space overall unless you've been making heavy use of table compression (unavailable in GTT's at least up to 10gR2). Look into the use of tablespace groups: http://download.oracle.com/docs/cd/B19306_01/server.102/b14231/tspaces.htm#ADMIN01103
Using a tablespace group, rather than a single temporary tablespace, can alleviate problems caused where one tablespace is inadequate to hold the results of a sort, particularly on a table that has many partitions. A tablespace group enables parallel execution servers in a single parallel operation to use multiple temporary tablespaces.
Also, don't neglect the use of subquery factoring clauses. They can often replace the use of temporary tables. However they might still require just as much temporary storage space because a large result set from a SQFC can spill to disk to avoid the consumption of too much memory, so you still have to go ahead with the increase in TEMP space. They're very handy for not having to deploy a new database object every time you need a new temporary table.
I looked at large sized Global Temporary Tables for a migration exercise. It worked but for debugging and rejection hadling I eventually went with plain tables.
If the GTTs don't work out, consider either Row-Level Security / VPD (or even views).
You can have a column derived from sys_context('USERENV','SESSIONID') and use that to ensure that the user can only see their own data.
Still the thought of multiple sessions dealing with multi-gigabyte datasets concurrently is a bit scary.
PS. I believe that for GTTs used through a procedure use the temp tablespace of the session user rather than the temp tablespace of the procedure owner. If you can get the sessions as separate oracle users then you have a chance at spreading your file IO over different tablespaces.

Resources