Table of Contents

Method EnsureDatabaseExistsAsync

Namespace
LMKit.Data.Storage.PgVector
Assembly
LM-Kit.NET.Data.Connectors.PgVector.dll

EnsureDatabaseExistsAsync(string, string, CancellationToken)

Ensures that the PostgreSQL database named in the supplied connection string exists, creating it if it does not. Because a connection cannot be opened to a database that does not yet exist, this method connects to an existing maintenance database (maintenanceDatabase, postgres by default) using the same host and credentials, and issues CREATE DATABASE there.

public static Task EnsureDatabaseExistsAsync(string connectionString, string maintenanceDatabase = "postgres", CancellationToken cancellationToken = default)

Parameters

connectionString string

A connection string whose Database value identifies the database to ensure exists. The same host, port, and credentials are reused to reach the maintenance database.

maintenanceDatabase string

An existing database to connect to in order to issue CREATE DATABASE. Defaults to postgres.

cancellationToken CancellationToken

An optional token to cancel the operation.

Returns

Task

A task that completes once the target database exists.

Remarks

The connecting role must have the CREATEDB privilege and access to the maintenance database. This method only creates the database; it does not install the vector extension (that is a server-side installation) nor create any collections.

Exceptions

ArgumentException

Thrown when the connection string is null/empty or specifies no database.

Share