AWS Database Blog
Implementing table partitioning in Oracle Standard Edition: Part 1
Organizations are aggressively adopting the cloud as a standard and actively evaluating their database needs. Amazon RDS for Oracle is a managed service that makes it easy to quickly create Oracle Database instances, enabling you to migrate existing on-premises workloads to the cloud. Migration from on-premises Oracle Database to Amazon RDS for Oracle is quick because it doesn’t involve code conversion.
Oracle Enterprise Edition (Oracle EE) has become the standard adopted by many organizations. However, if you do a more in-depth database assessment, you may find that not every application needs all the features of Oracle EE, and you may be overpaying.
You can significantly reduce your Oracle commercial license usage by switching to Oracle Database Standard Edition (Oracle SE), which is even easier with the Amazon RDS for Oracle License Included (LI) option. Applications with no or minimum Oracle EE features usage are excellent candidates for migrating to Oracle SE.
Oracle table partitioning is a commonly used feature to manage large tables and improve SELECT query performance. Oracle partitioning is only available in the Oracle EE Extra cost option.
This post demonstrates how to implement a partitioning feature for tables in Oracle Standard Edition (Oracle SE) using a single view accessing multiple sub-tables and the INSTEAD OF trigger.
The following diagram illustrates the architecture of this solution.
Creating objects
To implement the solution, start by creating your objects.
- To demonstrate the feature, you break the Oracle EE partition tables into individual tables per partition on Oracle SE. Create a sample table using the following code:
- Collect the privilege details of the source table. For this use case, grant SELECT to oraadmin and use the following script to collect the object-level grant details:
- Connect Oracle SE Database and create four individual tables, append the unique number to each to identify it like a table partition:
- Enter the following code to create a single view that acts as the main partition table by combining all four tables using the UNION ALL statement:
Inserting and distributing data
To insert and distribute your data, complete the following steps:
- Enter the following code to create an INSTEAD OF INSERT trigger for the PARTTBL_MAIN view:
- Confirm that tables are empty. See the following code:
- Create a sequence to control row creation:
- Insert the data into the
PARTTBL_MAIN
view. Each time you run the following code, it inserts approximately 93 rows because we insert 1 row per day: - Confirm that the rows are inserted into each table, and we get a total row count at the
PARTTBL_MAIN
view:
Updating the data
To update your data, complete the following steps:
- Enter the following code to create an
INSTEAD OF UPDATE
trigger to thePARTTBL_MAIN
view: - Review the current data using the following
SELECT
statement on thePARTTBL_MAIN
view. See the following code: - Update the
PARTTBL_MAIN
view and confirm that the records are updated correctly. See the following code:
Deleting the data
To delete your data, complete the following steps:
- Enter the following code to create an
INSTEAD OF DELETE
trigger on thePARTTBL_MAIN
view: - Review the current partition data using the following
SELECT
statement on thePARTTBL_MAIN
view: - Delete the records for
ORD_MONTH
3 and confirm that the records are deleted successfully. See the following code:
Granting privileges on view and individual tables
To grant privileges on the view and individual tables using the grant information you collected, complete the following steps:
- Connect to the ORACLE SE instance with a database privilege user, create a user called
oraadmin
, and grant only connect privileges. See the following code: - Test and confirm that
oraadmin
doesn’t have access to thePARTTBL_MAIN
view. The following query should return an ORA-00942 error: - Connect as a database privilege user and grant privileges on the
PARTTBL_MAIN
view and all underlying tables: - Confirm that
oraadmin
has access to thePARTTBL_MAIN
view and underlying tables:
Limitations
A global, unique index key at an overall view level is unsupported; however, you can have unique local indexes at a table level.
Conclusion
In this post, we described how we could use a view and tables per partition and an INSTEAD OF
trigger on the view as an alternate solution to implementing partitioning in Oracle SE. You can gather the grants and privilege information from the source database and replicate the same on an individual table and views. You can also use a similar technique for range-list partitioning. Additionally, you can migrate Oracle EE partition data to individual tables in Oracle SE with AWS Data Migration Service (AWS DMS).
In the next post in this series, we describe automating partition maintenance in Oracle SE.
About the Authors
Srinivas Potlachervoois a Lead Database Consultant with the Professional Services team at Amazon Web Services. He works as database migration specialist to help AWS customers to move their on-premises database environment to AWS cloud database solutions.
Bhavesh Rathod is a Senior Database Consultant with the Professional Services team at Amazon Web Services. He works as database migration specialist to help Amazon customers to move their on-premises database environment to AWS cloud database solutions.
Samujjwal Roy is a Principal DB Consultant with the Professional Services team at Amazon Web Services. He has been with Amazon for 17+ years and has led migration projects for internal and external Amazon customers to move their on-premises database environment to AWS Cloud database solutions.