Bai Eel: Let’s talk about the technical details and implementation principles of IvorySQL’s Oracle compatibility

Two years ago, I heard from a friend of Hangao that they were going to create an open source database project based on PostgreSQL, focusing on compatibility with Oracle, and releasing it simultaneously with the PG Community Edition kernel. I didn’t quite believe it when I heard it. Highgo’s Highgo adds certain Oracle compatibility features to the PG kernel, and is generally a few versions slower than the PG community version. If they open source such a database product, it will It will not affect the development of Highgo. Although I have some concerns about Hanco's investment in open source databases, the IvorySQL community has developed. A few days ago, version 3.0 was officially released. It also received 630+ STARs on GITHUB and ranked on the Motianlun domestic database popularity list. 136, ranking in the middle and upper reaches. When an open source product reaches version 3.0, it should be considered to have entered a relatively benign stage.

On the SQL engine, IvorySQL adopts a special dual parser mode, with separate parse trees for Oracle compatibility mode and PG compatibility mode. The way most domestic database products are compatible with Oracle databases is to add Oracle-compatible syntax to the syntax parser, not this way. The advantage of IvorySQL's design is that the development of Oracle-compatible parsers and the development of PG parsers are independent and have less influence on each other.

There are some other benefits by separating the parser. First, the complexity of the parser is reduced, faults are isolated, and it is less error-prone. In addition, when PG is upgraded, the native parser of the open source community can be directly used without considering changes in Oracle syntax. When Oracle syntax changes, it will not affect the PG parser and only needs to be upgraded independently. However, there is a disadvantage in doing this, that is, you cannot mix and match PG and ORACLE syntax. For most application scenarios, there are currently not many requirements that must merge the two requirements.    

When migrating Oracle database to IvorySQL, IvorySQL's Oracle SQL parser can help users reduce the difficulty of migration and speed up migration. After the system is upgraded in the future, the system can gradually be compatible with PG syntax and gradually move to the PG SQL parser. IvorySQL is compatible with the Oracle PL/SQL process language through the PL/iSQL plug-in. PL/iSQL not only supports stored procedures, but also supports Oracle-specific syntax such as anonymous blocks.

Half a month ago, a classmate from IvorySQL asked me if I was interested in trying the V3.0 version they were about to release. It is said that compared with the 2.x version, it has been greatly enhanced in terms of compatibility with Oracle. I have always been interested in testing database products, let alone a PG database product that is quite compatible with Oracle.

Compared with the original PG, the deployment of IvorySQL is slightly more complicated and requires the installation of some dependency packages. Because there are requirements for the LIB library version of Python, I initially failed to install and deploy it in an environment where countless PG-type domestic databases have been installed in the company's laboratory because there were too many conflicting dependent libraries. So I changed to experience it in the wsl environment of my laptop. In a clean CentOS7 environment, deployment is still very smooth.    

First, yum install -y libicu libxslt python3 installs Python3 and libicu, libxslt and other dependent packages. Then you can install the various installation packages provided by IvorySQL.

Install ivorysql3-libs-3.0-1.rhel7.x86_64.rpm, ivorysql3-3.0-1.rhel7.x86_64.rpm, ivorysql3-contrib-3.0-1.rhel7.x86_64.rpm, ivorysql3-server-3.0-1 in sequence. .rhel7.x86_64.rpm, all in one minute. For RPM installation, it is not necessary to create the ivorysql user and user group in the installation document. In fact, these have been automatically created when installing ivorysql3. After setting the environment variables, you can directly initialize the database.    

From the installation experience, although there are many installation packages, and Python3 has some requirements for environmental dependency packages, the installation in a brand new CentOS7 environment is still relatively smooth. Next, let's have a preliminary experience with the functions of IvorySQL.

Let's first experience the PG compatibility mode. Here we encountered a small BUG. The default database for connecting to the IvorySQL database is ivorysql. However, the current IvorySQL 3.0BETA version only creates the postgres database when initdb is created, and does not create the ivorysql database. I think this problem should be easily solved in the official version 3.0.    

Currently IvorySQL supports most Oracle data types, but it seems that it does not currently support large fields such as LOB/CLOB. However, we can use PG's BLOB storage mode to store LOB fields when creating a table.

Log in to the database with

Let’s take a look at the table created in PG compatibility mode.

In Oracle compatibility mode, let’s take a look at how this table is represented.

There are certain differences between PG The current strategy is acceptable, but can it be done better? Hopefully, with the emergence of new versions, we will have more surprises in this regard.

Next we test whether there is Oracle compatibility support in PG compatibility mode. After logging in to IvorySQL using port 5432, perform some operations such as Oracle-specific anonymous blocks and query sysdate.

From the above results, we can see that the standard PG compatible port does not support Oracle syntax when logging into the database.

It can be seen that the current compatibility mode of this database is pg mode, and the database mode is oracle mode, which means that the current database can be accessed using Oracle compatibility mode. IvorySQL's database_mode has two database modes: Oracle and PG. The PG database schema cannot be accessed using Oracle compatibility mode, while the oracle database schema can be accessed through PG or Oracle compatibility mode. The port for Oracle compatibility mode is 1521.    

IvorySQL adds a new ivorysql.conf configuration file based on the original PG configuration file. Oracle compatibility mode ports and some compatibility configurations can be configured in this file. shared_preload_libraries = 'liboracle_parser, ivorysql_ora', from this line of configuration, we can see that liboracle_parser and ivorysql_ora are key components to achieve Oracle compatibility, and their codes are in the src/backend/oracle_parser directory.

Log in to the database through Let's take a look at the extent to which Oracle compatibility mode is compatible with Oracle. It seems that sysdate, dual and other Oracle syntaxes no longer report errors. Even setting nls_date_format does not report an error, but it does not seem to work.    

However, you can see this parameter of Oracle from Ivy_guc.c. Could it be that you have encountered a BUG? Later, when I thought about it carefully, it turned out that I had not used Oracle well for a long time, and I had forgotten it. To modify the NLS parameters of the session, use alert session and cannot use alter system.

This time I got it right, and the compatibility of time calculation with Oracle is also very good.

In terms of built-in data types and built-in functions, IvorySQL's support is still good, and most commonly used syntax and functions in applications are supported.    

​I encountered a small problem during After communicating with IvorySQL classmates, it was confirmed that compatibility in this area has not yet been officially opened. I hope that IvorySQL can provide support in subsequent versions in the future. After all, Sequence is also the most commonly used function in applications.    

Because of compatibility issues, I had to make some modifications to the stored procedure for PG syntax. After modification, a PL/iSQL stored procedure similar to Oracle stored procedure ran as expected. Because of compatibility issues, I can only assign a value to v through select to_char(sysdate,'yyyy-mm-dd:hh24:mi:ss') into v from dual; instead of writing v directly like Oracle's PL/SQL: = to_char(sysdate,'yyyy-mm-dd:hh24:mi:ss'). After communicating with students at IvorySQL, we have found that PL syntax is still being improved, and it currently does not support the direct use of built-in functions in SQL.    

Regarding PL/SQL compatibility, this time IvorySQL has also arranged the syntax of anonymous blocks. Anonymous blocks are still widely used in Oracle applications. When our D-SMART collects database indicators, for databases that support anonymous blocks, the anonymous block method is preferred, which can reduce the network interaction between the RDBMS SERVER and the client. , improve application efficiency.

I have had a preliminary experience with IvorySQL in the past two days. Compared with the original PG, IvorySQL is still remarkable in terms of Oracle compatibility. There are currently many domestic open source database products, but there are still relatively few that provide support for Oracle. Most domestic database companies have put features compatible with Oracle into their commercial versions. IvorySQL is still full of sincerity in this regard. I hope that with the iteration of the version, Hanco will open more and more Oracle compatible features to IvorySQL. As an open source database product that synchronizes quickly with the PG Community Edition and maintains good syntax compatibility with Oracle, IvorySQL is still worth owning for some users who want to use an open source database to replace Oracle.

If you are interested in IvorySQL, you can refer to the following website:

IvorySQL official website: https://www.ivorysql.org/zh-cn/

GITHUB        :https://github.com/IvorySQL/IvorySQL

GITEE           :IvorySQL (IvorySQL) - Gitee.com

Microsoft launches new "Windows App" Xiaomi officially announces that Xiaomi Vela is fully open source, and the underlying kernel is NuttX Vite 5. Alibaba Cloud 11.12 is officially released. The cause of the failure is exposed: Access Key service (Access Key) anomaly. GitHub report: TypeScript replaces Java and becomes the third most popular. The language operator’s miraculous operation: disconnecting the network in the background, deactivating broadband accounts, forcing users to change optical modems ByteDance: using AI to automatically tune Linux kernel parameters Microsoft open source Terminal Chat Spring Framework 6.1 officially GA OpenAI former CEO and president Sam Altman & Greg Brockman joins Microsoft
{{o.name}}
{{m.name}}

Guess you like

Origin my.oschina.net/u/5729420/blog/10149235