diff --git a/docs/assets/svg/StackGres-Postgres-LocalPV.svg b/docs/assets/svg/StackGres-Postgres-LocalPV.svg
new file mode 100644
index 000000000..9e2e6bab7
--- /dev/null
+++ b/docs/assets/svg/StackGres-Postgres-LocalPV.svg
@@ -0,0 +1,133 @@
+
+
+
+
+
+
+
+
+
+
+
+
+ pvc
+
+
+
+
+
+
+
+
+
+
+
+ pvc
+
+
+
+
+
+
+
+
+
+
+
+ pv
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ pv
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ PostgreSQL database on Kubernetes with OpenEBS
+
+
+
+
+
+
+
+
+
+
+ NODE 1
+ NODE 2
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Block Device 1
+ Block Device 2
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/docs/assets/svg/postgresql-deployment.svg b/docs/assets/svg/postgresql-deployment.svg
deleted file mode 100644
index 5e32054d2..000000000
--- a/docs/assets/svg/postgresql-deployment.svg
+++ /dev/null
@@ -1,7442 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-]>
-
-
-
-
-
-
-
-
- template
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- cStorPool instance1
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- NODE 1
- NODE 2
- NODE 3
- NODE 4
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- PostgreSQL with OpenEBS persistent volumes
-
- cStorPool instance2
- cStorPool instance3
- cStorPool instance4
- volume replicas
- volume replicas
- volume replicas
- volume replicas
-
-
-
-
-
- cStor tgt
-
-
-
-
-
-
-
-
-
- pg-0
- PVC
- OpenEBS PV
-
- cStor tgt
-
-
-
-
-
-
-
-
-
- pg-1
- PostgreSQL as statefulset
- PVC
- OpenEBS PV
-
- cStor tgt
-
-
-
-
-
-
-
-
-
- pg-2
- PVC
- OpenEBS PV
-
- cStor tgt
-
-
-
-
-
-
-
-
-
- pg-3
- PVC
- OpenEBS PV
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/docs/postgres.md b/docs/postgres.md
index c02f9688d..48a49dcb2 100644
--- a/docs/postgres.md
+++ b/docs/postgres.md
@@ -11,190 +11,303 @@ sidebar_label: PostgreSQL
## Introduction
-
+PostgreSQL is a powerful, open source object-relational database system. It supports a large part of the SQL standard and offers many modern features to ensure the reliability, data integrity, and correctness. This makes it very easy to manage and use by any person with a little knowledge in databases.
-OpenEBS is deployed under PostgreSQL for a variety of reasons discussed below. The basics are that PostgreSQL is typically deployed as a `StatefulSet` on Kubernetes and requires persistent storage for each instance of PostgreSQL StorageManager. OpenEBS provides persistent volumes on the fly when StorageManagers are scaled up.
+StackGres is a full stack PostgreSQL distribution for Kubernetes, packed into an easy deployment unit. The StackGres stack consists of connection pooling, automatic failover and HA, monitoring, backups and DR, centralized logging, and many more. This stack is made with the help of Kubernetes operator and makes the easy way of packaging, deploying and managing PostgreSQL applications in Kubernetes ecosystem. A StackGres cluster is basically a StatefulSet where each pod is a database instance. The StatefulSet guarantees that each pod is always bound to its own persistent volume therefore the database instance data will be mapped to the state of a patroni instance inside kubernetes
-
+This guide explains the basic installation for StackGres PostgreSQL on OpenEBS Local PV device. It also contains the creation of a sample database, tables and tuples. StackGres PostgreSQL is a StatefulSet type and the high performance of OpenEBS Local PV storage engine will be suitable for a persistent storage solution for PostgreSQL databases which can deal with heavy load.
-**Advantages of using OpenEBS for PostgreSQL database:**
-- No need to manage the local disks, they are managed by OpenEBS
-- Large size PVs can be provisioned by OpenEBS and PostgreSQL
-- Start with small storage and add disks as needed on the fly. Sometimes PostgreSQL instances are scaled up because of capacity on the nodes. With OpenEBS persistent volumes, capacity can be thin provisioned and disks can be added to OpenEBS on the fly without disruption of service
-- PostgreSQL sometimes need highly available storage, in such cases OpenEBS volumes can be configured with 3 replicas.
-- If required, OpenEBS can be used to take backups of the PostgreSQL data periodically and back them up to S3 or to any object storage or to other PVs backed by OpenEBS so that restoration of the same data is possible to the same or any other Kubernetes cluster
+## Deployment model
-
+
-*Note: PostgreSQL can be deployed both as `deployment` or as `statefulset`. When PostgreSQL deployed as `statefulset`, you would not typically also replicate the data at OpenEBS level. When PostgreSQL is deployed as a `deployment`, consider 3 OpenEBS replicas, and choose your the StorageClass accordingly.*
+We will use GKE, where we will install Stackgres PostgreSQL with OpenEBS storage engine. The Local PV volume will be provisioned on a node where Stackgres PostgreSQL pod is getting scheduled and uses one of the matching unclaimed block devices, which will then use the entire block device for storing data. No other application can use this device. If users have limited blockdevices attached to some nodes, they can use `nodeSelector` in the application YAML to provision applications on particular nodes where the available block device is present. The recommended configuration is to have at least three nodes and one unclaimed external disk to be attached per node.
-
+## Configuration workflow
-
+1. [Install OpenEBS](/docs/next/postgres.html#install-openebs)
+2. [Select OpenEBS storage engine](/docs/next/postgres.html#select-openebs-storage-engine)
+3. [Configure OpenEBS Local PV StorageClass](/docs/next/postgres.html#configure-openebs-local-pv-storageclass)
+4. [Installing StackGres PostgreSQL Operator](/docs/next/postgres.html#installing-stackgres-postgresql-operator)
+5. [Installing PostgreSQL Database](/docs/next/postgres.html#installing-postgresql-database)
+6. [Accessing PostgreSQL database](/docs/next/postgres.html#accessing-postgresql-database)
-
-## Deployment model
-
+### Install OpenEBS
-
+If OpenEBS is not installed in your K8s cluster, this can be done from [here](/docs/next/installation.html). If OpenEBS is already installed, go to the next step.
-As shown above, OpenEBS volumes need to be configured with single replica. This configuration works fine when the nodes (hence the OpenEBS cStor pool) is deployed across Kubernetes zones.
+### Select OpenEBS storage engine
-
+A storage engine is the data plane component of the IO path of a Persistent Volume. In CAS architecture, users can choose different data planes for different application workloads based on a configuration policy. OpenEBS provides different types of storage engines and chooses the right engine that suits your type of application requirements and storage available on your Kubernetes nodes. More information can be read from [here](/docs/next/overview.html#types-of-openebs-storage-engines).
-
+In this document, we are deploying StackGres PostgreSQL using OpenEBS Local PV device.
-
+### Configure OpenEBS Local PV StorageClass
-## Configuration workflow
+There are 2 ways to use OpenEBS Local PV.
-
+- `openebs-hostpath` - Using this option, it will create Kubernetes Persistent Volumes that will store the data into OS host path directory at: /var/openebs/<"postgresql-pv-name">/. Select this option, if you don’t have any additional block devices attached to Kubernetes nodes. You would like to customize the directory where data will be saved, create a new OpenEBS Local PV storage class using these [instructions](https://docs.openebs.io/docs/next/uglocalpv-hostpath.html#create-storageclass).
-1. **Install OpenEBS**
+- `openebs-device` - Using this option, it will create Kubernetes Local PVs using the block devices attached to the node. Select this option when you want to dedicate a complete block device on a node to a StackGres PostgreSQL application pod. You can customize which devices will be discovered and managed by OpenEBS using the instructions [here](/docs/next/uglocalpv-device.html#optional-block-device-tagging).
- If OpenEBS is not installed in your K8s cluster, this can done from [here](/docs/next/installation.html). If OpenEBS is already installed, go to the next step.
+The Storage Class `openebs-device` has been chosen to deploy StackGres PostgreSQL in the Kubernetes cluster.
-2. **Configure cStor Pool**
+**Note:** Ensure that you have a disk with the required capacity is added to the corresponding nodes. In this example, we have added 100G disks to each node.
- If cStor Pool is not configured in your OpenEBS cluster, this can be done from [here](/docs/next/ugcstor.html#creating-cStor-storage-pools). As PostgreSQL is a StatefulSet application, it requires single storage replication factor. During cStor Pool creation, make sure that the maxPools parameter is set to >=3. If cStor pool is already configured, go to the next step. Sample YAML named **openebs-config.yaml** for configuring cStor Pool is provided in the Configuration details below.
+### Installing StackGres PostgreSQL Operator
-4. **Create Storage Class**
+In this section, we will install the StackGres operator. We will later deploy the latest available version of PostgreSQL application using StackGres.
- You must configure a StorageClass to provision cStor volume on cStor pool. In this solution we are using a StorageClass to consume the cStor Pool which is created using external disks attached on the Nodes. The storage pool is created using the steps provided in the Step 3. In this solution,PostgreSQL is a deployment. Since it requires replication at the storage level so cStor volume `replicaCount` is 3. Sample YAML named **openebs-sc-disk.yaml** to consume cStor pool with cStor volume replica count as 3 is provided in the configuration details below.
+```
+$ kubectl apply -f https://stackgres.io/downloads/stackgres-k8s/stackgres/1.0.0-alpha1/stackgres-operator-demo.yml
+```
-5. **Launch and test PostgreSQL**
+Once it’s ready, you will see that the two pods are `Running` and the other pods are in `Completed` state.
- Install PostgreSQL deployment on OpenEBS volume using the following command.
+```
+$ kubectl get pod -n stackgres
+
+NAME READY STATUS RESTARTS AGE
+stackgres-operator-78d57d4f55-vtlhj 1/1 Running 0 3m29s
+stackgres-operator-bootstrap-9p9zs 0/1 Completed 0 3m58s
+stackgres-operator-conversion-webhooks-jdhxx 0/1 Completed 0 4m
+stackgres-operator-crd-upgrade-5fx7c 0/1 Completed 0 3m59s
+stackgres-operator-create-certificate-r75cn 0/1 Completed 0 3m58s
+stackgres-operator-upgrade-wn79r 0/1 Completed 0 3m57s
+stackgres-operator-wait-mv6ss 0/1 Completed 0 3m56s
+stackgres-restapi-58c7db8b89-j8xkz 2/2 Running 0 3m22s
+```
- ```
- helm install --name my-release --set persistence.storageClass=openebs-cstor-disk stable/postgresql
- ```
+Users can manage the StackGres PostgreSQL database using a web console. This can be done accessing the Rest API service. Get the StackGres PostgreSQL service using the following command.
- This will create a PostgreSQL deployment with 3 replica of cStor volume with a PVC size of 8Gi. More details can be read from [here](https://github.com/helm/charts/tree/master/stable/postgresql).
+```
+$ kubectl get svc -n stackgres
-
+NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
+stackgres-operator ClusterIP 10.8.10.219 443/TCP 4m26s
+stackgres-restapi LoadBalancer 10.8.12.173 35.225.210.254 443:30098/TCP 4m25s
+```
-
-
-## Reference at openebs.ci
+Now, manage the PostgreSQL cluster using the Load Balancer IP on your web browser.
-
+In this example following is the web address.
-A live deployment of PostgreSQL using OpenEBS volumes can be seen at the website www.openebs.ci
+https://35.225.210.254/
-Deployment YAML spec files for PostgreSQL and OpenEBS resources are found here
+Default username is **admin**
- OpenEBS-CI dashboard of PostgreSQL
+Passwords can be obtained by running the following command.
+```
+$ kubectl get secret -n stackgres stackgres-restapi --template '{{ print (.data.clearPassword | base64decode)}}'
+AYzpZCPhSJvhEEazHCmMfamtEzL9NFsAOcZQwy06
+```
-
+### Installing PostgreSQL Database
-
+To create your first StackGres cluster you have to create a simple custom resource that reflects the cluster configuration. The following configuration file has been saved as *stackgres.yaml*.
-
+```
+apiVersion: stackgres.io/v1
+kind: SGCluster
+metadata:
+ name: app1-db
+spec:
+ instances: 2
+ postgresVersion: 'latest'
+ pods:
+ persistentVolume:
+ size: '90Gi'
+ storageClass: openebs-device
+ prometheusAutobind: false
+```
+In the above PostgreSQL cluster configuration file, the Storage Class used is **openebs-device** with a capacity of **90Gi**. So while scheduling Postgres pod, NDM will assign a matched block device which matches as per the requested capacity.
+Install StackGres PostgreSQL application using the following way.
-## Post deployment Operations
+```
+$ kubectl apply -f stackgres.yaml
-
+sgcluster.stackgres.io/app1-db-sc created
+```
-**Monitor OpenEBS Volume size**
+Verify the PostgreSQL cluster creation is successfully running under the default namespace.
-It is not seamless to increase the cStor volume size (refer to the roadmap item). Hence, it is recommended that sufficient size is allocated during the initial configuration.
+```
+$ kubectl get pod -l cluster=true
-**Monitor cStor Pool size**
+NAME READY STATUS RESTARTS AGE
+app1-db-0 5/5 Running 0 2m19s
+app1-db-1 5/5 Running 0 66s
+```
-In some cases the cStor pool may not be dedicated to only the PostgreSQL database. It is recommended to watch the pool capacity and add more disks to the pool before it hits 80% threshold. See [cStorPool metrics](/docs/next/ugcstor.html#monitor-pool).
+Verify the PostgreSQL persistent volume details.
+PVC:
+```
+$ kubectl get pvc -l cluster=true
-
+NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
+app1-db-data-app1-db-0 Bound pvc-259d26b7-75f5-4b8f-8571-b7fda80cd2ab 90Gi RWO openebs-device 94s
+app1-db-data-app1-db-1 Bound pvc-5f4d965b-3dfe-477a-a48d-ed3f4ab6743d 90Gi RWO openebs-device 21s
+```
-
+PV:
-
+```
+$ kubectl get pv
+
+NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
+pvc-259d26b7-75f5-4b8f-8571-b7fda80cd2ab 90Gi RWO Delete Bound default/app1-db-data-app1-db-0 openebs-device 108s
+pvc-5f4d965b-3dfe-477a-a48d-ed3f4ab6743d 90Gi RWO Delete Bound default/app1-db-data-app1-db-1 openebs-device 35s
+```
+Verify PostgreSQL service status.
+```
+$ kubectl get services -l cluster=true
+NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
+app1-db-primary ClusterIP 10.8.3.57 5432/TCP,5433/TCP 2m38s
+app1-db-replicas ClusterIP 10.8.13.224 5432/TCP,5433/TCP 2m38s
+```
+Since we have mentioned 2 replicas and capacity with 90G in Postgres cluster spec, any two disks with capacity more than 90G from the scheduled node will be claimed. In this case, 100G disks are present in all the nodes in the cluster. Verify whether 100G disks are claimed for provisioning PostgreSQL clusters.
-## Configuration Details
+```
+$ kubectl get bd -n openebs
-
+NAME NODENAME SIZE CLAIMSTATE STATUS AGE
+blockdevice-1fcc50ef4b3550ada3f82fe90102daca gke-ranjith-doc-default-pool-41db3a16-t4d0 107373116928 Claimed Active 17m
+blockdevice-58c88ac19e09084c6f71178130c20ba8 gke-ranjith-doc-default-pool-41db3a16-rqbt 107373116928 Unclaimed Active 19m
+blockdevice-8fd1127f57cf19b01e4da75110ae488a gke-ranjith-doc-default-pool-41db3a16-81tl 107373116928 Claimed Active 19m
+```
-**openebs-config.yaml**
+Verify the master and slave configuration.
-```yaml
-#Use the following YAMLs to create a cStor Storage Pool.
-# and associated storage class.
-apiVersion: openebs.io/v1alpha1
-kind: StoragePoolClaim
-metadata:
- name: cstor-disk
-spec:
- name: cstor-disk
- type: disk
- poolSpec:
- poolType: striped
- # NOTE - Appropriate disks need to be fetched using `kubectl get blockdevices -n openebs`
- # `Block devices` is a custom resource supported by OpenEBS with `node-disk-manager`
- # as the disk operator
-# Replace the following with actual disk CRs from your cluster `kubectl get blockdevices -n openebs`
-# Uncomment the below lines after updating the actual disk names.
- blockDevices:
- blockDeviceList:
-# Replace the following with actual disk CRs from your cluster from `kubectl get blockdevices -n openebs`
-# - blockdevice-69cdfd958dcce3025ed1ff02b936d9b4
-# - blockdevice-891ad1b581591ae6b54a36b5526550a2
-# - blockdevice-ceaab442d802ca6aae20c36d20859a0b
----
+```
+$ kubectl exec -ti "$(kubectl get pod --selector app=StackGresCluster,cluster=true -o name | head -n 1)" -c patroni -- patronictl list
+
++ Cluster: app1-db (6956175936947793994) ------+----+-----------+
+| Member | Host | Role | State | TL | Lag in MB |
++-----------+---------------+--------+---------+----+-----------+
+| app1-db-0 | 10.4.1.9:7433 | Leader | running | 1 | |
+| app1-db-1 | 10.4.2.8:7433 | | running | 1 | 0 |
++-----------+---------------+--------+---------+----+-----------+
```
-**openebs-sc-disk.yaml**
+Out of all of the PostgreSQL servers, one will be elected as the master, the rest will remain as read-only replicas.
+
+### Accessing PostgreSQL database
+
+Get the details of PostgreSQL database service.
-```yaml
-apiVersion: storage.k8s.io/v1
-kind: StorageClass
-metadata:
- name: openebs-cstor-disk
- annotations:
- openebs.io/cas-type: cstor
- cas.openebs.io/config: |
- - name: StoragePoolClaim
- value: "cstor-disk"
- - name: ReplicaCount
- value: "3"
-provisioner: openebs.io/provisioner-iscsi
-reclaimPolicy: Delete
----
```
+$ kubectl get services -l cluster=true
+NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
+app1-db-primary ClusterIP 10.8.3.57 5432/TCP,5433/TCP 5m47s
+app1-db-replicas ClusterIP 10.8.13.224 5432/TCP,5433/TCP 5m47s
+```
+Install *postgresql-client* on your master node or a node from where you have access to the Kubernetes cluster.
-
+```
+$ sudo apt-get install postgresql-client
+```
-
+Let’s access the database by accessing one of the application pods.
+
+```
+$ kubectl exec -ti "$(kubectl get pod --selector app=StackGresCluster,cluster=true,role=master -o name)" -c postgres-util -- psql
+
+psql (12.4 OnGres Inc.)
+Type "help" for help.
+
+postgres=# select current_user;
+ current_user
+--------------
+ postgres
+(1 row)
+
+postgres=# CREATE USER app WITH PASSWORD 'test';
+
+# CREATE ROLE
+postgres=# CREATE DATABASE app WITH OWNER app;
+
+#CREATE DATABASE
+postgres=# \l
+ List of databases
+ Name | Owner | Encoding | Collate | Ctype | Access privileges
+-----------+----------+----------+---------+---------+-----------------------
+ app | app | UTF8 | C.UTF-8 | C.UTF-8 |
+ postgres | postgres | UTF8 | C.UTF-8 | C.UTF-8 |
+ template0 | postgres | UTF8 | C.UTF-8 | C.UTF-8 | =c/postgres +
+ | | | | | postgres=CTc/postgres
+ template1 | postgres | UTF8 | C.UTF-8 | C.UTF-8 | =c/postgres +
+ | | | | | postgres=CTc/postgres
+(4 rows)
+
+$ postgres=# \c app;
+You are now connected to database "app" as user "postgres".
+app=#
+
+
+$ CREATE TABLE COMPANY(
+ ID INT PRIMARY KEY NOT NULL,
+ NAME TEXT NOT NULL,
+ AGE INT NOT NULL,
+ ADDRESS CHAR(50),
+ SALARY REAL,
+ JOIN_DATE DATE
+);
+CREATE TABLE
+
+app=# INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY,JOIN_DATE) VALUES (1, 'Paul', 32, 'California', 20000.00,'2001-07-13');
+
+app=# INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,JOIN_DATE) VALUES (2, 'Allen', 25, 'Texas', '2007-12-13');
+
+app=# INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY,JOIN_DATE) VALUES (3, 'Teddy', 23, 'Norway', 20000.00, DEFAULT );
+
+app=# \d
+ List of relations
+ Schema | Name | Type | Owner
+--------+---------+-------+----------
+ public | company | table | postgres
+(1 row)
+
+app=# select * from public.company;
+ id | name | age | address | salary | join_date
+----+-------+-----+----------------------------------------------------+--------+------------
+ 1 | Paul | 32 | California | 20000 | 2001-07-13
+ 2 | Allen | 25 | Texas | | 2007-12-13
+ 3 | Teddy | 23 | Norway | 20000 |
+(3 rows)
+
+app-# \q
+```
## See Also:
-
+### [OpenEBS use cases](/docs/next/usecases.html)
-### [OpenEBS architecture](/docs/next/architecture.html)
+### [Understanding NDM](/docs/next/ugndm.html)
-### [OpenEBS use cases](/docs/next/usecases.html)
+### [Local PV concepts](/docs/next/localpv.html)
-### [cStor pools overview](/docs/next/cstor.html#cstor-pools)
+### [Local PV User guide](/docs/next/uglocalpv-device.html)
@@ -202,4 +315,3 @@ reclaimPolicy: Delete
-