---
id: I0165
title: "Postgres finalized promotion flag"
url: https://carbium.sh/library/integrate/postgres-finalized-promotion-flag
collection: Integrations
category: Relational databases
revision: 1
updated: 2026-11-23
author: Carbium
code: MIT (LICENSE in the zip); text: all rights reserved, Carbium Corporation
---

# Postgres finalized promotion flag

A small job reads the newest confirmed signatures for one address, stores each transaction's logs at confirmed, and sets an is_final flag once the signature reaches finalized.

## What the job stores

Solana moves a transaction through processed, confirmed and finalized, so the same signature can be read at confirmed before it reaches finalized. This job reads the logs at confirmed, writes them to a row, and marks the row not final. A later step asks for the status of the open rows and sets the flag once a status reads finalized. The logs stay as the first read wrote them, so the record exists before finalized arrives.

Each row is one signature. The table lists the columns and the step that writes each one.

| Column | Written when | Holds |
|---|---|---|
| signature | the address's newest confirmed signatures are read | the transaction signature, the primary key |
| slot | the same read | the slot the transaction landed in |
| logs | a confirmed read of the transaction returns it | a JSON array of the program log lines |
| is_final | a status read shows finalized | 0 until then, 1 after |

## Reading the logs at confirmed

The first call is getSignaturesForAddress with commitment confirmed and a limit of 5, which returns the newest signatures for the address. Each row without logs then gets getTransaction with commitment confirmed, json encoding and maxSupportedTransactionVersion set to 1. Mainnet carries v1 transactions, and with that option absent or 0 the call answers -32015 for a v1 transaction or for a block that holds one. Calls go to `https://services.carbium.sh` with the key in the `x-api-key` header. Each of the two calls costs 50 cells, so a pass that reads five transactions spends 300 cells: 50 for the signature list and 50 for each read.

Both calls carry their commitment explicitly. The JSON-RPC server defaults to finalized, and @solana/kit fills in confirmed when a call leaves the field out, so writing it down keeps the job reading the level the reader asked for. A getTransaction answer of null means the node does not hold that transaction yet. The row keeps logs null and the next pass reads it again.

## Promoting rows to finalized

The second step takes up to 100 rows with is_final 0 and asks getSignatureStatuses for all of them in one call. A status whose confirmationStatus is finalized sets is_final to 1. Any other value, and a null status, leaves the row open. Since the Alpenglow switch a slot takes about 200 ms, and finalized sits 0 to 1 slots behind processed, so a pass every few seconds catches rows as they reach finalized.

Promotion changes only the flag. The logs written at confirmed stay as they were read, so the row keeps what the node reported before finalized.

## The job

The file is one pass. It takes an address as its first argument and reads the Memo program by default, a busy address with recent signatures. It writes `confirm-log.db` in the working directory and uses `node:sqlite`, because the entry relies on Node built-ins only. The table and both UPDATE statements are plain SQL, so a Postgres table with the same columns runs the same logic through a driver of your choice.

`main.ts` (run: `node main.ts`)

```ts
// I0165 · Postgres finalized promotion flag
// https://carbium.sh/library/integrate/postgres-finalized-promotion-flag
// Copyright (c) Carbium Corporation. MIT License (LICENSE). Keep this notice.
// SPDX-License-Identifier: MIT

import { createDefaultRpcTransport, createSolanaRpcFromTransport } from "@solana/kit";
import type { Address, Signature } from "@solana/kit";
import { DatabaseSync } from "node:sqlite";

const key = process.env.CARBIUM_KEY;
if (!key) {
  console.error("Set CARBIUM_KEY to your Carbium key.");
  process.exit(1);
}
const rpc = createSolanaRpcFromTransport(
  createDefaultRpcTransport({
    url: process.env.CARBIUM_RPC_URL ?? "https://services.carbium.sh",
    headers: { "x-api-key": key },
  }),
);
const address = (process.argv[2] ?? "MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr") as Address;

const db = new DatabaseSync("confirm-log.db");
db.exec(`CREATE TABLE IF NOT EXISTS tx_log (
  signature TEXT PRIMARY KEY,
  slot INTEGER NOT NULL,
  seen_at TEXT NOT NULL,
  logs TEXT,
  is_final INTEGER NOT NULL DEFAULT 0
)`);
const addRow = db.prepare("INSERT OR IGNORE INTO tx_log (signature, slot, seen_at) VALUES (?, ?, ?)");
const setLogs = db.prepare("UPDATE tx_log SET logs = ? WHERE signature = ?");
const promote = db.prepare("UPDATE tx_log SET is_final = 1 WHERE signature = ?");

// 1. The newest signatures for the address, read at confirmed.
const recent = await rpc.getSignaturesForAddress(address, { limit: 5, commitment: "confirmed" }).send();
const seenAt = new Date().toISOString();
for (const s of recent) addRow.run(s.signature, Number(s.slot), seenAt);

// 2. Logs for rows that have none, read at confirmed. A failed read is settled, not fatal.
const needLogs = db.prepare("SELECT signature FROM tx_log WHERE logs IS NULL LIMIT 5").all() as { signature: string }[];
const reads = await Promise.allSettled(
  needLogs.map((r) =>
    rpc.getTransaction(r.signature as Signature, { commitment: "confirmed", encoding: "json", maxSupportedTransactionVersion: 1 }).send(),
  ),
);
let stored = 0;
reads.forEach((res, i) => {
  if (res.status === "rejected") {
    console.error(`getTransaction failed for ${needLogs[i].signature}: ${String(res.reason)}`);
  } else if (res.value) {
    setLogs.run(JSON.stringify(res.value.meta?.logMessages ?? []), needLogs[i].signature);
    stored++;
  }
});

// 3. Flip is_final where the status reached finalized.
const open = db.prepare("SELECT signature FROM tx_log WHERE is_final = 0 LIMIT 100").all() as { signature: string }[];
let promoted = 0;
if (open.length > 0) {
  try {
    const { value } = await rpc.getSignatureStatuses(open.map((r) => r.signature as Signature)).send();
    value.forEach((st, i) => {
      if (st?.confirmationStatus === "finalized") {
        promote.run(open[i].signature);
        promoted++;
      }
    });
  } catch (err) {
    console.error(`getSignatureStatuses failed: ${String(err)}`);
  }
}

const counts = db.prepare("SELECT COUNT(*) AS total, SUM(is_final) AS final FROM tx_log").get() as { total: number; final: number | null };
console.log(`${address}: ${recent.length} newest confirmed, ${stored} logs stored, ${promoted} promoted, ${counts.final ?? 0} of ${counts.total} rows final`);
db.close();
```

## Run it and read the counts

Export `CARBIUM_KEY` and run `node main.ts`. Pass another address after the file name to read its signatures instead. The last line names the address and prints the newest signatures read, the logs stored on this pass, the rows promoted, and the final rows out of the total. A first run reads signatures that are seconds old, so the promoted count often stays low. Run the file again a little later and the counts move as the flags flip. To keep the table current, run the pass every few seconds under a supervisor such as a systemd user timer.

A read that fails is logged with its signature and reason, and the other reads still store. The key comes from the environment only and is never printed.

## What it costs on your plan

Free allows 0.24 req/s for getSignaturesForAddress, about one call every four seconds, and each pass makes one of those. The getTransaction reads share the [RPC table](https://carbium.sh/docs/rpc), where each plan sets its own rate. [Limits are per account](https://carbium.sh/docs/limits), so every key on one account draws from one budget.

A call over its rate waits once and is served if its cells refill within 1 s. Past that it gets 429 with a retry-after hint. The job settles each read, so a 429 on one row leaves that row's logs null and the next pass reads it again. On a Free key a pass that reads five transactions at once may see some of them throttled, so pace the pass or move to a plan with more req/s.

## Where it ends

- `getSignaturesForAddress` reaches back 30 days at most, from its own [address index](https://carbium.sh/docs/migrate). Older signatures are not served, and an empty page past that age marks the index's limit.
- The index reaches below the validator's ledger floor, so a getTransaction call can answer null for an older signature the index lists. The row stays open with null logs, and the job does not treat that as an error.
- A signature whose fork is dropped never reaches finalized. Its row stays at is_final 0, and getSignatureStatuses may return null for it. This job leaves such rows open. A rule that retires them is yours to add, for example a column that records the drop.
- The job reads the five newest signatures per pass, so an address that gets more than five new signatures between passes loses the ones in between. For every log line as it happens, [WebSocket](https://carbium.sh/docs/websocket) `logsSubscribe` streams transaction logs, all or by mention, and it suits a feed that needs lines as they land.
- SQLite stands in for Postgres in this file. The Postgres driver, its connection and its table are not part of it.
- For a deeper check of transactions that never land, see the [dropped transaction detector](https://carbium.sh/library/howsolana/dropped-transaction-detector).

## When it goes wrong

| What goes wrong | What to do |
|---|---|
| getTransaction answers -32015 for a signature the job reads. | Set maxSupportedTransactionVersion to 1 with encoding json on each getTransaction call, as the file does. Mainnet holds v1 transactions, so a missing option fails on those. |
| Rows stay at is_final 0 for days and never promote. | Check getSignatureStatuses for those rows. A signature from a dropped fork never reaches finalized, so record those rows in a separate column and stop selecting them. |
| The read step logs 429 with a retry-after hint on a Free key. | Lower the number of reads per pass, or move the key to a plan with more req/s for getTransaction. Throttled rows keep null logs, and the next pass reads them. |
| The logs column stays null for a signature the job listed. | The node may not hold that transaction yet, or the signature sits below the index's ledger floor. A null answer is not a failure, so leave the row for the next pass. |
| The run exits on the first read with a 401 response. | The key was refused at the door. Send the whole key in the x-api-key header, as the file does. An unknown key gets 401 with UNKNOWN_KEY, see [errors](https://carbium.sh/docs/errors). |

## Questions

### Can I get the logs of a confirmed transaction before it is finalized?

Yes. Pass commitment confirmed to getTransaction and the logs come back from the confirmed state. The job stores them at that point and leaves is_final at 0 until the status reads finalized.

### Why keep the rows that never reach finalized?

Their logs are the record of what the node showed at confirmed. Deleting them would hide the difference between a transaction that was never final and one the job failed to read.

### Does the job need a WebSocket?

No. The pass polls, and each call costs cells. A logsSubscribe stream pushes lines as they land, which suits a feed that cannot wait for the next pass.

### Can the same table live in Postgres?

Yes. The schema and both UPDATE statements are plain SQL, so a Postgres driver runs them with the same parameters. This file uses node:sqlite because the entry relies on Node built-ins only.

## Related

- [Dropped transaction detector](https://carbium.sh/library/howsolana/dropped-transaction-detector) (How to use Solana, HS0028)
- [Memo payment lookup](https://carbium.sh/library/usecase/memo-payment-lookup) (Use cases, UC0022)
- [carbium.sh/docs/rpc](https://carbium.sh/docs/rpc)
- [carbium.sh/docs/limits](https://carbium.sh/docs/limits)
- [carbium.sh/docs/migrate](https://carbium.sh/docs/migrate)
- [carbium.sh/docs/websocket](https://carbium.sh/docs/websocket)
- [carbium.sh/docs/errors](https://carbium.sh/docs/errors)
