From 2968d37dd2bb94eb88a1489bb1a6898c293a05c4 Mon Sep 17 00:00:00 2001 From: Brooke Hamilton Date: Wed, 8 Jul 2020 18:50:34 -0400 Subject: [PATCH] PostgreSQL updates --- concepts/actors/actors_features.md | 1 + concepts/state-management/README.md | 3 + howto/setup-state-store/setup-postgresql.md | 57 +++++++++++++++++++ .../supported-state-stores.md | 3 +- overview/README.md | 2 +- reference/api/state_api.md | 2 +- 6 files changed, 65 insertions(+), 3 deletions(-) create mode 100644 howto/setup-state-store/setup-postgresql.md diff --git a/concepts/actors/actors_features.md b/concepts/actors/actors_features.md index 5b24fe2c3..76f28f4f7 100644 --- a/concepts/actors/actors_features.md +++ b/concepts/actors/actors_features.md @@ -28,6 +28,7 @@ To use actors, your state store must support multi-item transactions. This mean - Redis - MongoDB +- PostgreSQL - SQL Server ## Actor timers and reminders diff --git a/concepts/state-management/README.md b/concepts/state-management/README.md index b374df2d8..620e08870 100644 --- a/concepts/state-management/README.md +++ b/concepts/state-management/README.md @@ -49,6 +49,7 @@ The following table summarizes the capabilities of existing data store implement Store | Strong consistent write | Strong consistent read | ETag| ----|----|----|---- Cosmos DB | Yes | Yes | Yes +PostgreSQL | Yes | Yes | Yes Redis | Yes | Yes | Yes Redis (clustered)| Yes | No | Yes SQL Server | Yes | Yes | Yes @@ -110,6 +111,8 @@ SELECT AVG(value) FROM StateTable WHERE Id LIKE '||||*||tem * [Spec: Dapr actors specification](../../reference/api/actors_api.md) * [How-to: Set up Azure Cosmos DB store](../../howto/setup-state-store/setup-azure-cosmosdb.md) * [How-to: Query Azure Cosmos DB store](../../howto/query-state-store/query-cosmosdb-store.md) +* [How-to: Set up PostgreSQL store](../../howto/setup-state-store/setup-postgresql.md) +* [How-to: Query PostgreSQL store](../../howto/query-state-store/query-postgresql-store.md) * [How-to: Set up Redis store](../../howto/setup-state-store/setup-redis.md) * [How-to: Query Redis store](../../howto/query-state-store/query-redis-store.md) * [How-to: Set up SQL Server store](../../howto/setup-state-store/setup-sqlserver.md) diff --git a/howto/setup-state-store/setup-postgresql.md b/howto/setup-state-store/setup-postgresql.md new file mode 100644 index 000000000..ff8a1a8ff --- /dev/null +++ b/howto/setup-state-store/setup-postgresql.md @@ -0,0 +1,57 @@ +# Setup PostgreSQL + +This article provides guidance on configuring a PostgreSQL state store. + +## Create a PostgreSQL Store +Dapr can use any PostgreSQL instance. If you already have a running instance of PostgreSQL, move on to the [Configuration](#configuration) 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". + + ```bash + 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: + + ```SQL + create database dapr_test + ``` + +## Create a Dapr component + +Create a file called `postgres.yaml`, and paste the following. If you want to also configure PostgreSQL to store actors, add the `actorStateStore` configuration element shown below. + +```yaml +apiVersion: dapr.io/v1alpha1 +kind: Component +metadata: + name: statestore +spec: + type: state.postgresql + metadata: + - name: connectionString + value: "" + - name: actorStateStore + value: "true" +``` +The above example uses secrets as plain strings. It is recommended to use a secret store for the secrets as described [here](../../concepts/secrets/README.md) + +## Apply the configuration + +### In Kubernetes + +To apply the SQL Server state store to Kubernetes, use the `kubectl` CLI: + +```yaml +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`. diff --git a/howto/setup-state-store/supported-state-stores.md b/howto/setup-state-store/supported-state-stores.md index f0e0d64bf..f3ca21385 100644 --- a/howto/setup-state-store/supported-state-stores.md +++ b/howto/setup-state-store/supported-state-stores.md @@ -11,7 +11,8 @@ | Hazelcast | :white_check_mark: | :x: | | Memcached | :white_check_mark: | :x: | | MongoDB | :white_check_mark: | :white_check_mark: | -| Redis | :white_check_mark: | :white_check_mark: | +| PostgreSQL | :white_check_mark: | :white_check_mark: | +| Redis | :white_check_mark: | :white_check_mark: | | Zookeeper | :white_check_mark: | :x: | | Azure CosmosDB | :white_check_mark: | :x: | | Azure SQL Server | :white_check_mark: | :white_check_mark: | diff --git a/overview/README.md b/overview/README.md index d33c1621c..1bc2eb8a3 100644 --- a/overview/README.md +++ b/overview/README.md @@ -35,7 +35,7 @@ Each of these building blocks is independent, meaning that you can use one, some | Building Block | Description | |----------------|-------------| | **[Service Invocation](../concepts/service-invocation)** | Resilient service-to-service invocation enables method calls, including retries, on remote services wherever they are located in the supported hosting environment. -| **[State Management](../concepts/state-management)** | With state management for storing key/value pairs, long running, highly available, stateful services can be easily written alongside stateless services in your application. The state store is pluggable and can include Azure CosmosDB, AWS DynamoDB or Redis among others. +| **[State Management](../concepts/state-management)** | With state management for storing key/value pairs, long running, highly available, stateful services can be easily written alongside stateless services in your application. The state store is pluggable and can include Azure CosmosDB, Azure SQL Server, PostgreSQL, AWS DynamoDB or Redis among others. | **[Publish and Subscribe Messaging](../concepts/publish-subscribe-messaging)** | Publishing events and subscribing to topics | tween services enables event-driven architectures to simplify horizontal scalability and make them | silient to failure. Dapr provides at least once message delivery guarantee. | **[Resource Bindings](../concepts/bindings)** | Resource bindings with triggers builds further on event-driven | chitectures for scale and resiliency by receiving and sending events to and from any external | source such as databases, queues, file systems, etc. | **[Distributed Tracing](../concepts/observability/traces.md)** | Dapr supports distributed tracing to easily diagnose and | serve inter-service calls in production using the W3C Trace Context standard. diff --git a/reference/api/state_api.md b/reference/api/state_api.md index 4318fc5ce..47ecb0f9d 100644 --- a/reference/api/state_api.md +++ b/reference/api/state_api.md @@ -219,7 +219,7 @@ curl -X "DELETE" http://localhost:3500/v1.0/state/starwars/planet -H "ETag: xxxx ## Configuring state store for actors -Actors don't support multiple state stores and require a transactional state store to be used with Dapr. Currently mongodb and redis implement the transactional state store interface. +Actors don't support multiple state stores and require a transactional state store to be used with Dapr. Currently mongodb, Azure SQL Server, redis, and PostgreSQL implement the transactional state store interface. To specify which state store to be used for actors, specify value of property `actorStateStore` as true in the metadata section of the state store component yaml file. Example: Following components yaml will configure redis to be used as the state store for Actors.