CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-pg-native

A slightly nicer interface to Postgres over node-libpq providing both sync and async operations

88

1.20x

Quality

Pending

Does it follow best practices?

Impact

88%

1.20x

Average score across 10 eval scenarios

Overview
Eval results
Files

task.mdevals/scenario-4/

PostgreSQL Replication Status Monitor

Overview

Build a Node.js application that connects to a PostgreSQL server in replication mode to monitor replication status and slot information. The application should establish a special connection that allows querying replication-specific system views.

Requirements

Connection Configuration

Create a connection that enables replication mode. The connection should:

  • Connect to a PostgreSQL server
  • Enable special replication protocol capabilities
  • Handle connection errors appropriately

Replication Information Query

Implement functionality to query and display replication information:

  1. Query the pg_replication_slots system view to retrieve active replication slots
  2. Extract and display the following information for each slot:
    • Slot name
    • Slot type
    • Database name
    • Active status
  3. Handle cases where no replication slots exist

Output Format

Display the retrieved information in a clear, structured format. For each replication slot, show all relevant fields.

Error Handling

  • Handle connection failures gracefully
  • Handle cases where replication features are not available
  • Display appropriate error messages

Dependencies { .dependencies }

pg { .dependency }

PostgreSQL client for Node.js providing connection management and query execution.

Test Cases

Test 1: Replication Mode Connection @test

File: replication.test.js

Test Description: Verify that the connection can be established with replication mode enabled.

Expected Behavior:

  • Connection should be created with replication mode configuration
  • Connection should successfully connect to the PostgreSQL server without errors
  • Connection should be able to query replication-specific views

Test 2: Query Replication Slots @test

File: replication.test.js

Test Description: Verify that the application can query and retrieve replication slot information.

Expected Behavior:

  • Should successfully execute query against pg_replication_slots
  • Should return results containing slot information (or empty array if no slots)
  • Should handle the query result correctly

Test 3: Handle Empty Replication Slots @test

File: replication.test.js

Test Description: Verify proper handling when no replication slots are configured.

Expected Behavior:

  • Query should succeed even with no replication slots
  • Should return empty result set
  • Should not throw errors for empty results

Implementation Notes

  • Use appropriate connection configuration options to enable replication features
  • Ensure proper resource cleanup (close connections when done)
  • The application should work with PostgreSQL 10 or later
  • Consider that replication mode connections have different capabilities than normal connections

Install with Tessl CLI

npx tessl i tessl/npm-pg-native

tile.json