Skip to main content

PostgreSQL

info

PostgreSQL ingestion reads source tables through SQL time windows. Specify the schema in SQL object names, not as the database name. The key distinction is between timestamps with and without time zones. For verification, recheck the same window in the source client before comparing target child tables.

Entry point: taosExplorer → Data In → PostgreSQL.

The reading host is taosX or the selected taosX-Agent, and needs access to the database and selected schema/tables. The PostgreSQL administrator provides the authentication account and source objects.

1. Prepare a Small Data Range​

This example uses source table public.readings, with fields ts, device, and temperature. Confirm whether ts is a time column with or without a time zone, and record a one-minute window known to contain data. An authorized TDengine TSDB administrator creates the following in taosExplorer's Data Browser or the taos CLI:

CREATE DATABASE postgres_demo PRECISION 'ms';
CREATE STABLE postgres_demo.temperatures (ts TIMESTAMP, temperature DOUBLE)
TAGS (device VARCHAR(32));
PrerequisiteHow to confirm
Execution location and networkCheck the source address and port from the actual taosX or taosX-Agent host. The common port is 5432. Server authentication rules must allow this host and identity to connect.
Source permissionsThe account needs database CONNECT, schema USAGE, and table SELECT permissions. Separate device reads also require permission to run the corresponding DISTINCT query.
TLSPrepare a CA according to service policy, and client certificate and private key if necessary. Place files on the reading host, accessible to the service identity.
Time and targetConfirm source column types, session time zone, and target precision. Obtain target write permissions and record a committed test window.

2. Configure and Start​

  1. Add a PostgreSQL data source and select target database postgres_demo. Enter the actual host, port, database, user, and password, and select an agent if needed.
  2. Configure SSL mode according to source requirements. The application name identifies connections at the source; use a traceable name. Check connectivity.
  3. Enter the SQL template and explicit start/end times and time zone. Replace object names if different:
SELECT ts, device, temperature FROM public.readings
WHERE ts >= ${start} AND ts < ${end} ORDER BY ts;
  1. Retrieve samples and check time values and types. Select target temperatures and child table template t_{device}. Map time, temperature, and device tags, then preview, submit, and start.
View source connection and authentication locations

Under Connection Configuration, enter the PostgreSQL host, actual listener port, and source database. A schema name such as public belongs in SQL object names. Target postgres_demo is selected in the task's basic information and cannot replace the source database. The gray address and port in the image are format hints.

PostgreSQL source address, port, and database

Under Authentication, enter the source read-only account and password. Confirm permissions cover the schemas and tables used by the query, then select connection options using the next section and check connectivity.

PostgreSQL source username and password

2.1 Samples and Mapping​

This example maps ts, device, and temperature. Check time according to whether the source column has a time zone; do not apply millisecond-integer settings from message sources. For multi-column models, also check fixed-point precision and every result column.

For sample retrieval, optional processing, and preview steps, see Relational Database Sample Mapping. Select target temperatures and child table template t_{device}. Map temperature to DOUBLE and device to a tag; the preview should generate t_d001.

View multi-column mapping and results

The separate example below uses supertable pg_all, with source column mappings on the left and a multi-row target preview on the right. The time column is source ttimezone; numeric columns include sint, iint, bint, and ddecimal. These names belong to the example source table and are not required for this page's temperature exercise.

PostgreSQL configured multi-column mapping and target result preview

In the actual task, compare types, nulls, and representative values column by column, especially fixed-point decimal precision and the source time zone. Scroll horizontally through all result columns, then return to this page's ts, device, and temperature configuration. Numeric values appearing in the preview do not prove that all column types and the complete window have passed verification.

3. Time and Query Range​

Connection itemConfiguration
Server address, port, database, user, and passwordEnter the source service and authorized identity. Qualify the schema in SQL, such as public.readings; it is not the database name.
Application nameIdentifies this task's source connections, for example taosx_postgres_demo. It does not participate in target child table naming.
SSL modeThe UI offers DISABLE, ALLOW, PREFER, and REQUIRE. Neither DISABLE nor ALLOW attempts TLS. PREFER prefers TLS but permits plaintext fallback; REQUIRE requires TLS but does not imply strict server identity verification. The initial value is PREFER; explicitly select a mode according to source security policy in production.
CA and client certificateFor certificates or strict verification, confirm the DSN entry point and material described below. The UI has no corresponding file-upload fields. REQUIRE does not mean server identity has been verified.

PostgreSQL application name and SSL mode settings

The direct source DSN's ssl_mode also supports VERIFY_CA and VERIFY_FULL. The former verifies the certificate trust chain; the latter additionally verifies the server host name. Neither appears in the UI dropdown above. ssl_ca applies to these two modes, while client-identity parameters ssl_client_cert and ssl_client_key apply to the VERIFY_FULL branch. All are accessible file paths on the actual reading host. Before using this entry point, ask the administrator to confirm complete query, mapping, and certificate configuration. Adding file parameters to other modes does not enable mutual authentication. Do not disable source verification to accommodate UI options.

warning

Use ${start}/${end} for timestamp with time zone. Use ${start_no_tz}/${end_no_tz} only for timestamp without time zone columns storing wall-clock time in the task time zone. taosX uses the PostgreSQL connection's default session time zone. Recheck the same range in the source client rather than judging shifts from target display alone.

In the following image, the page time zone was set to UTC before filling the form. It uses a one-minute window from 2026-11-20 00:00:00 to 00:01:00, a 1 hour query interval, and 0 seconds delay. Replace this with a source-confirmed window containing data, and check the source column's time zone semantics.

PostgreSQL one-minute UTC window and one-hour query interval

The SQL template is a single-line input. The following image shows the end of the same input scrolled to the right; the complete statement is in section 2:

PostgreSQL time boundaries and ordering at the end of the same SQL template

For a column without a time zone that stores wall-clock time in the task time zone, change the example condition to ts >= ${start_no_tz} AND ts < ${end_no_tz}. Literals with and without offsets both expand to seconds, with quotes already added by taosX. See Time Placeholders for expansion and Time and Time Zone for the task time zone source and template-dependent offset limits. The page's time settings do not mean the source connection session has been adjusted automatically. Ask the source administrator to confirm, especially when source SQL includes implicit type conversions.

For query interval, delay, and device partitioning, see Common Relational Database Rules. Start with a bounded window before configuring continuous queries. Assess late-arriving historical source data separately.

For direct source DSN types, defaults, conditions for TLS files to take effect, and the minimum real-time window, see PostgreSQL Read Parameters. The connector lowercases the connection application name. The task's fixed-offset time zone applies only to windows and templates and does not automatically change source session TimeZone. To check sessions or source type conversion, ask the administrator to verify actual connection settings in the source client. Changing the target display time zone does not replace this check.

The UI initially sets the query interval to 1 day and delay to 0 seconds; explicitly set a small exercise window. The initial sample limit is 5 rows and request timeout is 30 seconds. Available samples only show that this trial read succeeded. After samples, mapping, and target preview are complete, start the task and verify the complete window's results.

3.1 Querying a BIGINT Millisecond Time Source​

Some source tables store Unix milliseconds in epoch_ms BIGINT rather than a date type. Do not compare the source column directly with date placeholders. First convert the task window to integers in the same units in SQL. With the task configured in UTC, the source session time zone confirmed by the administrator, and whole-day read windows, use:

SELECT epoch_ms, device, temperature FROM public.readings_epoch
WHERE epoch_ms >= EXTRACT(EPOCH FROM TIMESTAMP ${start_date})::bigint * 1000
AND epoch_ms < EXTRACT(EPOCH FROM TIMESTAMP ${end_date})::bigint * 1000
ORDER BY epoch_ms;

Use ${start_date} and ${end_date} as a pair. They expand to dates in the task time zone without hours, minutes, or seconds. This example therefore suits explicitly whole-day windows. Do not truncate an arbitrary minute window to dates and treat them as precise boundaries. To retain time of day, use the earlier time placeholders matching the source type and check the actual expressions in the source client.

EXTRACT(EPOCH ...) returns seconds; multiply by 1000 to compare with a millisecond column. Do not use that multiplier for seconds or microseconds. First record the expected millisecond integers for the window boundaries in the PostgreSQL client, then recheck row counts with the same SQL. Finally map epoch_ms to the target timestamp in milliseconds, and compare target row counts and time boundaries.

4. Advanced Options and Write Error Policies​

Expand Advanced Options first and record read concurrency, batch, health monitoring, and queue settings. Establish a small-window baseline before adjusting settings individually. Then check Error Handling Policy, especially null times, numeric conversion, and string length. Allowing automatic schema changes does not migrate PostgreSQL constraints, indexes, or transactional semantics. Archiving or discarding can also leave fewer target rows than the source query results.

For direct DSN defaults, zero values, and actually supported options, see Advanced Query Source Parameters. Controls with the same name do not necessarily take effect identically; check the submitted configuration first.

For viewing actual archives and backfilling, see Write Errors and Invalid Data. For tuning, see Tuning and Resource Control.

5. Verification​

Run SELECT ts, temperature, device FROM postgres_demo.t_d001 ORDER BY ts LIMIT 20; in taosExplorer's Data Browser or the taos CLI, replacing example d001 with the child table for the actual device. Compare times, numeric values, nulls, and devices against the same source window.

6. Troubleshooting​

SymptomChecks
Connection or SSL failsCheck the address, authentication rules, and SSL requirements from the reading host. Do not weaken server policy to connect.
Table missing or permission deniedCheck database, schema, case, and account permissions. Do not rely on a different search path.
Data differs by a fixed number of hoursCheck source column types, connection session, and task time zone, then compare the same instant.

For other task, write, and runtime issues, see Troubleshooting by Symptom.

7. Stop, Resume, and Limitations​

Retain the original task and verified windows. After starting the original task, check the interrupted range. Window queries do not automatically migrate PostgreSQL constraints, indexes, functions, or all historical changes. Test special types and precision separately before expanding the migration scope.