> ## Documentation Index
> Fetch the complete documentation index at: https://docs.wirekite.io/llms.txt
> Use this file to discover all available pages before exploring further.

# PostgreSQL / YugaByte / TigerData / AlloyDB

> This guide explains how to configure PostgreSQL (including YugaByte, TigerData, and AlloyDB) as a target database for Wirekite data loading and replication.

## Overview

Wirekite supports PostgreSQL 10 and above (including YugaByte, TigerData, Google AlloyDB, and AWS Aurora PostgreSQL) as a target database for:

* **Schema Loading** - Create target tables from Wirekite's intermediate schema format
* **Data Loading** - Bulk load extracted data using COPY command
* **Change Loading (CDC)** - Apply ongoing changes using merge table approach

<Note>
  PostgreSQL loaders use the high-performance COPY command for bulk loading. The Change Loader uses shadow tables with `$wkm` suffix for atomic change application.
</Note>

## Prerequisites

Before configuring PostgreSQL as a Wirekite target, ensure the following requirements are met:

### Database Configuration

1. **Version**: PostgreSQL 10 or above
2. **User Permissions**: Create a Wirekite user with:
   * CREATE TABLE privilege
   * FILE access for COPY operations
   * INSERT, UPDATE, DELETE on target tables
   * Read/write access to Wirekite internal tables (`wirekite_progress` and `wirekite_action`)

### CLI Tools

Use the `psql` command line tool or Wirekite cmdline tool to interact with PostgreSQL.

<Tip>
  For cloud-managed PostgreSQL (AlloyDB, Aurora, Cloud SQL), you'll need to use `databaseRemote=true` (the default) since server-side file access isn't available.
</Tip>

***

## Schema Loader

The Schema Loader reads Wirekite's intermediate schema format (`.skt` file) and generates PostgreSQL-appropriate DDL statements for creating target tables.

<Note>
  If you need to add storage directives or other schema elements, use the CREATE TABLE output as a basis. Don't change column names, column order, or datatypes to incompatible ones.
</Note>

### Required Parameters

<ResponseField name="schemaFile" type="string" required>
  Path to the Wirekite schema file (`.skt`) generated by the Schema Extractor. Must be an absolute path.
</ResponseField>

<ResponseField name="createTableFile" type="string" required>
  Output file for CREATE TABLE statements. Includes both base tables and merge tables for CDC operations.
</ResponseField>

<ResponseField name="createConstraintFile" type="string" required>
  Output file for non-columnar constraints including indexes. Column-level constraints (NOT NULL) are in CREATE TABLE.
</ResponseField>

<ResponseField name="createForeignKeyFile" type="string" required>
  Output file for FOREIGN KEY definitions. Consider applying these after initial data load for better performance.
</ResponseField>

<ResponseField name="logFile" type="string" required>
  Absolute path to the log file for Schema Loader operations.
</ResponseField>

### Optional Parameters

<ResponseField name="dropTableFile" type="string" default="none">
  Output file for DROP TABLE IF EXISTS statements. Set to "none" to skip generation.
</ResponseField>

<ResponseField name="createRecoveryTablesFile" type="string" default="none">
  Output file for recovery table creation SQL. Set to "none" to skip.
</ResponseField>

<ResponseField name="createMergeTables" type="boolean" default="true">
  When `true`, generates merge tables (`$wkm` suffix) for CDC operations. Set to `false` if only doing data loads.
</ResponseField>

### Extended Schema Options

When migrating from Oracle, PostgreSQL can generate additional DDL for non-table objects. Set each parameter to a file path to enable, or leave as `"none"` to skip.

<ResponseField name="objectsFile" type="string" default="none">
  Path to the source XKT file containing extended schema objects (views, procedures, etc.).
</ResponseField>

<ResponseField name="createIndexFile" type="string" default="none">
  Output file for CREATE INDEX statements.
</ResponseField>

<ResponseField name="createSequenceFile" type="string" default="none">
  Output file for CREATE SEQUENCE statements.
</ResponseField>

<ResponseField name="createViewsFile" type="string" default="none">
  Output file for CREATE VIEW statements.
</ResponseField>

<ResponseField name="createMaterializedViewsFile" type="string" default="none">
  Output file for CREATE MATERIALIZED VIEW statements.
</ResponseField>

<ResponseField name="createSynonymsFile" type="string" default="none">
  Output file for CREATE SYNONYM statements.
</ResponseField>

<ResponseField name="createGrantsFile" type="string" default="none">
  Output file for GRANT statements.
</ResponseField>

<ResponseField name="createRolesUsersFile" type="string" default="none">
  Output file for role and user creation statements.
</ResponseField>

<ResponseField name="createSchemasFile" type="string" default="none">
  Output file for CREATE SCHEMA statements.
</ResponseField>

<ResponseField name="createTriggersFile" type="string" default="none">
  Output file for CREATE TRIGGER statements.
</ResponseField>

<ResponseField name="createProceduresFile" type="string" default="none">
  Output file for CREATE PROCEDURE statements.
</ResponseField>

<ResponseField name="createFunctionsFile" type="string" default="none">
  Output file for CREATE FUNCTION statements.
</ResponseField>

<ResponseField name="createPackagesFile" type="string" default="none">
  Output file for CREATE PACKAGE statements.
</ResponseField>

***

## Data Loader

The Data Loader reads Wirekite's intermediate data format (`.dkt` files) and loads records into PostgreSQL tables using COPY commands.

### Required Parameters

<ResponseField name="dsnFile" type="string" required>
  Path to a file containing the PostgreSQL connection string.
</ResponseField>

**Connection string format:**

```
postgres://username:password@host:port/database
```

**Example:**

```
postgres://wirekite:secretpass@postgres-target.example.com:5432/myapp
```

<ResponseField name="inputDirectory" type="string" required>
  Directory containing data files (`.dkt`) to load.
</ResponseField>

<ResponseField name="schemaFile" type="string" required>
  Path to the Wirekite schema file used by Schema Loader. Required for table structure information.
</ResponseField>

<ResponseField name="logFile" type="string" required>
  Absolute path to the log file for Data Loader operations.
</ResponseField>

### Optional Parameters

<ResponseField name="maxThreads" type="integer" default="5">
  Maximum number of parallel threads for loading tables. We recommend setting this to the number of CPUs on the host.
</ResponseField>

<ResponseField name="hexEncoding" type="boolean" default="false">
  Set to `true` if data was extracted using hex encoding instead of base64.
</ResponseField>

<ResponseField name="databaseRemote" type="boolean" default="true">
  When `true`, uses `COPY FROM STDIN`. When `false`, uses local file I/O methods.
</ResponseField>

<ResponseField name="removeFiles" type="boolean" default="true">
  When `true`, removes data files from `inputDirectory` after loading. Should typically be `true` to save disk space.
</ResponseField>

***

## Change Loader

The Change Loader applies ongoing data changes (INSERT, UPDATE, DELETE) to PostgreSQL tables using a merge approach with shadow tables.

<Note>
  The Change Loader uses merge tables to stage changes before applying them atomically to base tables.
</Note>

### Required Parameters

<ResponseField name="dsnFile" type="string" required>
  Path to a file containing the PostgreSQL connection string.
</ResponseField>

**Connection string format:**

```
postgres://username:password@host:port/database
```

<ResponseField name="inputDirectory" type="string" required>
  Directory containing change files (`.ckt`) from the Change Extractor.
</ResponseField>

<ResponseField name="workDirectory" type="string" required>
  Working directory for intermediate files during merge operations.
</ResponseField>

<ResponseField name="schemaFile" type="string" required>
  Path to the Wirekite schema file for table structure information.
</ResponseField>

<ResponseField name="logFile" type="string" required>
  Absolute path to the log file for Change Loader operations.
</ResponseField>

### Optional Parameters

<ResponseField name="databaseRemote" type="boolean" default="true">
  When `true`, indicates remote database connection mode.
</ResponseField>

<ResponseField name="maxFilesPerBatch" type="integer" default="60">
  Maximum number of change files to process in a single batch.
</ResponseField>

<ResponseField name="removeFiles" type="boolean" default="true">
  When `true`, removes change files from `inputDirectory` after fully processing. Should typically be `true` to save disk space.
</ResponseField>

<Warning>
  The Change Loader should not start until the Data Loader has successfully completed the initial full load.
</Warning>

***

## Orchestrator Configuration

When using the Wirekite Orchestrator, prefix target parameters with `target.schema.`, `target.data.`, or `target.change.`.

**Example orchestrator configuration for PostgreSQL target:**

```
# Main configuration
source=oracle
target=postgres

# Schema loading
target.schema.schemaFile=/opt/wirekite/output/schema/wirekite_schema.skt
target.schema.createTableFile=/opt/wirekite/output/schema/create_tables.sql
target.schema.createConstraintFile=/opt/wirekite/output/schema/constraints.sql
target.schema.createForeignKeyFile=/opt/wirekite/output/schema/foreign_keys.sql
target.schema.logFile=/var/log/wirekite/schema-loader.log

# Data loading
target.data.dsnFile=/opt/wirekite/config/postgres.dsn
target.data.inputDirectory=/opt/wirekite/output/data
target.data.schemaFile=/opt/wirekite/output/schema/wirekite_schema.skt
target.data.logFile=/var/log/wirekite/data-loader.log
target.data.maxThreads=8
target.data.databaseRemote=true

# Change loading (CDC)
target.change.dsnFile=/opt/wirekite/config/postgres.dsn
target.change.inputDirectory=/opt/wirekite/output/changes
target.change.workDirectory=/opt/wirekite/work
target.change.schemaFile=/opt/wirekite/output/schema/wirekite_schema.skt
target.change.logFile=/var/log/wirekite/change-loader.log
target.change.maxFilesPerBatch=30
target.change.databaseRemote=true
```

For complete Orchestrator documentation, see the [Execution Guide](/run/execution).
