Buffaly Logo Buffaly

Use Buffaly with PostgreSQL

Use the supplied Unix package to provision PostgreSQL session storage and semantic search for a Root environment. Select each database provider explicitly, keep the installed configuration intact and use the registered upgrade path for existing databases.

Know which environment PostgreSQL supports

  • Root environment: the host supports PostgreSQL sessions, action/entity semantic discovery and session-history semantic search. Root is the environment selection, not the PostgreSQL superuser, an operating-system root account or a database named Root.
  • User environment: the current session-ownership implementation requires configured SQL Server session storage and rejects PostgreSQL and hybrid providers. PostgreSQL Root support does not enable per-user ownership or the SQL Server-only User source-corpus capability. Authentication being enabled does not change this provider boundary.
  • Session persistence: Infrastructure Feature accepts exactly file or database-source. This is separate from AppSettings.BuffalySessionsDb.ProviderMode. Selecting file does not remove all database dependencies or enable User environments on PostgreSQL. Changing either setting does not migrate existing data.
  • Packaged setup: the documented shell flow selects linux-x64, linux-arm64 or Apple Silicon osx-arm64. Follow Linux installation or Mac installation for archive verification, native dependencies and launch. The Windows MSI/instance-provisioning procedures in this documentation are SQL Server procedures; a provider implementation alone is not a Windows PostgreSQL installer.

Prepare the server and setup identity

  1. Obtain the validated package, matching checksum, release identity and platform/profile evidence from the deployment owner. Core Provisioning owns Build ID selection, package construction, validation and wrapping. Installing the supplied package does not require building from source.
  2. Prepare a reachable PostgreSQL server with the vector extension available, including the HNSW index/operator support used by the packaged schema. Both target databases need that extension: the bootstrap applies the complete PostgreSQL schema to each. The current vector storage contract is 1536 dimensions. Match the release's tested PostgreSQL/pgvector versions rather than assuming any server version or client-only installation is sufficient.
  3. Put psql on the setup and maintenance user's PATH. Prepare bash and Python 3 through the platform guide. Mac Homebrew libpq supplies a client, not a server, and its bin directory may need an explicit PATH entry in a non-interactive maintenance shell.
  4. Use two distinct database names: one for sessions/Features/history and one for action/entity semantics. The setup role must connect to the maintenance postgres database, create targets when absent, and own or have the DDL/extension permissions needed to apply every packaged schema/routine/index script. A DBA may precreate the databases and extension with the required ownership. A runtime-only SELECT/DML role is not enough for bootstrap or later schema upgrades.
  5. The installer does not create a PostgreSQL login, grant a canned runtime role or automatically swap administration credentials for a restricted application identity. It uses the supplied connections for setup and writes them into role configuration. Plan any later credential separation with the deployment/database owner, including complete configuration replacement and the credentials required for the next authorized upgrade.

Use simple Host=...;Port=5432;Database=...;Username=...;Password=... connections with this shell flow. Its bootstrap helper splits on semicolons and extracts only those fields; quoted values containing semicolons are not parsed as an Npgsql connection-string builder would parse them. psql follows libpq authentication/TLS settings such as an approved password file and PGSSLMODE/PGSSLROOTCERT; runtime Npgsql follows its connection settings. Extra TLS options in the runtime string are not forwarded by the shell helper to psql. Configure and verify trust for both clients without printing passwords.

Fresh-install package prerequisite: scripts/configure.sh must have valid embedded Python and an unindented closing PY marker. The current source copy has leading whitespace in that block and cannot complete settings generation. Use a corrected, validated package before fresh setup. A shell syntax check can warn about an unterminated heredoc while still returning zero; the deployment owner's check must also cover the embedded Python.

Let the fresh installer own schema and Features setup

After completing the platform prerequisites and verifying an unused root and fresh databases, run the supplied scripts/install.sh with --sql-mode postgresql, --sessions-connection and --semantic-connection. Set the connection variables, root, port and none/required authentication choice as described in the platform guide. This shared command illustrates the database-selection contract; use the actual supplied package path.

bash '<extracted-package-root>/scripts/install.sh' \
  --install-root "$BUFFALY_INSTALL_ROOT" \
  --port "$BUFFALY_PORT" \
  --auth "$BUFFALY_AUTH_MODE" \
  --sql-mode postgresql \
  --sessions-connection "$BUFFALY_SESSIONS_CONNECTION_STRING" \
  --semantic-connection "$BUFFALY_SEMANTICDB_CONNECTION_STRING"

The package builder copies Buffaly.Sessions.DB.PostGres/Scripts into scripts/postgres and adds a clean-install release receipt. The installer checks or creates each database through postgres, applies all packaged scripts/postgres/*.sql files in filename order to both targets, renders settings, then seeds Features and installation paths in the sessions database. These actions are writes, not connectivity tests. The clean-install receipt rejects existing session/message data or an existing release receipt; do not replay this directory as a repair or update procedure.

configure.sh --database-provider postgresql selects and renders configuration; it does not create databases, install pgvector, apply schema or migrate data. Fresh rendering replaces role settings and app-local copies. Do not rerun it over an existing installation to change one connection or repair a failed bootstrap.

Select the provider for each store

Inspect the complete role settings under config/agent-web, config/agent-worker and config/sessions-web. Set ProviderMode to postgresql in each participating section and verify its PostgresConnectionStringName resolves to the intended database.

AppSettings sectionSelected connection nameUnix-rendered target
BuffalySessionsDbbuffaly_sessions.postgres.readwriteSessions, Features and related records
BuffalySemanticDbbuffaly_semanticdb.postgres.readwriteSeparate action/entity semantic database
BuffalySessionSemanticDbbuffaly_session_semanticdb.postgres.readwriteSessions database, through a distinct connection name

Web and worker configure all three stores independently. The Unix renderer includes sessions/history sections in Sessions.Web settings, but its standalone startup configures the sessions repository; the agent host/worker own the session-history provider initialization shown here. Verify the hosting topology rather than treating a configuration section as proof of a standalone history connection. The Unix renderer also writes the legacy buffaly_sessions.readwrite, buffaly_semanticdb.readwrite and buffaly_session_semanticdb.readwrite aliases with the same corresponding PostgreSQL values. Keep those aliases consistent: current shell update helpers still read the first two and recognize PostgreSQL by Host=. An alias ending in .readwrite does not mean an extra SQL Server database must be created.

For an existing environment, read the complete current document through its configuration/settings owner, apply only the approved connection/provider changes and save the complete document. Preserve authentication, listener, secret references, unrelated keys and required app/role bindings. For database-backed Features or session Data, use the owning read-modify-save operation with the entire existing document; no per-key SQL patch, partial replacement bag or copy of package seed values. Reload and verify both changed and unrelated values. See settings and feature flags and install layout.

Provider selection happens during process startup, before repository initialization. A saved setting alone does not reconfigure a running provider. Any activation/restart is a separate target-owned operation. Database settings, a chat-model provider and an embedding provider are different selections; configure embeddings before relying on semantic search.

Upgrade an existing installation through the registered runner

Keep a matched database/files/configuration recovery set and record the original running/stopped state first. From a maintenance shell with the intended psql PATH and approved credentials, use the new supplied package's script:

bash '<extracted-new-package-root>/scripts/upgrade.sh' \
  --package '<absolute-path-to-supplied-new-tarball>' \
  --install-root '<existing-install-root>' \
  --url 'http://127.0.0.1:<port>/'

The wrapper uses the staged host's registered upgrade install command against the package's shared Upgrades SQL/JSON artifacts before canonical Provisioning payload/profile activation. Registered schema/readiness and maintenance verification follow; copying bootstrap files or creating tables alone does not satisfy the current guarded-writer/release contract. Do not substitute scripts/postgres for Upgrades, replay all SQL files or invoke a legacy broad PostgreSQL dispatcher.

The default wrapper stops and starts the selected installation. Use --skip-restart for an originally stopped instance; it also omits HTTP validation. Add --expect-no-auth only when that matches the deployment. Follow the platform guide for systemd or LaunchAgent ownership and retain sibling-root safety. Read manifest/update-receipts/update-*.json; payload/config rollback does not reverse database changes or back up live data.

Check connection identity, schema readiness and saved work

Use approved database credentials and libpq trust settings for a read-only connection check. Repeat for both target databases. This example uses psql's password prompt or an approved password file, rather than putting a password in the command:

psql -X -v ON_ERROR_STOP=1 \
  -h '<postgres-host>' -p 5432 -U '<runtime-user>' \
  -d '<target-database>' \
  -c "SELECT current_database(), current_user, extversion FROM pg_extension WHERE extname = 'vector';"

Confirm the expected database/user and exactly one installed vector-extension row. This query proves that connection and extension visibility only; it does not prove schema compatibility, write permissions or application readiness.

  • Inspect the selected provider, named connection status and resolved root in web and worker without displaying connection secrets. Check the session-history mapping independently of action/entity discovery.
  • Check startup/upgrade results. The sessions provider validates pgvector, required tables and routines, then the exact scalar-storage/guarded-writer readiness contract. Resolve a failure with the matching release/registered upgrade owner, not a fabricated readiness row or copied receipt.
  • Verify expected page content/authentication and worker startup through the platform guide. The current shell validator can accept nonzero HTTP errors or skip HTTP without curl; a success exit alone is not acceptance.
  • In an authorized test, save and reopen a small Root session, inspect exact history and read an artifact's bytes. Verify durability across an approved restart when required. Keep User-environment tests on the supported SQL Server path.
  • Verify a known action/entity semantic result and a separate session-history match against exact source/history. Check the configured embedding model, 1536-dimensional stored vector contract and index state; reindexing is a separate owning operation.

Back up PostgreSQL and disk state together

Use the database owner's PostgreSQL backup/restore process for every distinct target, including required roles/permissions and compatible pgvector availability at restore. Preserve matching configuration, secret/key dependencies, local content, package/profile/release evidence and session/artifact files. Database-source mode still stores artifact bytes on disk. Restore into isolated databases, root and listener first; validate provider/schema compatibility, history and artifact access before cutover. Follow administrator storage, backup and restore and the storage-role reference.