Tablespaces with interval partitioning - oracle

Is there any way to specify different tablespaces for each partition if I use interval partitioning?
My table is (it is just example, I have more columns in the table):
create table MY_TABLE
(
id NUMBER(20) not null,
type VARCHAR2(1 char) not null,
session_id NUMBER(12) not null,
date_of_beginning DATE not null,
account_number NUMBER not null
)
PCTFREE 1
PARTITION BY RANGE (date_of_beginning)
INTERVAL(NUMTOYMINTERVAL(1, ''MONTH''))
SUBPARTITION BY HASH(account_number) subpartitions 50
(
PARTITION p_1 VALUES LESS THAN (TO_DATE(''01.06.2015'', ''dd.mm.yyyy''))
)';
I want each partition to be stored in separate tablespase. Any ideas how can I achieve it? Maybe some trigger?
For other tables like this one, we have a job, which creates tablespace and partition in the beginning of the month. But this one creates partitions automatically because of intervals.

Related

Problem with alter table big_table modify partition

I create table:
create table big_table(
bt_id number primary key,
bt_date date,
bt_value varchar2(20)
)
Then I wnat partition this table (code abbreviated):
alter table big_table modify
partition by range (bt_date)
interval(numtoyminterval(1, 'MONTH'))
subpartition by hash (bt_id)
(
partition nn_st_p1 values less than (to_date(' 2019-05-01 00:00:00', 'syyyy-mm-dd hh24:mi:ss'))
subpartitions 4
store in (ipr_tbl),
)online
Error message:
17:20:39 line 1: ORA-14006: invalid partition name
I can't understand what is wrong with my partition name?
Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
Try something like this
CREATE TABLE big_table
(bt_id NUMBER PRIMARY KEY
, bt_date DATE
, bt_value VARCHAR2(20)
)
PARTITION BY RANGE (bt_date) INTERVAL (NUMTOYMINTERVAL(1,'MONTH'))
SUBPARTITION BY HASH (bt_id) SUBPARTITIONS 4
(PARTITION nn_st_p1 VALUES LESS THAN (TO_DATE('01-MAY-2019','dd-MON-yyyy'))
)
PARALLEL;

How to create subpartition for Reference-Partitioned Tables

Consider the following scenario of Reference-Partitioned Tables. The table T_PARTNER_CUSTOMER borrows partition part1 and part2 from table T_PARTNER_CONFIG.
CREATE TABLE T_PARTNER_CONFIG (
ID NUMBER(38) NOT NULL,
SECURITY_CONTEXT_ID NUMBER(38) NOT NULL
)
PARTITION BY LIST(SECURITY_CONTEXT_ID)
(PARTITION part1 VALUES (0, 1, 2),
PARTITION part2 VALUES (4, 5, 6));
CREATE TABLE T_PARTNER_CUSTOMER (
ID NUMBER(38) NOT NULL,
PARTNER_CONFIG_ID NUMBER(38) NOT NULL
CUSTOMER_NUMBER VARCHAR2(10) NOT NULL,
CONSTRAINT FK_PC_PARTNER_CONFIG
FOREIGN KEY(PARTNER_CONFIG_ID) REFERENCES T_PARTNER_CONFIG (id)
)
PARTITION BY REFERENCE(FK_PC_PARTNER_CONFIG);
Now if we want to create further subpartition for table T_PARTNER_CUSTOMER, so that the partition part1 and part2 are further subdivided for table T_PARTNER_CUSTOMER. I tried the approach below, but it doesn't work. I am using Oracle 11g Enterprise edition.
CREATE TABLE T_PARTNER_CUSTOMER (
ID NUMBER(38) NOT NULL,
PARTNER_CONFIG_ID NUMBER(38) NOT NULL
CUSTOMER_NUMBER VARCHAR2(10) NOT NULL,
CONSTRAINT FK_PC_PARTNER_CONFIG
FOREIGN KEY(PARTNER_CONFIG_ID) REFERENCES T_PARTNER_CONFIG (id)
)
PARTITION BY REFERENCE(FK_PC_PARTNER_CONFIG)
SUBPARTITION BY HASH (CUSTOMER_NUMBER) SUBPARTITIONS 8;
Seems to be impossible, see documentation:
There is no "SUBPARTITON" clause available, unlike for other partition type, e.g. LIST:

Delete tables from table based on table size

I use this table to store messages. I would like to delete rows by date if the size of the table is bigger than 10 MB. Is this possible in Oracle?
CREATE TABLE EVENTS(
EVENTID INTEGER NOT NULL,
SOURCE VARCHAR2(50 ),
TYPE VARCHAR2(50 ),
EVENT_DATE DATE,
DESCRIPTION VARCHAR2(100 )
)
/

oracle partition by group_id and subpartition monthly

I want to create a table like this.
create table some_data (
id number(19,0),
group_id number(19,0),
value float,
timestamp timestamp
);
For this table i would like to have the data stored like
group_id=1
jan-2015
feb-2015
...
group_id=2
jan-2015
feb-2015
...
and so on. So I assume i have to create a partition by range for the group_id and then a subpartition also by range with the timestamp column, right?
So it should look like this:
create table some_data (
id number(19,0),
group_id number(19,0),
value float,
timestamp timestamp
)
PARTITION BY RANGE (group_id)
SUBPARTITION BY RANGE ("TIMESTAMP")
INTERVAL (NUMTOYMINTERVAL(1,'MONTH'))
(
PARTITION part_1 values LESS THAN (TO_DATE('01.02.2015','DD.MM.YYYY'))
);
Is this right? And also the question: With this partition, if a new group_id is added, will oracle create automatically a new partition for the new group_id and the new suppartitions for new data with new months?
Interval partitioning is not supported on subpartition level:
http://docs.oracle.com/cd/E11882_01/server.112/e41084/statements_7002.htm#SQLRF54559
You can define it like this:
create table some_data (
id number(19,0),
group_id number(19,0),
value float,
timestamp timestamp -- not good naming
)
PARTITION BY RANGE ("TIMESTAMP")
INTERVAL (NUMTOYMINTERVAL(1,'MONTH'))
SUBPARTITION BY RANGE (group_id) -- it could be hash or list as well
subpartition template(
...
)
(
PARTITION part_1 values LESS THAN (TO_DATE('01.02.2015','DD.MM.YYYY'))
);

How do I create a partitioned table without initial partitions?

Say, I have the following DDL:
create table partition_test_table
(
id number(38,0) not null,
value varchar(255),
country_code varchar(2) not null,
creation_date date not null,
constraint pk_partition_test_table primary key (id)
)
partition by range ( creation_date )
subpartition by list ( country_code );
This doesn't work because it doesn't declare any initial partitions. How do I create a partitioned table without initial partitions? Is that even possible?
Thanks.

Resources