The documentation you are viewing is for Dapr v0.11 which is an older version of Dapr. For up-to-date documentation, see the latest version.


Detailed information on the PostgreSQL state store component

Create a PostgreSQL Store

Dapr can use any PostgreSQL instance. If you already have a running instance of PostgreSQL, move on to the Create a Dapr component section.

  1. Run an instance of PostgreSQL. You can run a local instance of PostgreSQL in Docker CE with the following command:

    This example does not describe a production configuration because it sets the password in plain text and the user name is left as the PostgreSQL default of “postgres”.

    docker run -p 5432:5432 -e POSTGRES_PASSWORD=example postgres
  2. Create a database for state data. Either the default “postgres” database can be used, or create a new database for storing state data.

    To create a new database in PostgreSQL, run the following SQL command:

    create database dapr_test

Create a Dapr component

Create a file called postgres.yaml, paste the following and replace the <CONNECTION STRING> value with your connection string. The connection string is a standard PostgreSQL connection string. For example, "host=localhost user=postgres password=example port=5432 connect_timeout=10 database=dapr_test". See the PostgreSQL documentation on database connections, specifically Keyword/Value Connection Strings, for information on how to define a connection string.

If you want to also configure PostgreSQL to store actors, add the actorStateStore configuration element shown below.

kind: Component
  name: statestore
  type: state.postgresql
  version: v1
  - name: connectionString
    value: "<CONNECTION STRING>"
  - name: actorStateStore
    value: "true"

Apply the configuration

In Kubernetes

To apply the PostgreSQL state store to Kubernetes, use the kubectl CLI:

kubectl apply -f postgres.yaml

Running locally

To run locally, create a components dir containing the YAML file and provide the path to the dapr run command with the flag --components-path.

Last modified July 7, 2022: update nav bar v0.11 (#2633) (b309d3d)