Skip to content

Commit

Permalink
Merge pull request #857 from Olshansk/master
Browse files Browse the repository at this point in the history
SQL Store Postgres Example
  • Loading branch information
kozlovic committed Jun 13, 2019
2 parents 2327eaa + cd3c6df commit bebb9c0
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
27 changes: 26 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ that the RAFT state can be recovered along with the Streaming state.

To minimize the single point of failure, NATS Streaming server can be run in Fault Tolerance mode. It works by having a group
of servers with one acting as the active server (accessing the store) and handling all communication with clients, and all others
acting as standby servers.
acting as standby servers.

It is important to note that is not possible to run Nats Stream as Fault Tolerance mode and Clustering mode at the same time.

Expand Down Expand Up @@ -2025,6 +2025,31 @@ is provided in this repo:
mysql -u nss -p -D nss_db -e "$(cat ./mysql.db.sql)"
```

#### SQL Store Example - Postgres
Run a local dockerized instance of postgres if you do not already have one:

```
ID=$(docker run -d -e POSTGRES_PASSWORD=password -p 5432:5432 postgres)
```

[Optional] Drop any previous tables to clear data from previous sessions:

```
cat drop_postgres.db.sql | docker exec -i $ID psql -h 127.0.1.1 -U postgres
```

Run the appropriate database migrations for Postgres:

```
cat postgres.db.sql | docker exec -i $ID psql -h 127.0.1.1 -U postgres
```

Run the nats streaming server with postgres at the sql_source:

```
DOCKER_BRIDGE_IP=$(docker inspect --format '{{(index .IPAM.Config 0).Gateway}}' bridge) docker run -d --name nats-streaming -p 4222:4222 -p 8222:32768 nats-streaming-local -SDV --store sql --sql_driver postgres --sql_source="user=postgres password=postgres host=$DOCKER_BRIDGE_IP port=5432 sslmode=disable"
```

#### SQL Store Options

Aside from the driver and datasource, the available options are the maximum number of opened connections to the database (`max_open_conns`)
Expand Down
10 changes: 10 additions & 0 deletions drop_postgres.db.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
DROP TABLE IF EXISTS ServerInfo;
DROP TABLE IF EXISTS Clients;
DROP TABLE IF EXISTS Channels;
DROP INDEX IF EXISTS Idx_ChannelsName;
DROP TABLE IF EXISTS Messages;
DROP INDEX IF EXISTS Idx_MsgsTimestamp;
DROP TABLE IF EXISTS Subscriptions;
DROP TABLE IF EXISTS SubsPending;
DROP INDEX IF EXISTS Idx_SubsPendingSeq;
DROP TABLE IF EXISTS StoreLock;

0 comments on commit bebb9c0

Please sign in to comment.