Welcome to dbFreaks.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

Moving tables between tablespaces

 
   Database Help (Home) -> DB2 RSS
Next:  Converting a FM9 table to MySQL View with minimal..  
Author Message
Troels Arvin

External


Since: May 04, 2004
Posts: 42



(Msg. 1) Posted: Mon Aug 18, 2008 7:26 am
Post subject: Moving tables between tablespaces
Archived from groups: comp>databases>ibm-db2 (more info?)

Hello,

How does a use efficiently move a table between tablespaces, given that
the user doesn't have shell access to the server hosting the database?

Is there some built-in routine that the user can execute? - Such as a
function with the following parameters:

admin_move_table(
schemaname,
tablename,
destination_tablespace
)

 >> Stay informed about: Moving tables between tablespaces 
Back to top
Login to vote
Serge Rielau6

External


Since: Oct 04, 2004
Posts: 441



(Msg. 2) Posted: Mon Aug 18, 2008 7:29 am
Post subject: Re: Moving tables between tablespaces [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Troels Arvin wrote:
> Hello,
>
> How does a use efficiently move a table between tablespaces, given that
> the user doesn't have shell access to the server hosting the database?
>
> Is there some built-in routine that the user can execute? - Such as a
> function with the following parameters:
>
> admin_move_table(
> schemaname,
> tablename,
> destination_tablespace
> )
There is no such thing in DB2 for LUW.
The easiest way is to do a CREATE TABLE LIKE followed by a LOAD from
CURSOR, a DROP and finally a RENAME TABLE.

Cheers
Serge

--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab

 >> Stay informed about: Moving tables between tablespaces 
Back to top
Login to vote
Troels Arvin

External


Since: May 04, 2004
Posts: 42



(Msg. 3) Posted: Mon Aug 18, 2008 11:42 am
Post subject: Re: Moving tables between tablespaces [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Serge Rielau wrote:
>> admin_move_table(
>> schemaname,
>> tablename,
>> destination_tablespace
>> )

> There is no such thing in DB2 for LUW.

Sad


> The easiest way is to do a CREATE TABLE LIKE followed by a LOAD from
> CURSOR, a DROP and finally a RENAME TABLE.

Yes, that's also what I told the user to do. However, this will mean
losing indexes, constraints, permissions, and triggers as far as I can see.

--
Troels
 >> Stay informed about: Moving tables between tablespaces 
Back to top
Login to vote
Serge Rielau6

External


Since: Oct 04, 2004
Posts: 441



(Msg. 4) Posted: Mon Aug 18, 2008 11:42 am
Post subject: Re: Moving tables between tablespaces [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Troels Arvin wrote:
> Yes, that's also what I told the user to do. However, this will mean
> losing indexes, constraints, permissions, and triggers as far as I can see.
You can check out the article Kovi pointed to.
It deals with these guys.

Cheers
Serge
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
 >> Stay informed about: Moving tables between tablespaces 
Back to top
Login to vote
Mark A

External


Since: Aug 11, 2008
Posts: 9



(Msg. 5) Posted: Mon Aug 18, 2008 11:42 am
Post subject: Re: Moving tables between tablespaces [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

"Serge Rielau" wrote in message

> Troels Arvin wrote:
>> Yes, that's also what I told the user to do. However, this will mean
>> losing indexes, constraints, permissions, and triggers as far as I can
>> see.
> You can check out the article Kovi pointed to.
> It deals with these guys.
>
> Cheers
> Serge
> --
> Serge Rielau
> DB2 Solutions Development
> IBM Toronto Lab

I am a bit confused by the following statement in the article referenced:

"The composition of the DDL objects is entirely based on the documented
SYSCAT catalog views, with one exception. The high watermark for an IDENTITY
column needs to be retrieved from SYSIBM.SYSSEQUENCES.LASTASSIGNVAL, which
is not exposed in DB2 UDB V8."

Does COPYSCHEMA(<TARGETSCHEMA>,<TARGETTABLESPACEINFO>,<SOURCESCHEMA>) reset
the sequences and/or indentify columns to the same last assinged value as
the source schema? Does the COPYSCHEMA SP work differently in V9.5 versus
V8 in this regard?
 >> Stay informed about: Moving tables between tablespaces 
Back to top
Login to vote
Serge Rielau6

External


Since: Oct 04, 2004
Posts: 441



(Msg. 6) Posted: Mon Aug 18, 2008 11:42 am
Post subject: Re: Moving tables between tablespaces [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Mark A wrote:
> "Serge Rielau" wrote in message
>
>> Troels Arvin wrote:
>>> Yes, that's also what I told the user to do. However, this will mean
>>> losing indexes, constraints, permissions, and triggers as far as I can
>>> see.
>> You can check out the article Kovi pointed to.
>> It deals with these guys.
>>
>> Cheers
>> Serge
>> --
>> Serge Rielau
>> DB2 Solutions Development
>> IBM Toronto Lab
>
> I am a bit confused by the following statement in the article referenced:
>
> "The composition of the DDL objects is entirely based on the documented
> SYSCAT catalog views, with one exception. The high watermark for an IDENTITY
> column needs to be retrieved from SYSIBM.SYSSEQUENCES.LASTASSIGNVAL, which
> is not exposed in DB2 UDB V8."
>
> Does COPYSCHEMA(<TARGETSCHEMA>,<TARGETTABLESPACEINFO>,<SOURCESCHEMA>) reset
> the sequences and/or indentify columns to the same last assinged value as
> the source schema? Does the COPYSCHEMA SP work differently in V9.5 versus
> V8 in this regard?
Yes.... in the same sense as the value is preserved by a
db2stop/db2start. The tool works the same on DB2 V8 and DB2 9.5. It's
just that the column in question wasn't exposed in DB2 V8.

Cheers
Serge


--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
 >> Stay informed about: Moving tables between tablespaces 
Back to top
Login to vote
Gregor_Kovac(

External


Since: Apr 29, 2008
Posts: 6



(Msg. 7) Posted: Mon Aug 18, 2008 1:17 pm
Post subject: Re: Moving tables between tablespaces [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Hi!

Maybe this article an help you.
http://www.ibm.com/developerworks/db2/library/techarticle/dm-0602rielau/

Best regards,
Kovi

Troels Arvin pravi:
> Hello,
>
> How does a use efficiently move a table between tablespaces, given that
> the user doesn't have shell access to the server hosting the database?
>
> Is there some built-in routine that the user can execute? - Such as a
> function with the following parameters:
>
> admin_move_table(
> schemaname,
> tablename,
> destination_tablespace
> )

--
____________________________
|http://kovica.blogspot.com|
-----------------------------~-~-~-~-~-~-~-~-~-~-
| In A World Without Fences Who Needs Gates? |
| Experience Linux. |
-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
 >> Stay informed about: Moving tables between tablespaces 
Back to top
Login to vote
Mark A

External


Since: Aug 11, 2008
Posts: 9



(Msg. 8) Posted: Mon Aug 18, 2008 6:34 pm
Post subject: Re: Moving tables between tablespaces [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

"Serge Rielau" wrote in message

> Yes.... in the same sense as the value is preserved by a db2stop/db2start.
> The tool works the same on DB2 V8 and DB2 9.5. It's just that the column
> in question wasn't exposed in DB2 V8.
>
> Cheers
> Serge
>
> Serge Rielau
> DB2 Solutions Development
> IBM Toronto Lab

I tried using the stored procedure SYSPROC.ADMIN_COPY_SCHEMA to copy a
schema from one name to another in the same database.

1. The proc I executed above is a different stored procedure than mentioned
in the link from this thread. The one I used above comes with DB2 V9.5.

2. When I call the stored procedure, it copies the schema and data (if I use
COPY or COPYNO), but it does not set the identity column last value to the
same values as the source schema, so that upon the first insert into the new
schema there is a duplicate unique constraint error (-803).
 >> Stay informed about: Moving tables between tablespaces 
Back to top
Login to vote
Frank Swarbrick

External


Since: Jan 15, 2008
Posts: 83



(Msg. 9) Posted: Tue Aug 19, 2008 12:37 pm
Post subject: Re: Moving tables between tablespaces [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

>>> On 8/18/2008 at 4:34 PM, in message
, Mark A
wrote:
> "Serge Rielau" wrote in message
>
>> Yes.... in the same sense as the value is preserved by a
> db2stop/db2start.
>> The tool works the same on DB2 V8 and DB2 9.5. It's just that the column

>
>> in question wasn't exposed in DB2 V8.
>>
>> Cheers
>> Serge
>>
>> Serge Rielau
>> DB2 Solutions Development
>> IBM Toronto Lab
>
> I tried using the stored procedure SYSPROC.ADMIN_COPY_SCHEMA to copy a
> schema from one name to another in the same database.
>
> 1. The proc I executed above is a different stored procedure than
> mentioned
> in the link from this thread. The one I used above comes with DB2 V9.5.
>
> 2. When I call the stored procedure, it copies the schema and data (if I
> use
> COPY or COPYNO), but it does not set the identity column last value to
> the
> same values as the source schema, so that upon the first insert into the
> new
> schema there is a duplicate unique constraint error (-803).

As far as I can tell this is "working as designed". However, it could use
some "design improvement" in my opinion. Here is a thread I participated in
in the DB2 Express forum:

http://www.ibm.com/developerworks/forums/thread.jspa?threadID=214937&tstart=
30

Especially look at my post dated Jul 25, 2008 07:36:26 PM and the response
from Raul Chong of IBM on Jul 28, 2008 10:04:17 AM.

What do you think?

Frank
 >> Stay informed about: Moving tables between tablespaces 
Back to top
Login to vote
Mark A

External


Since: Aug 11, 2008
Posts: 9



(Msg. 10) Posted: Tue Aug 19, 2008 3:05 pm
Post subject: Re: Moving tables between tablespaces [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

"Frank Swarbrick" wrote in message

> As far as I can tell this is "working as designed". However, it could use
> some "design improvement" in my opinion. Here is a thread I participated
> in
> in the DB2 Express forum:
>
> http://www.ibm.com/developerworks/forums/thread.jspa?threadID=214937&tstart=
> 30
>
> Especially look at my post dated Jul 25, 2008 07:36:26 PM and the response
> from Raul Chong of IBM on Jul 28, 2008 10:04:17 AM.
>
> What do you think?
>
> Frank


I agree that it is working as designed. When I first used that SP
(SYSPROC.ADMIN_COPY_SCHEMA) I just assumed it would start sequences and
identity columns at 1 (assuming they were initially defined that way) and I
wrote my own script to reset them to the correct values. But I am not sure
if my script below would work correctly on a database that is actively being
used (in my case it was not being used when the script ran, and I stopped
and started the instance before running it).

Note that after I copy the schema with the above stored proc, the original
schema is DB2INST1 and the new one is DB2INST2. After I reset the sequences,
I can then drop the objects in the old schema.

db2 connect to <dbanme>

db2 -x "select 'alter sequence DB2INST2.'||rtrim(SEQNAME)||' restart with ',
cast(NEXTCACHEFIRSTVALUE as int), ';' from syscat.sequences where seqschema
= 'DB2INST1'" > alter_seq.txt

db2 -tvf alter_seq.txt > alter_seq.out
 >> Stay informed about: Moving tables between tablespaces 
Back to top
Login to vote
sanjay kumar

External


Since: May 19, 2010
Posts: 1



(Msg. 11) Posted: Wed May 19, 2010 12:44 pm
Post subject: DB2 9.7 Has this [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Now in DB2 9.7, you can move your tables between tablespaces, and the entire process is online.....



Troels Arvin wrote:

Moving tables between tablespaces
18-Aug-08

Hello,

How does a use efficiently move a table between tablespaces, given that
the user does not have shell access to the server hosting the database?

Is there isome built-in routine that the user can execute? - Such as a
function with the following parameters:

admin_move_table(
schemaname,
tablename,
destination_tablespace
)

Previous Posts In This Thread:

On Monday, August 18, 2008 3:26 AM
Troels Arvin wrote:

Moving tables between tablespaces
Hello,

How does a use efficiently move a table between tablespaces, given that
the user does not have shell access to the server hosting the database?

Is there isome built-in routine that the user can execute? - Such as a
function with the following parameters:

admin_move_table(
schemaname,
tablename,
destination_tablespace
)

On Monday, August 18, 2008 7:17 AM
Gregor_Kovac( wrote:

Hi!
Hi!

Maybe this article an help you.
http://www.ibm.com/developerworks/db2/library/techarticle/dm-0602rielau/

Best regards,
Kovi

Troels Arvin pravi:

--
____________________________
|http://kovica.blogspot.com|
-----------------------------~-~-~-~-~-~-~-~-~-~-
| In A World Without Fences Who Needs Gates? |
| Experience Linux. |
-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-

On Monday, August 18, 2008 7:29 AM
Serge Rielau wrote:

Troels Arvin wrote:There is no such thing in DB2 for LUW.
Troels Arvin wrote:
There is no such thing in DB2 for LUW.
The easiest way is to do a CREATE TABLE LIKE followed by a LOAD from
CURSOR, a DROP and finally a RENAME TABLE.

Cheers
Serge

--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab

On Monday, August 18, 2008 7:42 AM
Troels Arvin wrote:

Serge Rielau wrote:Yes, that is also what I told the user to do.
Serge Rielau wrote:





Yes, that is also what I told the user to do. However, this will mean
losing indexes, constraints, permissions, and triggers as far as I can see.

--
Troels

On Monday, August 18, 2008 8:50 AM
Serge Rielau wrote:

Troels Arvin wrote:You can check out the article Kovi pointed to.
Troels Arvin wrote:
You can check out the article Kovi pointed to.
It deals with these guys.

Cheers
Serge
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab

On Monday, August 18, 2008 10:28 AM
Mark A wrote:

I am a bit confused by the following statement in the article referenced:"The
I am a bit confused by the following statement in the article referenced:

"The composition of the DDL objects is entirely based on the documented
SYSCAT catalog views, with one exception. The high watermark for an IDENTITY
column needs to be retrieved from SYSIBM.SYSSEQUENCES.LASTASSIGNVAL, which
is not exposed in DB2 UDB V8."

Does COPYSCHEMA(<TARGETSCHEMA>,<TARGETTABLESPACEINFO>,<SOURCESCHEMA>) reset
the sequences and/or indentify columns to the same last assinged value as
the source schema? Does the COPYSCHEMA SP work differently in V9.5 versus
V8 in this regard?

On Monday, August 18, 2008 10:53 AM
Serge Rielau wrote:

Mark A wrote:Yes....
Mark A wrote:
Yes.... in the same sense as the value is preserved by a
db2stop/db2start. The tool works the same on DB2 V8 and DB2 9.5. it is
just that the column in question was not exposed in DB2 V8.

Cheers
Serge


--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab

On Monday, August 18, 2008 6:34 PM
Mark A wrote:

I tried using the stored procedure SYSPROC.
I tried using the stored procedure SYSPROC.ADMIN_COPY_SCHEMA to copy a
schema from one name to another in the same database.

1. The proc I executed above is a different stored procedure than mentioned
in the link from this thread. The one I used above comes with DB2 V9.5.

2. When I call the stored procedure, it copies the schema and data (if I use
COPY or COPYNO), but it does not set the identity column last value to the
same values as the source schema, so that upon the first insert into the new
schema there is a duplicate unique constraint error (-803).

On Tuesday, August 19, 2008 2:37 PM
Frank Swarbrick wrote:

wrote:As far as I can tell this is "working as designed".
wrote:


As far as I can tell this is "working as designed". However, it could use
some "design improvement" in my opinion. Here is a thread I participated in
in the DB2 Express forum:

http://www.ibm.com/developerworks/forums/thread.jspa?threadID=214937&tstart=
30

Especially look at my post dated Jul 25, 2008 07:36:26 PM and the response
from Raul Chong of IBM on Jul 28, 2008 10:04:17 AM.

What do you think?

Frank

On Tuesday, August 19, 2008 3:05 PM
Mark A wrote:

I agree that it is working as designed. When I first used that SP(SYSPROC.
I agree that it is working as designed. When I first used that SP
(SYSPROC.ADMIN_COPY_SCHEMA) I just assumed it would start sequences and
identity columns at 1 (assuming they were initially defined that way) and I
wrote my own script to reset them to the correct values. But I am not sure
if my script below would work correctly on a database that is actively being
used (in my case it was not being used when the script ran, and I stopped
and started the instance before running it).

Note that after I copy the schema with the above stored proc, the original
schema is DB2INST1 and the new one is DB2INST2. After I reset the sequences,
I can then drop the objects in the old schema.

db2 connect to <dbanme>

db2 -x "select 'alter sequence DB2INST2.'||rtrim(SEQNAME)||' restart with ',
cast(NEXTCACHEFIRSTVALUE as int), ';' from syscat.sequences where seqschema
= 'DB2INST1'" > alter_seq.txt

db2 -tvf alter_seq.txt > alter_seq.out


Submitted via EggHeadCafe - Software Developer Portal of Choice
Server Side Processing in ADO.NET/WCF Data Services
http://www.eggheadcafe.com/tutorials/aspnet/db179aed-47fa-4f86-a4bf-4f...2a76585
 >> Stay informed about: Moving tables between tablespaces 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
Moving tables to new schema - I currently have 500 tables in 1 single schema. I would like to move 250 out of the 500 tables into a new schema. How is this done? Thanks.

Moving tables between an iSeries and DB2 for Linux - I am attempting to implement, what I believe to be, an unusual scenario, and am hoping to find someone that has experience with something similar. I currently have a series of physical and logical files on an iSeries (AS/400, System i5, or whatever IBM....

Restoring, can't redirect tablespaces - DB2 9.1.3 on Windows. If I take a backup from a system where all DB2 data is on drive D: and try to restore or "create from backup", onto drive E: of another system, I find: - System managed tablespaces can be redirected ok - Database manage...

multiple tablespaces containers on SAN - Hi, i want to know if this is better to split a tablespace into several containers while the database are on san disk. And how can i configure optimally the values for prefetch and extend ? thx

Changes with DB2 version 9 and automatic tablespaces / res.. - I am restoring a database (approximately 1 Terabyte). After the restore started, I noticed that the "list utilities" completed work was not being updated. I checked the location of the restore and watch to see that the size of the table space...
   Database Help (Home) -> DB2 All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]