Registry / devops / pulumi-postgresql

pulumi-postgresql

JSON →
library3.17.0pypypi✓ verified 87d ago

The `pulumi-postgresql` package provides a Pulumi provider for creating and managing PostgreSQL cloud resources. It allows users to define PostgreSQL databases, roles, schemas, and other configurations as infrastructure-as-code using Python and other supported languages. The provider is derived from the Terraform PostgreSQL provider and receives frequent updates, often alongside its upstream dependencies.

pip install pulumi_postgresql
INSTALL
IMPORT
SIG · PULUMI-POSTGRESQL
P
pulumi-postgresql
devopspythonv3.17.0
Install
6.4s avg
Import
1296ms
Disk
80MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v3.17.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 1.647s · 88.5MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 6.4s · import 0.945s · 74MB
80MB installed
● package 80MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

postgresql
import pulumi_postgresql as postgresql
This is the conventional alias used in Pulumi Python programs for the PostgreSQL provider.
Database
from pulumi_postgresql import Database
Role
from pulumi_postgresql import Role

This quickstart demonstrates how to create a new PostgreSQL database and a new role (user) using the `pulumi-postgresql` provider. It assumes PostgreSQL connection details are configured via environment variables (`PGHOST`, `PGUSER`, `PGPASSWORD`, `PGDATABASE`, `PGPORT`, `PGSSLMODE`) or Pulumi configuration. For local development, `PGSSLMODE` is often set to `disable` to avoid SSL connection errors. Always manage sensitive data like passwords using Pulumi secrets.

import pulumi import pulumi_postgresql as postgresql import os # Configure PostgreSQL provider using environment variables for sensitive data # Alternatively, use `pulumi config set postgresql:host <value>` etc. # For passwords, use `pulumi config set --secret postgresql:password <value>` pg_host = os.environ.get('PGHOST', 'localhost') pg_user = os.environ.get('PGUSER', 'postgres') pg_password = os.environ.get('PGPASSWORD', 'password') pg_database = os.environ.get('PGDATABASE', 'postgres') # Database for initial connection pg_port = os.environ.get('PGPORT', '5432') pg_sslmode = os.environ.get('PGSSLMODE', 'disable') # Often 'disable' for local dev, 'require' for production # The provider needs to be explicitly configured if not using default environment variables or pulumi config. # For this example, we're relying on environment variables or `pulumi config`. # If you need to explicitly create a provider instance: # pg_provider = postgresql.Provider("pg-provider", # host=pg_host, # username=pg_user, # password=pg_password, # database=pg_database, # port=pg_port, # sslmode=pg_sslmode # ) # Create a new PostgreSQL database new_db = postgresql.Database("my-new-database", name="mydatabase", opts=pulumi.ResourceOptions(delete_before_replace=True) # Optional: ensures clean replacement if name changes ) # Create a new PostgreSQL role (user) new_role = postgresql.Role("my-app-role", name="app_user", login=True, password="strong_password_here", # In production, this should be a secret! opts=pulumi.ResourceOptions(delete_before_replace=True) # Optional ) # Export the database name and role name pulumi.export('database_name', new_db.name) pulumi.export('role_name', new_role.name)
Debug
Known issues
gotchaThe default `sslmode` for the PostgreSQL provider is `require` (always SSL, also skip verification). If your PostgreSQL server is not configured for SSL, connection attempts will fail.
fix
Set `sslmode` to `disable` in your provider configuration or via `PGSSLMODE` environment variable if your server doesn't use SSL. For production, ensure SSL is configured and `sslmode` is set to `verify-ca` or `verify-full`.
affects: All v3.x
gotchaSensitive configuration values, such as `postgresql:password`, should always be managed using Pulumi's secret encryption to prevent them from being stored in plain text in your state file.
fix
Use `pulumi config set --secret postgresql:password <YOUR_PASSWORD>` when setting passwords via Pulumi configuration. If using environment variables, ensure proper secure handling of `PGPASSWORD`.
affects: All versions
gotchaSome PostgreSQL provider features, such as refreshing state passwords from the database, require the connecting user to be a PostgreSQL superuser. If the user is not a superuser (common in cloud-managed databases like AWS RDS or GCP SQL), these features might be disabled.
fix
Set `superuser` to `false` in your provider configuration or ensure the connecting user has the necessary privileges for operations you intend to perform. Consult provider documentation for specific resource requirements.
affects: All v3.x
breakingUpgrades to the `pulumi-terraform-bridge` or `terraform-provider-postgresql` dependencies can occasionally introduce changes in how resources are identified or managed, potentially leading to 'replace' actions or resources being removed from the Pulumi state during a `pulumi refresh`.
fix
Always run `pulumi preview` before `pulumi up` after provider upgrades to understand proposed changes. If resources are incorrectly marked for replacement or removal, investigate changes in input properties or provider behavior. A `pulumi refresh` followed by a `pulumi up` might be necessary, but ensure you understand the implications, particularly for functions or complex objects.
affects: Potentially across all minor/patch versions, especially with larger bridge upgrades (e.g., from v3.15.1 to newer versions).
Errors
Common errors & fixes
Error connecting to PostgreSQL server (scheme: postgres): XXXXpXXXXq: SSL is not enabled on the server
The PostgreSQL provider's default `sslmode` is `require`, meaning it attempts an SSL connection, but the target PostgreSQL server is not configured to accept SSL connections.
fix
Set the `sslmode` configuration option to `disable`. This can be done via `pulumi config set postgresql:sslmode disable` or by setting the `PGSSLMODE` environment variable to `disable`. Ensure this is appropriate for your environment.
missing required configuration key: host
The PostgreSQL provider requires the `host` (server address) to connect, but it was not provided via environment variables (`PGHOST`), Pulumi configuration (`postgresql:host`), or explicit provider arguments.
fix
Provide the PostgreSQL host. For example, `export PGHOST=your_db_host` or `pulumi config set postgresql:host your_db_host`. Ensure `host` is reachable from where Pulumi is executed.
pg: permission denied for database "my_new_database"
The PostgreSQL user configured for the provider (`postgresql:username` or `PGUSER`) does not have sufficient privileges to perform the requested operation on the specified database (e.g., creating a new database or role).
fix
Grant the necessary permissions to the connecting PostgreSQL user, or configure the Pulumi provider to use a user with adequate privileges (e.g., a superuser or a user with `CREATEDB` privilege for database creation).
Upgrade
Version history
3.17.0latest on PyPI · released May 22, 2026
Audit
Dependencies
pulumirequiredCore Pulumi SDK is required to define and manage infrastructure.
Agent activity
11 hits · last 30 days
node
10
Resources
pulumi-postgresql — pip install pulumi-postgresql · libregistry