Migrate legacy applications from Oracle Pro*C to ECPG
Created by Sai Parthasaradhi (AWS) and Mahesh Balumuri (AWS)
Environment: PoC or pilot | Source: Oracle | Target: PostgreSQL |
R Type: Re-architect | Workload: Oracle | Technologies: Migration; Databases |
Summary
Most legacy applications that have embedded SQL code use the Oracle Pro*C precompiler to access the database. When you migrate these Oracle databases to Amazon Relational Database Service (Amazon RDS) for PostgreSQL or Amazon Aurora PostgreSQL-Compatible Edition, you have to convert your application code to a format that’s compatible with the precompiler in PostgreSQL, which is called ECPG. This pattern describes how to convert Oracle Pro*C code to its equivalent in PostgreSQL ECPG.
For more information about Pro*C, see the Oracle documentation
Prerequisites and limitations
Prerequisites
An active AWS account
An Amazon RDS for PostgreSQL or Aurora PostgreSQL-Compatible database
An Oracle database running on premises
Tools
The PostgreSQL packages listed in the next section.
AWS CLI – The AWS Command Line Interface (AWS CLI) is an open-source tool for interacting with AWS services through commands in your command-line shell. With minimal configuration, you can run AWS CLI commands that implement functionality equivalent to that provided by the browser-based AWS Management Console from a command prompt.
Epics
Task | Description | Skills required |
---|---|---|
Install PostgreSQL packages. | Install the required PostgreSQL packages by using the following commands.
| App developer, DevOps engineer |
Install the header files and libraries. | Install the
For the development environment only, also run the following commands.
| App developer, DevOps engineer |
Configure the environment path variable. | Set the environment path for PostgreSQL client libraries.
| App developer, DevOps engineer |
Install additional software as necessary. | If required, install pgLoader as a replacement for SQL*Loader in Oracle.
If you’re calling any Java applications from Pro*C modules, install Java.
Install ant to compile the Java code.
| App developer, DevOps engineer |
Install the AWS CLI. | Install the AWS CLI to run commands to interact with AWS services such as AWS Secrets Manager and Amazon Simple Storage Service (Amazon S3) from your applications.
| App developer, DevOps engineer |
Identify the programs to be converted. | Identify the applications that you want to convert from Pro*C to ECPG. | App developer, App owner |
Task | Description | Skills required |
---|---|---|
Remove unwanted headers. | Remove the | App owner, App developer |
Update variable declarations. | Add Remove the
| App developer, App owner |
Update ROWNUM functionality. | The Pro*C code:
ECPG code:
| App developer, App owner |
Update function parameters to use alias variables. | In PostgreSQL, function parameters can’t be used as host variables. Overwrite them by using an alias variable. Pro*C code:
ECPG code:
| App developer, App owner |
Update struct types. | Define Pro*C code: Header file (
ECPG code: Header file (
Pro*C file (
ECPG file (
| App developer, App owner |
Modify logic to fetch from cursors. | To fetch multiple rows from cursors by using array variables, change the code to use Pro*C code:
ECPG code:
| App developer, App owner |
Modify package calls that don't have return values. | Oracle package functions that don’t have return values should be called with an indicator variable. If your application includes multiple functions that have the same name or if the unknown type functions generate runtime errors, typecast the values to the data types. Pro*C code:
ECPG code:
| App developer, App owner |
Rewrite SQL_CURSOR variables. | Rewrite the Pro*C code:
ECPG code:
| App developer, App owner |
Apply common migration patterns. |
| App developer, App owner |
Enable debugging, if required. | To run the ECPG program in debug mode, add the following command inside the main function block.
| App developer, App owner |
Task | Description | Skills required |
---|---|---|
Create an executable file for ECPG. | If you have an embedded SQL C source file named
| App developer, App owner |
Create a make file for compilation. | Create a make file to compile the ECPG program, as shown in the following sample file.
| App developer, App owner |
Task | Description | Skills required |
---|---|---|
Test the code. | Test the converted application code to make sure that it functions correctly. | App developer, App owner, Test engineer |
Related resources
ECPG - Embedded SQL in C
(PostgreSQL documentation) Error Handling
(PostgreSQL documentation) Why Use the Oracle Pro*C/C++ Precompiler
(Oracle documentation)
Additional information
PostgreSQL has an embedded SQL precompiler, ECPG, which is equivalent to the Oracle Pro*C precompiler. ECPG converts C programs that have embedded SQL statements to standard C code by replacing the SQL calls with special function calls. The output files can then be processed with any C compiler tool chain.
Input and output files
ECPG converts each input file you specify on the command line to the corresponding C output file. If an input file name doesn’t have a file extension, .pgc is assumed. The file's extension is replaced by .c
to construct the output file name. However, you can override the default output file name by using the -o
option.
If you use a dash (-
) as the input file name, ECPG reads the program from standard input and writes to standard output, unless you override that by using the -o
option.
Header files
When the PostgreSQL compiler compiles the pre-processed C code files, it looks for the ECPG header files in the PostgreSQL include
directory. Therefore, you might have to use the -I
option to point the compiler to the correct directory (for example, -I/usr/local/pgsql/include
).
Libraries
Programs that use C code with embedded SQL have to be linked against the libecpg
library. For example, you can use the linker options -L/usr/local/pgsql/lib -lecpg
.
Converted ECPG applications call functions in the libpq
library through the embedded SQL library (ecpglib
), and communicate with the PostgreSQL server by using the standard frontend/backend protocol.