Skip to main content

Netherframe PostgreSQL Backend

PostgreSQL backend implementation for Netherframe: state in PostgreSQL, with a state lock and conditional writes for hybrid execution.

Features

  • PostgreSQL State Storage: Store infrastructure state in PostgreSQL with JSONB columns for optimal querying
  • State Locking: one lock per state (state_id), held by a hybrid run from planning through approval to the end of apply (see Locking)
  • ACID Transactions: Leverage PostgreSQL's ACID guarantees for state consistency
  • Connection Pooling: Efficient connection management for high-performance operations
  • Hybrid Mode Support: Works with both synthesis mode (Terraform) and hybrid execution mode
  • Conditional Writes: a write replaces only the state version its run read (the state row is locked FOR UPDATE while compared and written)
  • Force-Unlock and Checkpoints: a crashed run's lock is released by its ID (nf state force-unlock); pre-apply checkpoints are rows of their own

Installation

pip install netherframe.backends.postgresql

Configuration

from nf.backends.postgresql import PostgreSQLBackend

# Basic configuration
backend = PostgreSQLBackend(
    nf_scope=stack,
    host="localhost",
    port=5432,
    database="netherframe_state",
    username="nf_user",
    password="your_password",
)

# Advanced configuration with SSL and custom schema
backend = PostgreSQLBackend(
    nf_scope=stack,
    host="db.example.com",
    port=5432,
    database="infrastructure",
    username="nf_user",
    password="your_password",
    schema="netherframe",
    ssl_mode="require",
    table_prefix="nf_",
    pool_size=10,
    max_overflow=20,
)

Schema

The backend creates the following tables:

  • nf_states: Main state storage with JSONB data
  • nf_locks: State locks, one per state_id
  • nf_resource_locks: Locks taken through the resource-lock API (see below); hybrid execution does not use them

Locking

Hybrid execution locks the whole state, as Terraform does; it does not lock individual resources:

  • apply takes the lock on its state_id before planning and holds it through the approval prompt to the end of the apply; plan holds it while planning.
  • A second run on the same state does not wait: it fails to take the lock (Failed to acquire state lock) and logs who holds it. Concurrent applies on one state are therefore serialized, never interleaved.
  • Every state write is conditional: it replaces only the state version (serial and lineage) the run read, with the row locked FOR UPDATE while it is compared and written. A saved plan is rejected if state changed since it was created.
  • The lock expires lock_timeout seconds (default 300) after its holder last renewed it; a running holder renews it in the background. nf state force-unlock releases the lock of a crashed run at once.

Changes that must be applied independently, at the same time, need separate states: give each independently deployed app its own state_id.

Resource-Lock API

The backend also has acquire_resource_lock, release_resource_lock, release_all_resource_locks and resource_lock_context: shared and exclusive locks on a resource id, with timeouts, stored in nf_resource_locks (see example_usage.py). Netherframe's hybrid execution never calls them, and they do not let two runs apply to one state at once. They are only useful to coordinate your own tooling.

Settings

Each connection setting is a flag of nf, else a key of [tool.nf.config] in pyproject.toml, else the backend's argument, else the default. Nothing is read from the environment.

  • --postgresql-host / postgresql_host: Database host (default: localhost)
  • --postgresql-port / postgresql_port: Database port (default: 5432)
  • --postgresql-database / postgresql_database: Database name
  • --postgresql-username / postgresql_username: Database username
  • --postgresql-ssl-mode / postgresql_ssl_mode: SSL mode (disable, allow, prefer, require, verify-ca, verify-full)
  • --postgresql-password-file / postgresql_password_file: File holding the database password (a mounted secret). The password is never a flag. In code, PostgreSQLBackend also takes password=, and PostgreSQLGraphBackend takes password_file= or password_source= (a callable).
[tool.nf.config]
postgresql_host = "db.internal"
postgresql_database = "netherframe"
postgresql_username = "nf_apply"
postgresql_password_file = "/run/secrets/postgresql-password"

See the Settings reference.

Metadata

Release files for netherframe.backends.postgresql 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for netherframe.backends.postgresql 0.2.1
File Size Uploaded Provenance Actions
netherframe_backends_postgresql-0.2.1.tar.gz 90.6 kB Without provenance Details for netherframe_backends_postgresql-0.2.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for netherframe.backends.postgresql 0.2.1
File Interpreter ABI Platform Actions
netherframe_backends_postgresql-0.2.1-py3-none-any.whl Python 3 none any Details for netherframe_backends_postgresql-0.2.1-py3-none-any.whl

Total release size: 197.7 kB

Release files / netherframe_backends_postgresql-0.2.1.tar.gz

Download URL netherframe_backends_postgresql-0.2.1.tar.gz
Size 90.6 kB
Tags Source
SHA-256 checksum
How to use checksums
790255d08e0c29a9ef9970e6c8a62511fe022e8c1a1311732d2f3f70b9c79d42
BLAKE2b-256 checksum
How to use checksums
38cc954b91d23eea6ed6078653986f1389f12c379a16d7b9082ca1604c8f4a72
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.9 {"installer":{"name":"uv","version":"0.13.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"CachyOS Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / netherframe_backends_postgresql-0.2.1-py3-none-any.whl

Download URL netherframe_backends_postgresql-0.2.1-py3-none-any.whl
Size 107.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c9251459c4e51112a877c89c9cc7aedf0f6b89818ff69aadc073743f0e9ccd96
BLAKE2b-256 checksum
How to use checksums
285e8a3389fe405f609bed676442b48291ea520f5fb1128b0385d08f756d458a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.9 {"installer":{"name":"uv","version":"0.13.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"CachyOS Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for netherframe.backends.postgresql 0.2.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page