top of page

Migrating an Oracle 19c database on Linux to PostgreSQL on Windows

Migrating an Oracle 19c database on Linux to PostgreSQL on Windows involves several steps. This is a detailed step-by-step process, but ensure you understand both Oracle and PostgreSQL environments before proceeding. This guide uses tools such as ora2pg to assist with the migration.


Prerequisites:


  1. Oracle 19c installed on Linux

  2. PostgreSQL installed on Windows

  3. Network access between the Linux and Windows servers

  4. ora2pg installed on Linux


Step 1: Install ora2pg on the Linux Server


ora2pg is a tool used to migrate Oracle schemas to PostgreSQL.

  1. Install dependencies:

    bash

    sudo apt-get install -y build-essential libaio1 libaio-dev

  2. Download and install ora2pg:

    bash

    sudo apt-get install ora2pg

  3. Verify installation:

    bash

    ora2pg --version


Step 2: Configure ora2pg for Oracle 19c


  1. Create a directory for ora2pg project files:

    bash

    mkdir ~/ora2pg_project cd ~/ora2pg_project

  2. Copy the default ora2pg configuration file:

    bash

    cp /etc/ora2pg/ora2pg.conf ./ora2pg.conf

  3. Edit the ora2pg.conf file:

    bash

    nano ora2pg.conf

    Update the following settings:

    ini

    ORACLE_HOME /path/to/oracle/home ORACLE_DSN dbi:Oracle:host=your_oracle_host;sid=your_oracle_sid ORACLE_USER your_oracle_user ORACLE_PWD your_oracle_password PG_DSN dbi:Pg:host=your_postgres_host;port=5432;dbname=your_postgres_db PG_USER your_postgres_user PG_PWD your_postgres_password


Step 3: Export Oracle Schema using ora2pg


  1. Perform an initial export of your Oracle schema:

    bash

    ora2pg -t SHOW_VERSION

  2. Test the schema export:

    bash

    ora2pg -t SCHEMA -o schema.sql -b ./output

    This will export the Oracle schema into PostgreSQL compatible SQL.

  3. Verify the output in the ./output directory and modify it if necessary.


Step 4: Export Oracle Data


  1. Export data from Oracle:

    bash

    ora2pg -t COPY -o data.sql -b ./output

  2. Check for any errors or warnings in the export log files.


Step 5: Set up PostgreSQL on Windows


  1. Install PostgreSQL on Windows: You can download and install PostgreSQL from here.

  2. Create a new PostgreSQL database:

    sql

    CREATE DATABASE your_postgres_db;

  3. Create necessary users:

    sql

    CREATE USER your_postgres_user WITH PASSWORD 'your_postgres_password'; GRANT ALL PRIVILEGES ON DATABASE your_postgres_db TO your_postgres_user;


Step 6: Transfer the Export Files from Linux to Windows


  1. Transfer the schema and data files (from ./output directory) from the Linux server to the Windows machine. You can use tools like scp or file transfer utilities.

  2. Example using scp:

    bash

    Copy code

    scp ~/ora2pg_project/output/schema.sql your_windows_user@your_windows_ip:/path/to/destination scp ~/ora2pg_project/output/data.sql your_windows_user@your_windows_ip:/path/to/destination


Step 7: Import into PostgreSQL


  1. On the Windows machine, connect to your PostgreSQL instance:

    bash

    psql -h localhost -U your_postgres_user -d your_postgres_db

  2. Import the schema:

    bash

    \i '/path/to/schema.sql';

  3. Import the data:

    bash

    \i '/path/to/data.sql';


Step 8: Verify Migration


  1. Check table structure:

    sql

    \dt

  2. Check the data:

    sql

    SELECT * FROM your_table LIMIT 10;

  3. Verify that all your tables, constraints, and data are successfully imported.


Step 9: Post-Migration Tasks


  1. Fix any compatibility issues: Review logs, check for data types or functions in PostgreSQL that behave differently than in Oracle.

  2. Migrate Stored Procedures: Manually convert Oracle PL/SQL procedures to PostgreSQL PL/pgSQL.

  3. Test thoroughly: Run application tests to ensure everything works correctly in PostgreSQL.


Step 10: Backup and Optimization


  1. Backup PostgreSQL database:

    bash

    pg_dump -U your_postgres_user -F c -b -v -f "backup_filename.backup" your_postgres_db

  2. Optimize: Run VACUUM and analyze performance tuning for PostgreSQL.

    bash

    Copy code

    VACUUM FULL; ANALYZE;



This is a basic guide for migration. Complex databases may require more fine-tuning and customization during the migration process. Be sure to test everything thoroughly after migration.



15 views

Recent Posts

See All

Comments


AiTech

©2023 by AiTech

bottom of page