Partitioning of sj_arkiv

If the tablespaces that is used by the WorkZone archive has reached its maximum size, it is possible to partition the sj_arkiv.archive_doc and sj_arkiv.archive_doc_info tables, if you use Oracle Enterprise with the Oracle partitioning option enabled. As an example, the maxium size for an 8 Kbytes block tablespace, is 32 Terabyte.

Note that in most organizations, it is only a database administrator who can perform this task.

To partition sj_arkiv.archive_doc and sj_arkiv.archive_doc_info tables, complete the steps below:

  1. Find the highest document ID.

  2. Create two new tablespaces.

  3. Run scripts:

    • Alter_sj_arkiv.sql

    • Part_doc_info.sql

    • Part_doc.sql

    • sequence.sql

    • Set_sj_arkiv_pwd.sql

Important: The partitioning must take place at a time when there are no users on the system, and there must be a backup/restore point.

Find the highest document ID

First, you need to find max doc_id from the sj_arkiv.archive_doc table and the sj_arkiv.archive_doc_info table. Use the following SQL command:

select max(doc_id) from sj_arkiv.archive_doc;

select max(doc_id) from sj_arkiv.archive_doc_info;

Kopibilledet mangler

The command should return the same number. Round the number up to nearest 100. This number is now called <p_doc_id>.

Create two new tablespaces

Create a tablespace that corresponds to the tablespace that the sj_arkiv.archive_doc_info and sj_arkiv.archive_doc tables are located in. Use the following SQL command:

select segment_name, tablespace_name from sys.dba_segments where owner = 'SJ_ARKIV' and segment_type = 'TABLE';

Kopibilledet mangler

Next, create a tablespace that corresponds to the LOB (large objects) tablespace for sj_arkiv.archive_doc. Use the following SQL command:

select table_name, segment_name, tablespace_name from sys.dba_lobs where owner = 'SJ_ARKIV' and table_name = 'ARCHIVE_DOC';

Kopibilledet mangler

The two tablespaces will be used to save data for the new partition.

To avoid that data is moved, the creation of partitions must be done with the use of ”exchange partition”.

Run scripts

The table below describes the scripts to execute in SQL*Plus and by which system user. The scripts must be executed in the same order as listed in the table. Note that the scripts must be customized to match your organization, see the Customizatons column. Click the script name to see the script.

Order Script Ensures that.. Executed by Customizations

1

Alter_sj_arkiv.sql

The password of the sj_arkiv table is set to sj_arkiv and that the user named sj_arkiv gets unlimited quota in the two new tablespaces.

sjsysadm

Change the two define commands at the top of the file to match your organization’s naming.

2

Part_doc_info.sql

  • Archive_doc_info is renamed to archive_doc_info_org.

  • A new partitioned table named Archive_doc_info is created and used by/in the exchange option.

  • Executes alter table… exchange partition p1 …

sj_arkiv

Change the three define commands at the top of the file to match your organization’s naming.

3

Part_doc.sqll

  • Archive_doc is renamed to archive_doc_org.

  • A new partitioned table named Archive_doc is created and used by/in the exchange option.

  • Executes alter table… exchange partition p1 …

sj_arkiv

Change the five define commands at the top of the file to match your organization’s naming.

4

sequence.sql

The doc_id sequence is inserted.

sj_arkiv

 

5

sequence.sql

The password for all system users of WorkZone is set to the same password that was used before starting the partitioning.

sjsysadm

The script must be customized. Please see the instructions in the script.

You are now ready to use WorkZone. All documents with doc_id greater than <p_doc_id> will bestored in partition P2.

The sj_arkiv.archive_doc_info_org and sj_arkiv.archive_doc_org tables are left. You will see that they exist as objects but they have no segments assigned.

A test with 92892 documents in the archive showed that it takes 45 seconds to create the documents but it only takes 2/10 seconds to change it to the partitioned table.

select table_name, segment_name, tablespace_name, partitioned

from sys.dba_lobs where owner = 'SJ_ARKIV' and table_name = 'ARCHIVE_DOC';

Kopibilledet mangler

Results in:

ARCHIVE_DOC, SJ_ARKIV_CAPTIA_SEC_P, USERS, YES

Oracle writes like this in the metadata even if the USERS tablespace is empty. You need to look in the sys.dba_segments. Use the following SQL command:


select * from sys.dba_segments a, sys.dba_lobs b
where a.segment_name = b.segment_name
and a.owner = 'SJ_ARKIV'
and b.owner = 'SJ_ARKIV
				

Kopibilledet mangler

Alter_sj_arkiv.sql


-- Execute this as SJSYSADM
-- define must be corrected to what is desired
define new_arkiv_tb=?;
define new_arkiv_lob_tb=?;

set echo on
set trimspool on
set pagesize 0

spool alter_sj_arkiv.log

alter user sj_arkiv identified by sj_arkiv;
alter user sj_arkiv quota unlimited on &new_arkiv_tb;
alter user sj_arkiv quota unlimited on &new_arkiv_lob_tb;

spool off

Kopibilledet mangler

Part_doc_info.sql


-- Execute this as SJ_ARKIV
-- define must be corrected to what is desired

define old_arkiv_tb=?;
define new_arkiv_tb=?;
define p_doc_id=?;
-- p_doc_id2 must be assign to p_doc_id * 2
define p_doc_id2=?


set echo on
set trimspool on
set pagesize 0
set timing on

spool part_doc_info.log

rename archive_doc_info to archive_doc_info_org;
alter index P_ARCHIVE_DOC_INFO rename to P_ARCHIVE_DOC_INFO_ORG;

create table SJ_ARKIV.ARCHIVE_DOC_INFO(
		DOC_ID number,
		CREATED date,
		CREATOR varchar2(100 byte),
		EDITED date,
		EDITOR varchar2(100 byte),
		EDIT_LOCK number,
		SJ_DOC_TYPE varchar2(80 byte),
		SJ_ID number,
		SJ_VERSION_NO number,
		SJ_LOCK number,
		indexed char(1 byte),
		"EXTENSION" VARCHAR2(12 byte),
		"MIME_TYPE" VARCHAR2(128 byte),
		"PROG_ID" VARCHAR2(80 byte),
		"ORIGINAL_FILE_NAME" VARCHAR2(255 byte))
		partition by range (doc_id)
		(partition p1 values less than (&p_doc_id) tablespace &old_arkiv_tb,
		partition p2 values less than (&p_doc_id2) tablespace &new_arkiv_tb);

create unique index P_ARCHIVE_DOC_INFO on ARCHIVE_DOC_INFO(DOC_ID) tablespace &new_arkiv_tb;

alter table SJ_ARKIV.ARCHIVE_DOC_INFO exchange partition p1 with table SJ_ARKIV.ARCHIVE_DOC_INFO_ORG;

grant select, insert, update, delete on SJ_ARKIV.ARCHIVE_DOC_INFO to SJSYSADM;

drop index P_ARCHIVE_DOC_INFO;
create unique index P_ARCHIVE_DOC_INFO on ARCHIVE_DOC_INFO(DOC_ID) local
(partition p1 tablespace &old_arkiv_tb,
partition p2 tablespace &new_arkiv_tb);

spool off


				

Kopibilledet mangler

Part_doc.sql


-- Execute this as SJ_ARKIV
-- define must be corrected to what is desired

define old_arkiv_tb=?;
define new_arkiv_tb=?;
define old_arkiv_lob_tb=?;
define new_arkiv_lob_tb=?;
define p_doc_id=?;
-- p_doc_id2 must be assign to p_doc_id * 2
define p_doc_id2=?

set echo on
set trimspool on
set pagesize 0
set timing on

spool part_doc.log


rename archive_doc to archive_doc_org;
alter index P_ARCHIVE_DOC rename to P_ARCHIVE_DOC_ORG;

create table SJ_ARKIV.ARCHIVE_DOC(
	DOC_ID number,
	DOC_LENGTH number,
	DOCUMENT blob)
	lob (DOCUMENT) store as securefile SJ_ARKIV_CAPTIA_SEC_P
	partition by range (doc_id)
	(partition p1 values less than (&p_doc_id) tablespace &old_arkiv_tb lob(document) store as (tablespace &old_arkiv_lob_tb disable storage in row nocache logging),
	partition p2 values less than (&p_doc_id2) tablespace &new_arkiv_tb lob(document) store as (tablespace &new_arkiv_lob_tb disable storage in row nocache logging));

create unique index P_ARCHIVE_DOC on ARCHIVE_DOC(DOC_ID) tablespace &new_arkiv_tb;

alter table SJ_ARKIV.ARCHIVE_DOC exchange partition p1 with table SJ_ARKIV.ARCHIVE_DOC_ORG;

grant select, insert, update, delete on SJ_ARKIV.ARCHIVE_DOC to SJSYSADM;

drop index P_ARCHIVE_DOC;
create unique index P_ARCHIVE_DOC on ARCHIVE_DOC(DOC_ID) local
(partition p1 tablespace &old_arkiv_tb,
partition p2 tablespace &new_arkiv_tb);

spool off

				

Kopibilledet mangler

sequence.sql


		-- Execute this as sj_arkiv
set trimspool on
set echo on
set pagesize 0

spool sequence.log

declare
	droptext varchar2(100);
	maxdokid number(16);
	seq_max number(16);
	cursor c_seq is
		select null from all_sequences
		where sequence_name = 'ARCHIVE_DOC_INFO$DOC_ID'
		and sequence_owner = 'SJ_ARKIV';
begin

   droptext := null;

   for post in c_seq loop
      droptext := 'drop sequence SJ_ARKIV.ARCHIVE_DOC_INFO$DOC_ID';
   end loop;

   select max(mdokid) into maxdokid from
      (select nvl(max(DOC_ID),0)+1 mdokid from SJ_ARKIV.ARCHIVE_DOC
      union
      select nvl(max(DOC_ID),0)+1 mdokid from SJ_ARKIV.ARCHIVE_DOC_INFO);
   
   if droptext is not null then
      EXECUTE IMMEDIATE 'select SJ_ARKIV.ARCHIVE_DOC_INFO$DOC_ID.nextval from dual' into seq_max;
      if maxdokid > seq_max then
         EXECUTE IMMEDIATE droptext;
         droptext := null;
      end if;
   end if;

   if droptext is null then
      EXECUTE IMMEDIATE 'create sequence SJ_ARKIV.ARCHIVE_DOC_INFO$DOC_ID start with ' || to_char(maxdokid);
   end if;

end;
/

spool off

				

Kopibilledet mangler

Set_sj_arkiv_pwd


-- Execute this as sjsysadm
set echo on
set trimspool on
set pagesize 0

spool set_sj_arkiv_pwd.log

-- take the value from sys_user_guid and use that as parameter for the call to sjp_sys_users.set_all_pwd
-- select * from sys_user_guid;

execute sjp_sys_users.set_all_pwd('?');

spool off

				

Kopibilledet mangler