### Install Pulumi PostgreSQL Provider Source: https://context7.com/pulumi/pulumi-postgresql/llms.txt Install the Pulumi PostgreSQL provider for your chosen language. ```bash # Node.js / TypeScript npm install @pulumi/postgresql # Python pip install pulumi_postgresql # Go go get github.com/pulumi/pulumi-postgresql/sdk/v3 # .NET dotnet add package Pulumi.Postgresql ``` -------------------------------- ### GCP SQL Instance and Database Setup (Python) Source: https://github.com/pulumi/pulumi-postgresql/blob/master/docs/_index.md Provisions a GCP SQL PostgreSQL instance and a database using Pulumi with Python. Requires GCP and PostgreSQL providers. ```python import pulumi import pulumi_gcp as gcp import pulumi_postgresql as postgresql test = gcp.sql.DatabaseInstance("test", project="test-project", name="test-instance", database_version="POSTGRES_13", region="europe-west3", settings={ "tier": "db-f1-micro", }) postgres = gcp.sql.User("postgres", project="test-project", name="postgres", instance=test.name, password="xxxxxxxx") test_db = postgresql.Database("test_db", name="test_db") ``` -------------------------------- ### GCP SQL Instance and Database Setup (TypeScript) Source: https://github.com/pulumi/pulumi-postgresql/blob/master/docs/_index.md Provisions a GCP SQL PostgreSQL instance and a database using Pulumi with TypeScript. Requires GCP and PostgreSQL providers. ```typescript import * as pulumi from "@pulumi/pulumi"; import * as gcp from "@pulumi/gcp"; import * as postgresql from "@pulumi/postgresql"; const test = new gcp.sql.DatabaseInstance("test", { project: "test-project", name: "test-instance", databaseVersion: "POSTGRES_13", region: "europe-west3", settings: { tier: "db-f1-micro", }, }); const postgres = new gcp.sql.User("postgres", { project: "test-project", name: "postgres", instance: test.name, password: "xxxxxxxx", }); const testDb = new postgresql.Database("test_db", {name: "test_db"}); ``` -------------------------------- ### Provision Full Application Database Stack Source: https://context7.com/pulumi/pulumi-postgresql/llms.txt This example provisions a complete application database stack, including roles, a database, a schema, grants, default privileges, and extensions. It demonstrates dependency management between resources and the use of Pulumi secrets for sensitive information. ```typescript import * as pulumi from "@pulumi/pulumi"; import * as postgresql from "@pulumi/postgresql"; // 1. Group role for read-only access const readonlyRole = new postgresql.Role("readonly", { name: "readonly", login: false, inherit: true, }); // 2. Application service account (write-only password) const appUser = new postgresql.Role("app-user", { name: "myapp", login: true, passwordWo: pulumi.secret("my-app-password"), passwordWoVersion: "1", connectionLimit: 50, roles: [readonlyRole.name], }, { dependsOn: [readonlyRole] }); // 3. Database const appDb = new postgresql.Database("app-db", { name: "myapp_production", owner: appUser.name, template: "template0", encoding: "UTF8", lcCollate: "en_US.utf8", lcCtype: "en_US.utf8", }, { dependsOn: [appUser] }); // 4. Extensions const pgcrypto = new postgresql.Extension("pgcrypto", { name: "pgcrypto", database: appDb.name, schema: "public", }, { dependsOn: [appDb] }); // 5. Application schema const appSchema = new postgresql.Schema("app-schema", { name: "app", database: appDb.name, owner: appUser.name, policies: [{ role: "readonly", usage: true, create: false }], }, { dependsOn: [appDb] }); // 6. Grant CONNECT on database const dbConnect = new postgresql.Grant("db-connect", { database: appDb.name, role: appUser.name, objectType: "database", privileges: ["CONNECT"], }, { dependsOn: [appDb] }); // 7. Grant schema usage + DML on tables const schemaUsage = new postgresql.Grant("schema-usage", { database: appDb.name, role: appUser.name, schema: "public", objectType: "schema", privileges: ["USAGE", "CREATE"], }, { dependsOn: [appSchema] }); // 8. Default privileges: auto-grant SELECT on future tables to readonly const defaultReadonly = new postgresql.DefaultPrivileges("default-readonly", { database: appDb.name, schema: "public", role: "readonly", owner: appUser.name, objectType: "table", privileges: ["SELECT"], }, { dependsOn: [appSchema] }); // 9. Revoke public schema access from PUBLIC role const revokePublic = new postgresql.Grant("revoke-public", { database: appDb.name, role: "public", schema: "public", objectType: "schema", privileges: [], }, { dependsOn: [appDb] }); export const databaseName = appDb.name; export const appUsername = appUser.name; ``` -------------------------------- ### Deploy Multiple PostgreSQL Databases in C# Source: https://github.com/pulumi/pulumi-postgresql/blob/master/docs/_index.md Deploy two PostgreSQL databases using the Pulumi PostgreSQL provider in C#. Ensure the `Pulumi.PostgreSql` NuGet package is installed. ```csharp using System.Collections.Generic; using System.Linq; using Pulumi; using PostgreSql = Pulumi.PostgreSql; return await Deployment.RunAsync(() => { var myDb1 = new PostgreSql.Database("my_db1", new() { Name = "my_db1", }); var myDb2 = new PostgreSql.Database("my_db2", new() { Name = "my_db2", }); }); ``` -------------------------------- ### Configure PostgreSQL Provider with Password and SSL Source: https://context7.com/pulumi/pulumi-postgresql/llms.txt Configure the provider connection to a PostgreSQL server using password authentication and SSL. This example shows explicit provider instantiation for multi-server stacks. ```typescript import * as postgresql from "@pulumi/postgresql"; // Provider can also be instantiated explicitly for multi-server stacks const prod = new postgresql.Provider("prod", { host: "prod-db.example.com", port: 5432, username: "admin", password: process.env.PGPASSWORD, sslmode: "verify-full", sslrootcert: "/etc/ssl/certs/ca.pem", maxConnections: 20, connectTimeout: 30, superuser: false, }); const staging = new postgresql.Provider("staging", { host: "staging-db.example.com", username: "admin", password: process.env.STAGING_PG_PASSWORD, sslmode: "require", superuser: false, }); // Use explicit provider for a resource const stagingDb = new postgresql.Database("staging-app", { name: "app" }, { provider: staging }); ``` -------------------------------- ### Deploy Multiple PostgreSQL Databases in Python Source: https://github.com/pulumi/pulumi-postgresql/blob/master/docs/_index.md Deploy two PostgreSQL databases using the Pulumi PostgreSQL provider in Python. Ensure the `pulumi-postgresql` package is installed. ```python import pulumi import pulumi_postgresql as postgresql my_db1 = postgresql.Database("my_db1", name="my_db1") my_db2 = postgresql.Database("my_db2", name="my_db2") ``` -------------------------------- ### Configure Pulumi Postgresql Provider with SSL Source: https://github.com/pulumi/pulumi-postgresql/blob/master/docs/_index.md Configure the Pulumi Postgresql provider in Pulumi.yaml with SSL enabled. This example specifies the database, host, password, port, SSL mode, and username, assuming SSL is required. ```yaml name: configuration-example runtime: config: postgresql:database: value: postgres postgresql:host: value: postgres_server_ip postgresql:password: value: postgres_password postgresql:port: value: 5432 postgresql:sslmode: value: require postgresql:username: value: postgres_user ``` -------------------------------- ### Configure Pulumi Postgresql Provider Source: https://github.com/pulumi/pulumi-postgresql/blob/master/docs/_index.md Configure the Pulumi Postgresql provider in Pulumi.yaml with connection details and database name. This example sets a connection timeout, database name, host, password, port, SSL mode, and username. ```yaml name: configuration-example runtime: config: postgresql:connectTimeout: value: 15 postgresql:database: value: postgres postgresql:host: value: postgres_server_ip postgresql:password: value: postgres_password postgresql:port: value: 5432 postgresql:sslmode: value: require postgresql:username: value: postgres_user ``` -------------------------------- ### Extension Source: https://context7.com/pulumi/pulumi-postgresql/llms.txt Installs and manages PostgreSQL extensions (e.g., `pgcrypto`, `uuid-ossp`, `pg_trgm`, `hstore`) within a database. ```APIDOC ## postgresql.Extension — Install and manage PostgreSQL extensions ### Description Installs and manages PostgreSQL extensions (e.g., `pgcrypto`, `uuid-ossp`, `pg_trgm`, `hstore`) within a database. ### Parameters #### Path Parameters - **name** (string) - Required - The name of the extension to install. - **database** (string) - Required - The name of the database where the extension will be installed. - **schema** (string) - Optional - The schema where the extension will be installed. Defaults to "public". - **version** (string) - Optional - The version of the extension to install. - **createCascade** (boolean) - Optional - If true, dependencies will also be created. Defaults to false. - **dropCascade** (boolean) - Optional - If true, dependencies will also be dropped. Defaults to false. ### Request Example ```typescript import * as postgresql from "@pulumi/postgresql"; const pgcrypto = new postgresql.Extension("pgcrypto", { name: "pgcrypto", database: "myapp_production", schema: "public", version: "1.3", createCascade: false, dropCascade: false, }); ``` ### Response #### Success Response (200) - **name** (string) - The name of the installed extension. - **database** (string) - The database where the extension is installed. - **schema** (string) - The schema where the extension is installed. ``` -------------------------------- ### Deploy Multiple PostgreSQL Databases in TypeScript Source: https://github.com/pulumi/pulumi-postgresql/blob/master/docs/_index.md Deploy two PostgreSQL databases using the Pulumi PostgreSQL provider in TypeScript. Ensure the `@pulumi/postgresql` package is installed. ```typescript import * as pulumi from "@pulumi/pulumi"; import * as postgresql from "@pulumi/postgresql"; const myDb1 = new postgresql.Database("my_db1", {name: "my_db1"}); const myDb2 = new postgresql.Database("my_db2", {name: "my_db2"}); ``` -------------------------------- ### Manage PostgreSQL Extensions Source: https://context7.com/pulumi/pulumi-postgresql/llms.txt Installs and manages PostgreSQL extensions like `pgcrypto` or `uuid-ossp` within a specified database and schema. Configure `version`, `createCascade`, and `dropCascade` as needed. ```typescript import * as postgresql from "@pulumi/postgresql"; const pgcrypto = new postgresql.Extension("pgcrypto", { name: "pgcrypto", database: "myapp_production", schema: "public", version: "1.3", createCascade: false, dropCascade: false, }); const uuidOssp = new postgresql.Extension("uuid-ossp", { name: "uuid-ossp", database: "myapp_production", schema: "public", }); ``` -------------------------------- ### Configure PostgreSQL Provider in C# Source: https://github.com/pulumi/pulumi-postgresql/blob/master/docs/_index.md Set up a PostgreSQL database instance and user using the GCP provider, then create a PostgreSQL database. Requires Pulumi.Gcp and Pulumi.PostgreSql packages. ```csharp using System.Collections.Generic; using System.Linq; using Pulumi; using Gcp = Pulumi.Gcp; using PostgreSql = Pulumi.PostgreSql; return await Deployment.RunAsync(() => { var test = new Gcp.Sql.DatabaseInstance("test", new() { Project = "test-project", Name = "test-instance", DatabaseVersion = "POSTGRES_13", Region = "europe-west3", Settings = new Gcp.Sql.Inputs.DatabaseInstanceSettingsArgs { Tier = "db-f1-micro", }, }); var postgres = new Gcp.Sql.User("postgres", new() { Project = "test-project", Name = "postgres", Instance = test.Name, Password = "xxxxxxxx", }); var testDb = new PostgreSql.Database("test_db", new() { Name = "test_db", }); }); ``` -------------------------------- ### Query PostgreSQL Tables Source: https://context7.com/pulumi/pulumi-postgresql/llms.txt Get a list of tables from a PostgreSQL database schema. Filter by `tableTypes`, regex, and LIKE patterns. Specify the `database` and target `schemas`. ```typescript import * as postgresql from "@pulumi/postgresql"; const tables = postgresql.getTables({ database: "myapp_production", schemas: ["public", "app_core"], tableTypes: ["BASE TABLE"], likeAnyPatterns: ["order%"], }); export const tableList = tables.then(t => t.tables.map(tbl => tbl.objectName)); // Expected output: ["orders", "order_items", "order_history"] ``` ```go tables, err := postgresql.GetTables(ctx, &postgresql.GetTablesArgs{ Database: "myapp_production", Schemas: []string{"public"}, TableTypes: []string{"BASE TABLE"}, }, nil) if err != nil { return err } for _, t := range tables.Tables { fmt.Println(t.ObjectName, t.SchemaName) } ``` -------------------------------- ### Configure PostgreSQL Provider in Go Source: https://github.com/pulumi/pulumi-postgresql/blob/master/docs/_index.md Provision a GCP SQL database instance and a PostgreSQL database using the Go SDK. Ensure you have the Pulumi GCP and PostgreSQL SDKs imported. ```go package main import ( "github.com/pulumi/pulumi-gcp/sdk/v9/go/gcp/sql" "github.com/pulumi/pulumi-postgresql/sdk/v3/go/postgresql" "github.com/pulumi/pulumi/sdk/v3/go/pulumi" ) func main() { pulumi.Run(func(ctx *pulumi.Context) error { test, err := sql.NewDatabaseInstance(ctx, "test", &sql.DatabaseInstanceArgs{ Project: pulumi.String("test-project"), Name: pulumi.String("test-instance"), DatabaseVersion: pulumi.String("POSTGRES_13"), Region: pulumi.String("europe-west3"), Settings: &sql.DatabaseInstanceSettingsArgs{ Tier: pulumi.String("db-f1-micro"), }, }) if err != nil { return err } _, err = sql.NewUser(ctx, "postgres", &sql.UserArgs{ Project: pulumi.String("test-project"), Name: pulumi.String("postgres"), Instance: test.Name, Password: pulumi.String("xxxxxxxx"), }) if err != nil { return err } _, err = postgresql.NewDatabase(ctx, "test_db", &postgresql.DatabaseArgs{ Name: pulumi.String("test_db"), }) if err != nil { return err } return nil }) } ``` -------------------------------- ### Configure GCP PostgreSQL Instance and User Source: https://github.com/pulumi/pulumi-postgresql/blob/master/docs/_index.md Sets up a GCP PostgreSQL instance and a user. Ensure the `postgresql:host`, `postgresql:password`, and `postgresql:username` configuration values are correctly set to reference your GCP resources. ```java package generated_program; import com.pulumi.Context; import com.pulumi.Pulumi; import com.pulumi.core.Output; import com.pulumi.gcp.sql.DatabaseInstance; import com.pulumi.gcp.sql.DatabaseInstanceArgs; import com.pulumi.gcp.sql.inputs.DatabaseInstanceSettingsArgs; import com.pulumi.gcp.sql.User; import com.pulumi.gcp.sql.UserArgs; import com.pulumi.postgresql.Database; import com.pulumi.postgresql.DatabaseArgs; import java.util.ArrayList; import java.util.Arrays; import java.util.Map; import java.io.File; import java.nio.file.Files; import java.nio.file.Paths; public class App { public static void main(String[] args) { Pulumi.run(App::stack); } public static void stack(Context ctx) { var test = new DatabaseInstance("test", DatabaseInstanceArgs.builder() .project("test-project") .name("test-instance") .databaseVersion("POSTGRES_13") .region("europe-west3") .settings(DatabaseInstanceSettingsArgs.builder() .tier("db-f1-micro") .build()) .build()); var postgres = new User("postgres", UserArgs.builder() .project("test-project") .name("postgres") .instance(test.name()) .password("xxxxxxxx") .build()); var testDb = new Database("testDb", DatabaseArgs.builder() .name("test_db") .build()); } } ``` -------------------------------- ### Create PostgreSQL Flexible Server with Active Directory Authentication (Go) Source: https://github.com/pulumi/pulumi-postgresql/blob/master/docs/_index.md This Go code provisions an Azure PostgreSQL Flexible Server with Active Directory authentication enabled. It fetches the tenant ID using `core.GetClientConfig` and configures the server to use AD authentication, disabling password-based login. ```go package main import ( "github.com/pulumi/pulumi-azure/sdk/v6/go/azure/core" "github.com/pulumi/pulumi-azure/sdk/v6/go/azure/postgresql" "github.com/pulumi/pulumi/sdk/v3/go/pulumi" ) func main() { pulumi.Run(func(ctx *pulumi.Context) error { current, err := core.GetClientConfig(ctx, map[string]interface{}{}, nil) if err != nil { return err } // https://registry.pulumi.io/providers/pulumi/azurerm/latest/docs/resources/postgresql_flexible_server pgsql, err := postgresql.NewFlexibleServer(ctx, "pgsql", &postgresql.FlexibleServerArgs{ Authentication: &postgresql.FlexibleServerAuthenticationArgs{ ActiveDirectoryAuthEnabled: pulumi.Bool(true), PasswordAuthEnabled: pulumi.Bool(false), TenantId: pulumi.String(current.TenantId), }, }) if err != nil { return err } // https://registry.pulumi.io/providers/pulumi/azurerm/latest/docs/resources/postgresql_flexible_server_active_directory_administrator _, err = postgresql.NewFlexibleServerActiveDirectoryAdministrator(ctx, "administrators", &postgresql.FlexibleServerActiveDirectoryAdministratorArgs{ ObjectId: pulumi.String("00000000-0000-0000-0000-000000000000"), PrincipalName: pulumi.String("Azure AD Admin Group"), PrincipalType: pulumi.String("Group"), ResourceGroupName: pulumi.Any(rgName), ServerName: pgsql.Name, TenantId: pulumi.String(pulumi.String(current.TenantId)), }) if err != nil { return err } return nil }) } ``` -------------------------------- ### Deploy Multiple PostgreSQL Databases in Go Source: https://github.com/pulumi/pulumi-postgresql/blob/master/docs/_index.md Deploy two PostgreSQL databases using the Pulumi PostgreSQL provider in Go. Ensure the `github.com/pulumi/pulumi-postgresql/sdk/v3/go/postgresql` package is imported. ```go package main import ( "github.com/pulumi/pulumi-postgresql/sdk/v3/go/postgresql" "github.com/pulumi/pulumi/sdk/v3/go/pulumi" ) func main() { pulumi.Run(func(ctx *pulumi.Context) error { _, err := postgresql.NewDatabase(ctx, "my_db1", &postgresql.DatabaseArgs{ Name: pulumi.String("my_db1"), }) if err != nil { return err } _, err = postgresql.NewDatabase(ctx, "my_db2", &postgresql.DatabaseArgs{ Name: pulumi.String("my_db2"), }) if err != nil { return err } return nil }) } ``` -------------------------------- ### Create PostgreSQL Schema with Policies (Go) Source: https://context7.com/pulumi/pulumi-postgresql/llms.txt Manages a PostgreSQL schema using Go, specifying the database, owner, and access policies. This is an alternative to the TypeScript implementation for schema management. ```go schema, err := postgresql.NewSchema(ctx, "app-schema", &postgresql.SchemaArgs{ Name: pulumi.String("app"), Database: pulumi.String("myapp_production"), Owner: pulumi.String("myapp_role"), Policies: postgresql.SchemaPolicyArray{ &postgresql.SchemaPolicyArgs{ Role: pulumi.String("readonly"), Usage: pulumi.Bool(true), Create: pulumi.Bool(false), }, }, }) ``` -------------------------------- ### Create a PostgreSQL Foreign Server Source: https://context7.com/pulumi/pulumi-postgresql/llms.txt Use this to create and manage PostgreSQL foreign servers for foreign data wrappers. Ensure the `fdwName`, `serverType`, and connection `options` are correctly configured. ```typescript import * as postgresql from "@pulumi/postgresql"; const foreignServer = new postgresql.Server("remote-server", { serverName: "remote_db", fdwName: "postgres_fdw", serverType: "mytype", serverVersion: "14.0", options: { host: "remote.example.com", port: "5432", dbname: "remote_db", }, }); ``` -------------------------------- ### Create PostgreSQL Flexible Server with Active Directory Authentication (C#) Source: https://github.com/pulumi/pulumi-postgresql/blob/master/docs/_index.md This C# code creates an Azure PostgreSQL Flexible Server with Active Directory authentication enabled. It retrieves the tenant ID from the Azure client configuration and sets the server to use AD authentication while disabling password authentication. ```csharp using System.Collections.Generic; using System.Linq; using Pulumi; using Azure = Pulumi.Azure; return await Deployment.RunAsync(() => { var current = Azure.Core.GetClientConfig.Invoke(); // https://registry.pulumi.io/providers/pulumi/azurerm/latest/docs/resources/postgresql_flexible_server var pgsql = new Azure.PostgreSql.FlexibleServer("pgsql", new() { Authentication = new Azure.PostgreSql.Inputs.FlexibleServerAuthenticationArgs { ActiveDirectoryAuthEnabled = true, PasswordAuthEnabled = false, TenantId = current.Apply(getClientConfigResult => getClientConfigResult.TenantId), }, }); // https://registry.pulumi.io/providers/pulumi/azurerm/latest/docs/resources/postgresql_flexible_server_active_directory_administrator var administrators = new Azure.PostgreSql.FlexibleServerActiveDirectoryAdministrator("administrators", new() { ObjectId = "00000000-0000-0000-0000-000000000000", PrincipalName = "Azure AD Admin Group", PrincipalType = "Group", ResourceGroupName = rgName, ServerName = pgsql.Name, TenantId = current.Apply(getClientConfigResult => getClientConfigResult.TenantId), }); }); ``` -------------------------------- ### Deploy Multiple PostgreSQL Databases in Java Source: https://github.com/pulumi/pulumi-postgresql/blob/master/docs/_index.md Deploy two PostgreSQL databases using the Pulumi PostgreSQL provider in Java. Ensure the `com.pulumi/postgresql` dependency is included. ```java package generated_program; import com.pulumi.Context; import com.pulumi.Pulumi; import com.pulumi.core.Output; import com.pulumi.postgresql.Database; import com.pulumi.postgresql.DatabaseArgs; import java.util.ArrayList; import java.util.Arrays; import java.util.Map; import java.io.File; import java.nio.file.Files; import java.nio.file.Paths; public class App { public static void main(String[] args) { Pulumi.run(App::stack); } public static void stack(Context ctx) { var myDb1 = new Database("myDb1", DatabaseArgs.builder() .name("my_db1") .build()); var myDb2 = new Database("myDb2", DatabaseArgs.builder() .name("my_db2") .build()); } } ``` -------------------------------- ### Configure PostgreSQL Provider in YAML Source: https://github.com/pulumi/pulumi-postgresql/blob/master/docs/_index.md Define a GCP SQL database instance and a PostgreSQL database using Pulumi's YAML configuration. Resources are declared with their types and properties. ```yaml # Pulumi.yaml provider configuration file name: configuration-example runtime: yaml config: postgresql:host: value: 'TODO: google_sql_database_instance.test.connection_name' postgresql:password: value: 'TODO: google_sql_user.postgres.password' postgresql:scheme: value: gcppostgres postgresql:username: value: 'TODO: google_sql_user.postgres.name' ``` ```yaml resources: test: type: gcp:sql:DatabaseInstance properties: project: test-project name: test-instance databaseVersion: POSTGRES_13 region: europe-west3 settings: tier: db-f1-micro postgres: type: gcp:sql:User properties: project: test-project name: postgres instance: ${test.name} password: xxxxxxxx testDb: type: postgresql:Database name: test_db properties: name: test_db ``` -------------------------------- ### Environment Variable Equivalents for PostgreSQL Connection Source: https://context7.com/pulumi/pulumi-postgresql/llms.txt Set environment variables to configure the PostgreSQL connection parameters. ```bash export PGHOST=db.example.com export PGPORT=5432 export PGUSER=admin export PGPASSWORD=secret export PGSSLMODE=require export PGCONNECT_TIMEOUT=30 ``` -------------------------------- ### Set PostgreSQL Credentials via Environment Variables Source: https://github.com/pulumi/pulumi-postgresql/blob/master/docs/_index.md Configure PostgreSQL connection details using environment variables. This method avoids hardcoding sensitive information directly in the Pulumi program. ```shell export PGHOST=localhost export PGPORT=5432 export PGUSER=postgres export PGPASSWORD=postgres ``` -------------------------------- ### Pulumi.yaml Configuration for GCP SQL (Python) Source: https://github.com/pulumi/pulumi-postgresql/blob/master/docs/_index.md Defines the Pulumi.yaml configuration for connecting to a GCP SQL instance using Python. Replace TODO values with actual resource outputs. ```yaml # Pulumi.yaml provider configuration file name: configuration-example runtime: python config: postgresql:host: value: 'TODO: google_sql_database_instance.test.connection_name' postgresql:password: value: 'TODO: google_sql_user.postgres.password' postgresql:scheme: value: gcppostgres postgresql:username: value: 'TODO: google_sql_user.postgres.name' ``` -------------------------------- ### Manage PostgreSQL Logical Replication Subscriptions Source: https://context7.com/pulumi/pulumi-postgresql/llms.txt Creates and manages a logical replication subscription. Requires connection information, publications to subscribe to, and the replication slot name. Can optionally create the slot. ```typescript import * as postgresql from "@pulumi/postgresql"; const sub = new postgresql.Subscription("app-sub", { name: "myapp_sub", database: "myapp_replica", conninfo: "host=primary.example.com port=5432 dbname=myapp_production user=replicator password=secret sslmode=require", publications: ["myapp_pub"], slotName: "myapp_slot", createSlot: true, }); ``` -------------------------------- ### postgresql.UserMapping Source: https://context7.com/pulumi/pulumi-postgresql/llms.txt Creates and manages user mappings between local roles and foreign server credentials, essential for authenticated access to foreign servers. ```APIDOC ## postgresql.UserMapping — Map local roles to foreign server users Creates and manages user mappings between local roles and foreign server credentials. ### Resource `postgresql.UserMapping` ### Example ```typescript import * as postgresql from "@pulumi/postgresql"; const userMap = new postgresql.UserMapping("app-user-map", { serverName: "remote_db", userName: "myapp_user", options: { user: "remote_user", password: "remote_password", }, }); ``` ``` -------------------------------- ### Create a PostgreSQL User Mapping Source: https://context7.com/pulumi/pulumi-postgresql/llms.txt Map local roles to foreign server users by providing the `serverName`, `userName`, and authentication `options`. This is essential for connecting local users to remote databases. ```typescript import * as postgresql from "@pulumi/postgresql"; const userMap = new postgresql.UserMapping("app-user-map", { serverName: "remote_db", userName: "myapp_user", options: { user: "remote_user", password: "remote_password", }, }); ``` -------------------------------- ### Manage PostgreSQL Logical Replication Slots Source: https://context7.com/pulumi/pulumi-postgresql/llms.txt Creates and manages PostgreSQL logical replication slots. Requires specifying the output plugin and the database. ```typescript import * as postgresql from "@pulumi/postgresql"; const slot = new postgresql.ReplicationSlot("app-slot", { name: "myapp_slot", plugin: "pgoutput", database: "myapp_production", }); ``` -------------------------------- ### FlexibleServerActiveDirectoryAdministrator Source: https://github.com/pulumi/pulumi-postgresql/blob/master/docs/_index.md Creates an Active Directory Administrator for an Azure PostgreSQL Flexible Server. ```APIDOC ## azure.postgresql.FlexibleServerActiveDirectoryAdministrator ### Description Manages an Azure PostgreSQL Flexible Server Active Directory Administrator. ### Arguments * `object_id` - (Required) The Object ID of the principal (user, group, or service principal) to be assigned as Active Directory administrator. * `principal_name` - (Required) The Principal Name of the principal to be assigned as Active Directory administrator. * `principal_type` - (Required) The type of the principal to be assigned as Active Directory administrator. Possible values are `user`, `group` and `servicePrincipal`. * `resource_group_name` - (Required) The name of the resource group. * `server_name` - (Required) The name of the PostgreSQL Flexible Server. * `tenant_id` - (Required) The tenant ID of the Azure Active Directory. ### Attributes Reference In addition to all the arguments above, the following attributes are exported: * `id` - The ID of the Active Directory Administrator. ``` -------------------------------- ### Configure Azure PostgreSQL with Passwordless Auth (YAML) Source: https://github.com/pulumi/pulumi-postgresql/blob/master/docs/_index.md Configures the Pulumi PostgreSQL provider for Azure with passwordless authentication. Set `azureIdentityAuth` to `true` and provide `azureTenantId`. Ensure `postgresql:host` and `postgresql:username` are correctly set. ```yaml # Pulumi.yaml provider configuration file name: configuration-example runtime: nodejs config: postgresql:azureIdentityAuth: value: true postgresql:azureTenantId: value: 'TODO: data.azurerm_client_config.current.tenant_id' postgresql:database: value: postgres postgresql:host: value: 'TODO: azurerm_postgresql_flexible_server.pgsql.fqdn' postgresql:port: value: 5432 postgresql:sslmode: value: require postgresql:username: value: 'TODO: azurerm_postgresql_flexible_server_active_directory_administrator.administrators.principal_name' ``` -------------------------------- ### ReplicationSlot Source: https://context7.com/pulumi/pulumi-postgresql/llms.txt Creates and manages PostgreSQL logical replication slots. ```APIDOC ## postgresql.ReplicationSlot — Manage logical replication slots ### Description Creates and manages PostgreSQL logical replication slots. ### Parameters #### Path Parameters - **name** (string) - Required - The name of the replication slot. - **plugin** (string) - Required - The output plugin to use for the slot (e.g., "pgoutput"). - **database** (string) - Required - The name of the database for which the slot is created. ### Request Example ```typescript import * as postgresql from "@pulumi/postgresql"; const slot = new postgresql.ReplicationSlot("app-slot", { name: "myapp_slot", plugin: "pgoutput", database: "myapp_production", }); ``` ### Response #### Success Response (200) - **name** (string) - The name of the replication slot. - **plugin** (string) - The output plugin used by the slot. - **database** (string) - The database for which the slot is created. ``` -------------------------------- ### GCP SQL Instance Configuration with Standard Authentication Source: https://github.com/pulumi/pulumi-postgresql/blob/master/docs/_index.md Configure the PostgreSQL provider for a GCP SQL instance using standard username and password authentication. The Cloud SQL API must be enabled. ```yaml # Pulumi.yaml provider configuration file name: configuration-example runtime: config: postgresql:host: value: test-project/europe-west3/test-instance postgresql:password: value: test1234 postgresql:port: value: 5432 postgresql:scheme: value: gcppostgres postgresql:superuser: value: false postgresql:username: value: postgres ``` -------------------------------- ### GCP SQL Instance Configuration with Impersonation Source: https://github.com/pulumi/pulumi-postgresql/blob/master/docs/_index.md Configure the PostgreSQL provider to connect to a GCP SQL instance using service account impersonation. Ensure GOOGLE_APPLICATION_CREDENTIALS is set and IAM roles are correctly assigned. ```yaml # Pulumi.yaml provider configuration file name: configuration-example runtime: config: postgresql:gcpIamImpersonateServiceAccount: value: service_account_id@$project_id.iam.gserviceaccount.com postgresql:host: value: test-project/europe-west3/test-instance postgresql:port: value: 5432 postgresql:scheme: value: gcppostgres postgresql:superuser: value: false postgresql:username: value: service_account_id@$project_id.iam ``` -------------------------------- ### Subscription Source: https://context7.com/pulumi/pulumi-postgresql/llms.txt Creates and manages a logical replication subscription that connects to a publication on a remote server. ```APIDOC ## postgresql.Subscription — Manage logical replication subscriptions ### Description Creates and manages a logical replication subscription that connects to a publication on a remote server. ### Parameters #### Path Parameters - **name** (string) - Required - The name of the subscription. - **database** (string) - Required - The name of the database to which the subscription is created. - **conninfo** (string) - Required - The connection string to the publication server. - **publications** (array) - Required - An array of publication names to subscribe to. - **slotName** (string) - Required - The name of the replication slot to use or create. - **createSlot** (boolean) - Optional - If true, a replication slot will be created if it does not exist. Defaults to false. ### Request Example ```typescript import * as postgresql from "@pulumi/postgresql"; const sub = new postgresql.Subscription("app-sub", { name: "myapp_sub", database: "myapp_replica", conninfo: "host=primary.example.com port=5432 dbname=myapp_production user=replicator password=secret sslmode=require", publications: ["myapp_pub"], slotName: "myapp_slot", createSlot: true, }); ``` ### Response #### Success Response (200) - **name** (string) - The name of the subscription. - **database** (string) - The database to which the subscription is created. - **slotName** (string) - The name of the replication slot used by the subscription. ``` -------------------------------- ### Configure Azure Active Directory Authentication Source: https://context7.com/pulumi/pulumi-postgresql/llms.txt Configure the PostgreSQL provider for Azure Active Directory authentication using Pulumi configuration. ```yaml # Pulumi.yaml config: postgresql:host: { value: "myserver.postgres.database.azure.com" } postgresql:port: { value: 5432 } postgresql:username: { value: "aad-admin-group@tenant.onmicrosoft.com" } postgresql:azureIdentityAuth: { value: true } postgresql:azureTenantId: { value: "00000000-0000-0000-0000-000000000000" } postgresql:sslmode: { value: "require" } ``` -------------------------------- ### Pulumi.yaml Configuration for GCP SQL (TypeScript) Source: https://github.com/pulumi/pulumi-postgresql/blob/master/docs/_index.md Defines the Pulumi.yaml configuration for connecting to a GCP SQL instance using TypeScript. Replace TODO values with actual resource outputs. ```yaml # Pulumi.yaml provider configuration file name: configuration-example runtime: nodejs config: postgresql:host: value: 'TODO: google_sql_database_instance.test.connection_name' postgresql:password: value: 'TODO: google_sql_user.postgres.password' postgresql:scheme: value: gcppostgres postgresql:username: value: 'TODO: google_sql_user.postgres.name' ``` -------------------------------- ### Manage PostgreSQL Physical Replication Slots Source: https://context7.com/pulumi/pulumi-postgresql/llms.txt Creates and manages PostgreSQL physical replication slots for streaming replication. Only requires a name for the slot. ```typescript import * as postgresql from "@pulumi/postgresql"; const physicalSlot = new postgresql.PhysicalReplicationSlot("standby-slot", { name: "standby_01", }); ``` -------------------------------- ### Create PostgreSQL Database Source: https://context7.com/pulumi/pulumi-postgresql/llms.txt Creates a PostgreSQL database with specified encoding, locale, and connection limits. Ensure the owner role exists before creating the database. ```typescript import * as pulumi from "@pulumi/pulumi"; import * as postgresql from "@pulumi/postgresql"; // Create an application database owned by a specific role const appDb = new postgresql.Database("app-db", { name: "myapp_production", owner: "myapp_role", template: "template0", encoding: "UTF8", lcCollate: "en_US.utf8", lcCtype: "en_US.utf8", connectionLimit: 100, allowConnections: true, isTemplate: false, alterObjectOwnership: true, // reassign existing objects when owner changes }); export const dbName = appDb.name; // Expected output: dbName: "myapp_production" ``` ```python import pulumi import pulumi_postgresql as postgresql app_db = postgresql.Database("app-db", name="myapp_production", owner="myapp_role", template="template0", encoding="UTF8", lc_collate="en_US.utf8", lc_ctype="en_US.utf8", connection_limit=100, allow_connections=True, alter_object_ownership=True) pulumi.export("db_name", app_db.name) ``` ```go package main import ( "github.com/pulumi/pulumi-postgresql/sdk/v3/go/postgresql" "github.com/pulumi/pulumi/sdk/v3/go/pulumi" ) func main() { pulumi.Run(func(ctx *pulumi.Context) error { appDb, err := postgresql.NewDatabase(ctx, "app-db", &postgresql.DatabaseArgs{ Name: pulumi.String("myapp_production"), Owner: pulumi.String("myapp_role"), Template: pulumi.String("template0"), Encoding: pulumi.String("UTF8"), LcCollate: pulumi.String("en_US.utf8"), LcCtype: pulumi.String("en_US.utf8"), ConnectionLimit: pulumi.Int(100), AllowConnections: pulumi.Bool(true), AlterObjectOwnership: pulumi.Bool(true), }) if err != nil { return err } ctx.Export("dbName", appDb.Name) return nil }) } ``` -------------------------------- ### postgresql.Database Source: https://context7.com/pulumi/pulumi-postgresql/llms.txt Create and manage PostgreSQL databases. Supports full configuration of encoding, locale, template, tablespace, connection limits, and ownership. ```APIDOC ## postgresql.Database — Create and manage PostgreSQL databases Creates and manages a PostgreSQL database, supporting full configuration of encoding, locale, template, tablespace, connection limits, and ownership. ### Parameters * **name** (string) - Required - The name of the database. * **owner** (string) - Optional - The role that will own the database. * **template** (string) - Optional - The template database to base the new database on. * **encoding** (string) - Optional - The character encoding scheme to use. * **lcCollate** (string) - Optional - The collation order for the database. * **lcCtype** (string) - Optional - The character classification for the database. * **connectionLimit** (integer) - Optional - The maximum number of concurrent connections to the database. * **allowConnections** (boolean) - Optional - Whether or not to allow connections to the database. * **isTemplate** (boolean) - Optional - Whether the database should be a template. * **alterObjectOwnership** (boolean) - Optional - If true, existing objects in the database will have their ownership reassigned when the owner changes. ``` -------------------------------- ### Create PostgreSQL Flexible Server Active Directory Administrator Source: https://github.com/pulumi/pulumi-postgresql/blob/master/docs/_index.md This snippet demonstrates how to create an Active Directory administrator for an Azure PostgreSQL Flexible Server. It requires the server's resource group name and server name, along with the administrator's object ID, principal name, principal type, and tenant ID. ```python administrators = azure.postgresql.FlexibleServerActiveDirectoryAdministrator("administrators", object_id="00000000-0000-0000-0000-000000000000", principal_name="Azure AD Admin Group", principal_type="Group", resource_group_name=rg_name, server_name=pgsql.name, tenant_id=current.tenant_id) ``` ``` -------------------------------- ### Deploy Multiple PostgreSQL Databases in YAML Source: https://github.com/pulumi/pulumi-postgresql/blob/master/docs/_index.md Deploy two PostgreSQL databases using the Pulumi PostgreSQL provider in YAML. This defines the resources directly in the Pulumi configuration. ```yaml resources: myDb1: type: postgresql:Database name: my_db1 properties: name: my_db1 myDb2: type: postgresql:Database name: my_db2 properties: name: my_db2 ``` -------------------------------- ### Configure SSL Client Certificate (mTLS) Authentication Source: https://context7.com/pulumi/pulumi-postgresql/llms.txt Configure the PostgreSQL provider for SSL client certificate (mTLS) authentication. ```typescript const mtlsProvider = new postgresql.Provider("mtls", { host: "secure-db.example.com", username: "app_user", sslmode: "verify-full", sslrootcert: "/etc/ssl/certs/server-ca.pem", clientcert: { cert: "/etc/ssl/certs/client.crt", key: "/etc/ssl/private/client.key", }, }); ``` -------------------------------- ### postgresql.Server Source: https://context7.com/pulumi/pulumi-postgresql/llms.txt Manages foreign servers in PostgreSQL, useful for setting up foreign data wrappers like `postgres_fdw`. ```APIDOC ## postgresql.Server — Manage foreign servers Creates and manages PostgreSQL foreign servers for use with `postgres_fdw` or other foreign data wrappers. ### Resource `postgresql.Server` ### Example ```typescript import * as postgresql from "@pulumi/postgresql"; const foreignServer = new postgresql.Server("remote-server", { serverName: "remote_db", fdwName: "postgres_fdw", serverType: "mytype", serverVersion: "14.0", options: { host: "remote.example.com", port: "5432", dbname: "remote_db", }, }); ``` ``` -------------------------------- ### Pulumi Java Provider Configuration Source: https://github.com/pulumi/pulumi-postgresql/blob/master/docs/_index.md Configure PostgreSQL provider settings and resources using Pulumi Java. This includes setting authentication, database, host, port, SSL mode, and username. It also defines PostgreSQL flexible server and active directory administrator resources. ```yaml # Pulumi.yaml provider configuration file name: configuration-example runtime: java config: postgresql:azureIdentityAuth: value: true postgresql:azureTenantId: value: 'TODO: data.azurerm_client_config.current.tenant_id' postgresql:database: value: postgres postgresql:host: value: 'TODO: azurerm_postgresql_flexible_server.pgsql.fqdn' postgresql:port: value: 5432 postgresql:sslmode: value: require postgresql:username: value: 'TODO: azurerm_postgresql_flexible_server_active_directory_administrator.administrators.principal_name' ``` ```java package generated_program; import com.pulumi.Context; import com.pulumi.Pulumi; import com.pulumi.core.Output; import com.pulumi.azure.core.CoreFunctions; import com.pulumi.azure.postgresql.FlexibleServer; import com.pulumi.azure.postgresql.FlexibleServerArgs; import com.pulumi.azure.postgresql.inputs.FlexibleServerAuthenticationArgs; import com.pulumi.azure.postgresql.FlexibleServerActiveDirectoryAdministrator; import com.pulumi.azure.postgresql.FlexibleServerActiveDirectoryAdministratorArgs; import java.util.ArrayList; import java.util.Arrays; import java.util.Map; import java.io.File; import java.nio.file.Files; import java.nio.file.Paths; public class App { public static void main(String[] args) { Pulumi.run(App::stack); } public static void stack(Context ctx) { final var current = CoreFunctions.getClientConfig(%!v(PANIC=Format method: runtime error: invalid memory address or nil pointer dereference); // https://registry.pulumi.io/providers/pulumi/azurerm/latest/docs/resources/postgresql_flexible_server var pgsql = new FlexibleServer("pgsql", FlexibleServerArgs.builder() .authentication(FlexibleServerAuthenticationArgs.builder() .activeDirectoryAuthEnabled(true) .passwordAuthEnabled(false) .tenantId(current.tenantId()) .build()) .build()); // https://registry.pulumi.io/providers/pulumi/azurerm/latest/docs/resources/postgresql_flexible_server_active_directory_administrator var administrators = new FlexibleServerActiveDirectoryAdministrator("administrators", FlexibleServerActiveDirectoryAdministratorArgs.builder() .objectId("00000000-0000-0000-0000-000000000000") .principalName("Azure AD Admin Group") .principalType("Group") .resourceGroupName(rgName) .serverName(pgsql.name()) .tenantId(current.tenantId()) .build()); } } ``` -------------------------------- ### PhysicalReplicationSlot Source: https://context7.com/pulumi/pulumi-postgresql/llms.txt Creates and manages PostgreSQL physical replication slots for streaming replication. ```APIDOC ## postgresql.PhysicalReplicationSlot — Manage physical replication slots ### Description Creates and manages PostgreSQL physical replication slots for streaming replication. ### Parameters #### Path Parameters - **name** (string) - Required - The name of the physical replication slot. ### Request Example ```typescript import * as postgresql from "@pulumi/postgresql"; const physicalSlot = new postgresql.PhysicalReplicationSlot("standby-slot", { name: "standby_01", }); ``` ### Response #### Success Response (200) - **name** (string) - The name of the physical replication slot. ``` -------------------------------- ### Create PostgreSQL Schema with Policies (TypeScript) Source: https://context7.com/pulumi/pulumi-postgresql/llms.txt Defines a PostgreSQL schema with specific ownership and access policies for different roles. Use this to enforce granular permissions on schema creation and usage. ```typescript import * as postgresql from "@pulumi/postgresql"; const appSchema = new postgresql.Schema("app-schema", { name: "app", database: "myapp_production", owner: "myapp_role", ifNotExists: true, dropCascade: false, policies: [ { role: "readonly", usage: true, create: false, }, { role: "myapp_role", usage: true, create: true, usageWithGrant: false, createWithGrant: false, }, ], }); ```