Skip to content

PostgreSQL Reader ​

The PostgreSQLReader plugin enables reading data from PostgreSQL databases.

Example ​

Create a sample table in PostgreSQL:

sql
CREATE TABLE IF NOT EXISTS users (
id SERIAL PRIMARY KEY,
username VARCHAR(50) NOT NULL,
email VARCHAR(100),
age INTEGER,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

INSERT INTO users (username, email, age) VALUES
('alice', '[email protected]', 28),
('bob', '[email protected]', 32),
('charlie', '[email protected]', 25);

Configuration to read from PostgreSQL:

json
{
  "job": {
    "content": [
      {
        "reader": {
          "name": "postgresqlreader",
          "parameter": {
            "username": "postgres",
            "password": "password",
            "column": ["id", "username", "email", "age", "created_at"],
            "splitPk": "id",
            "connection": [
              {
                "jdbcUrl": "jdbc:postgresql://localhost:5432/testdb",
                "table": ["users"]
              }
            ]
          }
        },
        "writer": {
          "name": "streamwriter",
          "parameter": {
            "encoding": "UTF-8",
            "print": true
          }
        }
      }
    ],
    "setting": {
      "speed": {
        "channel": 1
      }
    }
  }
}

Parameters ​

This plugin is based on the RDBMS Reader implementation.

Required Parameters ​

ParameterDescriptionRequiredDefault
jdbcUrlPostgreSQL JDBC connection URLYesNone
usernameDatabase usernameYesNone
passwordDatabase passwordYesNone
tableList of tables to read fromYesNone
columnList of columns to readYesNone

Optional Parameters ​

ParameterDescriptionRequiredDefault
splitPkPrimary key for data splittingNoNone
whereWHERE clause for filteringNoNone
fetchSizeJDBC fetch sizeNo1024

Data Type Mapping ​

PostgreSQL TypeAddax TypeNotes
SMALLINT, INTEGER, BIGINTlong
REAL, DOUBLE PRECISION, NUMERICdouble
VARCHAR, CHAR, TEXTstring
DATE, TIME, TIMESTAMPdate
BOOLEANbool
BIT(1)bool
BIT(n)bytespacked, 8 bits per byte, most significant byte first
BIT VARYINGstringthe bit string itself, leading zeros preserved
BYTEAbytes

Performance Tips ​

Use Split Key for Large Tables ​

json
{
  "parameter": {
    "splitPk": "id",
    "setting": {
      "speed": {
        "channel": 4
      }
    }
  }
}

Optimize with WHERE Clause ​

json
{
  "parameter": {
    "where": "created_at >= '2023-01-01' AND status = 'active'"
  }
}

Connection Examples ​

Standard Connection ​

json
{
  "jdbcUrl": "jdbc:postgresql://localhost:5432/mydb"
}

SSL Connection ​

json
{
  "jdbcUrl": "jdbc:postgresql://localhost:5432/mydb?ssl=true&sslmode=require"
}

Connection Pool Settings ​

json
{
  "jdbcUrl": "jdbc:postgresql://localhost:5432/mydb?prepareThreshold=0&preparedStatementCacheQueries=0"
}