diff --git a/.drone/drone.yml b/.drone/drone.yml
deleted file mode 100644
index 233caf3..0000000
--- a/.drone/drone.yml
+++ /dev/null
@@ -1,168 +0,0 @@
-kind: pipeline
-type: docker
-name: linux-amd64
-
-platform:
-  arch: amd64
-  os: linux
-
-steps:
-- name: test
-  image: docker.io/drycc/go-dev
-  pull: always
-  privileged: true
-  commands:
-  - make docker-build test
-  environment:
-    VERSION: ${DRONE_TAG:-latest}-linux-amd64
-    DEV_REGISTRY: ${DEV_REGISTRY:-docker.io}
-    DRYCC_REGISTRY: ${DRYCC_REGISTRY:-docker.io}
-  when:
-    event:
-    - push
-    - tag
-    - pull_request
-  volumes:
-  - name: image_registries
-    path: /etc/containers/registries.conf
-
-- name: publish
-  image: docker.io/drycc/go-dev
-  pull: always
-  privileged: true
-  commands:
-  - echo $DOCKER_PASSWORD | docker login $DRYCC_REGISTRY --username $DOCKER_USERNAME --password-stdin
-  - make docker-build docker-immutable-push
-  environment:
-    VERSION: ${DRONE_TAG:-latest}-linux-amd64
-    DEV_REGISTRY:
-      from_secret: dev_registry
-    DRYCC_REGISTRY:
-      from_secret: drycc_registry
-    DOCKER_USERNAME:
-      from_secret: docker_username
-    DOCKER_PASSWORD:
-      from_secret: docker_password
-  when:
-    event:
-    - push
-    - tag
-  volumes:
-  - name: image_registries
-    path: /etc/containers/registries.conf
-
-trigger:
-  event:
-  - push
-  - tag
-  - pull_request
-
-volumes:
-- name: image_registries
-  host:
-    path: /etc/containers/registries.conf
-
----
-kind: pipeline
-type: docker
-name: linux-arm64
-
-platform:
-  arch: arm64
-  os: linux
-
-steps:
-- name: publish
-  image: docker.io/drycc/go-dev
-  pull: always
-  privileged: true
-  commands:
-  - echo $DOCKER_PASSWORD | docker login $DRYCC_REGISTRY --username $DOCKER_USERNAME --password-stdin
-  - make docker-build docker-immutable-push
-  environment:
-    VERSION: ${DRONE_TAG:-latest}-linux-arm64
-    DEV_REGISTRY:
-      from_secret: dev_registry
-    DRYCC_REGISTRY:
-      from_secret: drycc_registry
-    DOCKER_USERNAME:
-      from_secret: docker_username
-    DOCKER_PASSWORD:
-      from_secret: docker_password
-  volumes:
-  - name: image_registries
-    path: /etc/containers/registries.conf
-
-trigger:
-  event:
-  - push
-  - tag
-
-volumes:
-- name: image_registries
-  host:
-    path: /etc/containers/registries.conf
-
----
-kind: pipeline
-type: docker
-name: manifest
-
-steps:
-- name: generate manifest
-  image: docker.io/drycc/go-dev
-  pull: always
-  commands:
-  - sed -i "s/docker.io/$${DRYCC_REGISTRY}/g" .drone/manifest.tmpl
-  environment:
-    DRYCC_REGISTRY:
-      from_secret: drycc_registry
-
-- name: publish
-  image: plugins/manifest
-  settings:
-    spec: .drone/manifest.tmpl
-    username:
-      from_secret: docker_username
-    password:
-      from_secret: docker_password
-  environment:
-    DEV_REGISTRY:
-      from_secret: dev_registry
-    DRYCC_REGISTRY:
-      from_secret: drycc_registry
-
-trigger:
-  event:
-  - push
-  - tag
-
-depends_on:
-- linux-amd64
-- linux-arm64
-
----
-kind: pipeline
-type: docker
-name: chart
-
-steps:
-- name: generate chart
-  image: docker.io/drycc/python-dev
-  commands:
-  - IMAGE_TAG=$([ ! -z $DRONE_TAG ] && echo \"${DRONE_TAG:1}\" || echo \"canary\")
-  - sed -i "s/image_tag:\ \"canary\"/image_tag:\ $IMAGE_TAG/g" charts/database/values.yaml
-  - helm package charts/database --version ${DRONE_TAG:-v1.0.0}
-  - curl -u $CHARTMUSEUM_USERNAME:$CHARTMUSEUM_PASSWORD -F chart=@database-${DRONE_TAG:-v1.0.0}.tgz "$CHARTMUSEUM_API/api/$([ -z $DRONE_TAG ] && echo testing || echo stable)/charts"
-  environment:
-    CHARTMUSEUM_USERNAME:
-      from_secret: chartmuseum_username
-    CHARTMUSEUM_PASSWORD:
-      from_secret: chartmuseum_password
-    CHARTMUSEUM_API:
-      from_secret: chartmuseum_api
-
-trigger:
-  event:
-  - push
-  - tag
diff --git a/.drone/manifest.tmpl b/.drone/manifest.tmpl
deleted file mode 100644
index c3bab75..0000000
--- a/.drone/manifest.tmpl
+++ /dev/null
@@ -1,18 +0,0 @@
-image: docker.io/drycc/postgres:{{#if build.tag}}{{trimPrefix "v" build.tag}}{{else}}canary{{/if}}
-{{#if build.tags}}
-tags:
-{{#each build.tags}}
-  - {{this}}
-{{/each}}
-{{/if}}
-manifests:
-  -
-    image: docker.io/drycc/postgres:{{#if build.tag}}{{build.tag}}-{{else}}latest-{{/if}}linux-amd64
-    platform:
-      architecture: amd64
-      os: linux
-  -
-    image: docker.io/drycc/postgres:{{#if build.tag}}{{build.tag}}-{{else}}latest-{{/if}}linux-arm64
-    platform:
-      architecture: arm64
-      os: linux
diff --git a/.gitignore b/.gitignore
index 4d4647b..4573d78 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,4 @@
 contrib/ci/tmp
+.vscode/
+charts/database/Chart.lock
+charts/database/charts/
diff --git a/.woodpecker/build-linux.yml b/.woodpecker/build-linux.yml
new file mode 100644
index 0000000..ef4ecfd
--- /dev/null
+++ b/.woodpecker/build-linux.yml
@@ -0,0 +1,35 @@
+matrix:
+  platform:
+    - linux/amd64
+    - linux/arm64
+
+labels:
+  type: exec
+  platform: ${platform}
+
+steps:
+- name: publish-linux
+  image: bash
+  commands:
+  - export VERSION=$([ -z $CI_COMMIT_TAG ] && echo latest || echo $CI_COMMIT_TAG)-$(sed 's#/#-#g' <<< $CI_SYSTEM_PLATFORM)
+  - echo $CONTAINER_PASSWORD | podman login $DRYCC_REGISTRY --username $CONTAINER_USERNAME --password-stdin > /dev/null 2>&1
+  - make podman-build podman-immutable-push
+  environment:
+    CODENAME:
+      from_secret: codename
+    DEV_REGISTRY:
+      from_secret: dev_registry
+    DRYCC_REGISTRY:
+      from_secret: drycc_registry
+    CONTAINER_USERNAME:
+      from_secret: container_username
+    CONTAINER_PASSWORD:
+      from_secret: container_password
+  when:
+    event:
+    - push
+    - tag
+    - cron
+
+depends_on:
+- test-linux
\ No newline at end of file
diff --git a/.woodpecker/chart.yaml b/.woodpecker/chart.yaml
new file mode 100644
index 0000000..cfcd3ec
--- /dev/null
+++ b/.woodpecker/chart.yaml
@@ -0,0 +1,33 @@
+labels:
+  type: exec
+  platform: linux/amd64
+
+steps:
+- name: generate-chart
+  image: bash
+  commands:
+  - export VERSION=$(sed 's#v##' <<< $CI_COMMIT_TAG)
+  - export IMAGE_TAG=$([ ! -z $CI_COMMIT_TAG ] && echo \"$VERSION\" || echo \"canary\")
+  - export APP_VERSION=$([ -z $CI_COMMIT_TAG ] && echo $CI_COMMIT_SHA || echo $VERSION)
+  - export CHART_VERSION=$([ -z $CI_COMMIT_TAG ] && echo 1.0.0 || echo $VERSION)
+  - sed -i "s/imageTag:\ \"canary\"/imageTag:\ $IMAGE_TAG/g" charts/$${CI_REPO_NAME}/values.yaml
+  - helm package -u charts/$${CI_REPO_NAME} --version $CHART_VERSION --app-version $APP_VERSION
+  - echo $CONTAINER_PASSWORD | helm registry login $DRYCC_REGISTRY -u $CONTAINER_USERNAME --password-stdin
+  - helm push $${CI_REPO_NAME}-$CHART_VERSION.tgz oci://$DRYCC_REGISTRY/$([ -z $CI_COMMIT_TAG ] && echo charts-testing || echo charts)
+  environment:
+    DEV_REGISTRY:
+      from_secret: dev_registry
+    DRYCC_REGISTRY:
+      from_secret: drycc_registry
+    CONTAINER_USERNAME:
+      from_secret: container_username
+    CONTAINER_PASSWORD:
+      from_secret: container_password
+  when:
+    event:
+    - push
+    - tag
+    - cron
+
+depends_on:
+- manifest
diff --git a/.woodpecker/manifest.tmpl b/.woodpecker/manifest.tmpl
new file mode 100644
index 0000000..8739535
--- /dev/null
+++ b/.woodpecker/manifest.tmpl
@@ -0,0 +1,18 @@
+image: registry.drycc.cc/drycc/{{project}}:{{#if build.tag}}{{trimPrefix "v" build.tag}}{{else}}canary{{/if}}
+{{#if build.tags}}
+tags:
+{{#each build.tags}}
+  - {{this}}
+{{/each}}
+{{/if}}
+manifests:
+  -
+    image: registry.drycc.cc/drycc/{{project}}:{{#if build.tag}}{{build.tag}}-{{else}}latest-{{/if}}linux-amd64
+    platform:
+      architecture: amd64
+      os: linux
+  -
+    image: registry.drycc.cc/drycc/{{project}}:{{#if build.tag}}{{build.tag}}-{{else}}latest-{{/if}}linux-arm64
+    platform:
+      architecture: arm64
+      os: linux
diff --git a/.woodpecker/manifest.yml b/.woodpecker/manifest.yml
new file mode 100644
index 0000000..19fc70c
--- /dev/null
+++ b/.woodpecker/manifest.yml
@@ -0,0 +1,43 @@
+labels:
+  type: exec
+  platform: linux/amd64
+
+steps:
+- name: generate-manifest
+  image: bash
+  commands:
+  - sed -i "s/{{project}}/$${CI_REPO_NAME}/g" .woodpecker/manifest.tmpl
+  - sed -i "s/registry.drycc.cc/$${DRYCC_REGISTRY}/g" .woodpecker/manifest.tmpl
+  environment:
+    DRYCC_REGISTRY:
+      from_secret: drycc_registry
+  when:
+    event:
+    - tag
+    - push
+    - cron
+
+- name: publish-manifest
+  image: bash
+  commands:
+  - podman run --rm
+    -e PLUGIN_SPEC=.woodpecker/manifest.tmpl
+    -e PLUGIN_USERNAME=$CONTAINER_USERNAME
+    -e PLUGIN_PASSWORD=$CONTAINER_PASSWORD
+    -e DRONE_TAG=$CI_COMMIT_TAG
+    -v $(pwd):$(pwd)
+    -w $(pwd)
+    docker.io/plugins/manifest
+  environment:
+    CONTAINER_USERNAME:
+      from_secret: container_username
+    CONTAINER_PASSWORD:
+      from_secret: container_password
+  when:
+    event:
+    - tag
+    - push
+    - cron
+
+depends_on:
+- build-linux
diff --git a/.woodpecker/test-linux.yml b/.woodpecker/test-linux.yml
new file mode 100644
index 0000000..194832f
--- /dev/null
+++ b/.woodpecker/test-linux.yml
@@ -0,0 +1,24 @@
+matrix:
+  platform:
+  - linux/amd64
+  - linux/arm64
+
+labels:
+  type: exec
+  platform: ${platform}
+
+steps:
+- name: test-linux
+  image: bash
+  commands:
+  - make test
+  environment:
+    CODENAME:
+      from_secret: codename
+    DEV_REGISTRY:
+      from_secret: dev_registry
+  when:
+    event:
+    - push
+    - tag
+    - cron
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 2e2c6ae..c0c3290 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -1,5 +1,4 @@
-# How to Contribute
+# Contributing to Drycc
 
 This project is part of Drycc. You can find the latest contribution
-guidelines [at the Drycc project](https://github.com/drycc/drycc/blob/main/CONTRIBUTING.md).
-
+guidelines [in our documentation](https://www.drycc.cc/docs/workflow/contributing/overview/).
diff --git a/Dockerfile b/Dockerfile
index d4d386f..f0764de 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,36 +1,48 @@
-FROM docker.io/minio/mc:latest as mc
-
-
-FROM docker.io/library/golang:buster as builder
-ARG GOBIN=/usr/local/bin
-ARG WAL_G_VERSION=v1.1
-
-RUN apt-get update \
-  && apt-get install -y git gcc liblzo2-dev cmake \
-  && git clone --dept 1 -b $WAL_G_VERSION https://github.com/wal-g/wal-g $GOPATH/src/github.com/wal-g/wal-g \
-  && cd $GOPATH/src/github.com/wal-g/wal-g \
-  && make install \
-  && make deps \
-  && make pg_install
-
-
-FROM docker.io/library/postgres:13-buster
-
-COPY rootfs /
-COPY --from=mc /usr/bin/mc /bin/mc
-COPY --from=builder /usr/local/bin/wal-g  /bin/wal-g
-
-ENV PGDATA $PGDATA/$PG_MAJOR
-ENV WALG_ENVDIR /etc/wal-g.d/env
-
-RUN mkdir -p $WALG_ENVDIR \
-  && apt-get update \
-  && apt-get install -y --no-install-recommends \
-    jq \
-    python3 \
-    ca-certificates \
-    python3-pip \
-  && pip3 install envdir
-
-CMD ["/docker-entrypoint.sh", "postgres"]
-EXPOSE 5432
+ARG CODENAME
+FROM registry.drycc.cc/drycc/base:${CODENAME}
+
+COPY rootfs/usr /usr/
+COPY rootfs/entrypoint.sh /entrypoint.sh
+
+
+ARG PYTHON_VERSION="3.13" \
+  POSTGRES_EXPORTER_VERSION="0.18.1"
+
+ENV HOME=/data \
+  PG_MAJOR=18 \
+  PG_MINOR=1 \
+  S3_RCLONE_VERSION="1.71.1" 
+
+ENV PGDATA=$HOME/$PG_MAJOR
+
+RUN install-packages vim gcc pigz jq\
+  && install-stack python $PYTHON_VERSION \
+  && install-stack postgresql $PG_MAJOR.$PG_MINOR \
+  && install-stack rclone $S3_RCLONE_VERSION \
+  && install-stack postgres_exporter $POSTGRES_EXPORTER_VERSION \
+  && . init-stack \
+  && set -eux; pip3 install --disable-pip-version-check --no-cache-dir psycopg[binary] patroni[kubernetes] 2>/dev/null; set +eux \
+  && apt-get purge -y --auto-remove gcc \
+  && apt-get autoremove -y \
+  && apt-get clean -y \
+  && rm -rf \
+  /usr/share/doc \
+  /usr/share/man \
+  /usr/share/info \
+  /usr/share/locale \
+  /var/lib/apt/lists/* \
+  /var/log/* \
+  /var/cache/debconf/* \
+  /etc/systemd \
+  /lib/lsb \
+  /lib/udev \
+  /usr/lib/`echo $(uname -m)`-linux-gnu/gconv/IBM* \
+  /usr/lib/`echo $(uname -m)`-linux-gnu/gconv/EBC* \
+  && mkdir -p /usr/share/man/man{1..8} \
+  && mkdir -p $PGDATA \
+  && groupadd postgres && useradd -g postgres postgres \
+  && chown -R postgres:postgres $HOME
+
+USER postgres
+ENTRYPOINT ["init-stack", "/entrypoint.sh"]
+EXPOSE 5432 8008
diff --git a/MAINTAINERS.md b/MAINTAINERS.md
index 634e415..fc5f4fa 100644
--- a/MAINTAINERS.md
+++ b/MAINTAINERS.md
@@ -1,4 +1,4 @@
 # Drycc Maintainers
 
 This project is part of Drycc. The official maintainers documentation is
-located [in the main project](https://github.com/drycc/drycc/blob/main/MAINTAINERS.md).
+located [in our documentation](http://www.drycc.cc/contributing/maintainers/).
diff --git a/Makefile b/Makefile
index 6c14bbb..185c51b 100644
--- a/Makefile
+++ b/Makefile
@@ -1,42 +1,34 @@
 # Short name: Short name, following [a-zA-Z_], used all over the place.
 # Some uses for short name:
-# - Docker image name
+# - Container image name
 # - Kubernetes service, rc, pod, secret, volume names
-SHORT_NAME := postgres
+SHORT_NAME := database
 DRYCC_REGISTRY ?= ${DEV_REGISTRY}
 IMAGE_PREFIX ?= drycc
 PLATFORM ?= linux/amd64,linux/arm64
 
 include versioning.mk
 
-SHELL_SCRIPTS = $(wildcard _scripts/*.sh contrib/ci/*.sh rootfs/bin/*)
+SHELL_SCRIPTS = $(wildcard rootfs/usr/share/scripts/patroni/*)
 
 # The following variables describe the containerized development environment
 # and other build options
 DEV_ENV_IMAGE := ${DEV_REGISTRY}/drycc/go-dev
-DEV_ENV_WORK_DIR := /go/src/${REPO_PATH}
-DEV_ENV_CMD := docker run --rm -v ${CURDIR}:${DEV_ENV_WORK_DIR} -w ${DEV_ENV_WORK_DIR} ${DEV_ENV_IMAGE}
-DEV_ENV_CMD_INT := docker run -it --rm -v ${CURDIR}:${DEV_ENV_WORK_DIR} -w ${DEV_ENV_WORK_DIR} ${DEV_ENV_IMAGE}
+DEV_ENV_WORK_DIR := /opt/drycc/go/src/${REPO_PATH}
+DEV_ENV_CMD := podman run --rm -v ${CURDIR}:${DEV_ENV_WORK_DIR} -w ${DEV_ENV_WORK_DIR} ${DEV_ENV_IMAGE}
+DEV_ENV_CMD_INT := podman run -it --rm -v ${CURDIR}:${DEV_ENV_WORK_DIR} -w ${DEV_ENV_WORK_DIR} ${DEV_ENV_IMAGE}
 
-all: docker-build docker-push
+all: podman-build podman-push
 
 # For cases where we're building from local
 # We also alter the RC file to set the image name.
-docker-build:
-	docker build ${DOCKER_BUILD_FLAGS} -t ${IMAGE} .
-	docker tag ${IMAGE} ${MUTABLE_IMAGE}
+podman-build:
+	podman build --build-arg CODENAME=${CODENAME} -t ${IMAGE} .
+	podman tag ${IMAGE} ${MUTABLE_IMAGE}
 
-docker-buildx:
-	docker buildx build --platform ${PLATFORM} -t ${IMAGE} . --push
-
-test: test-style test-functional
+test: test-style
 
 test-style:
 	${DEV_ENV_CMD} shellcheck $(SHELL_SCRIPTS)
 
-test-functional: test-functional-minio
-
-test-functional-minio:
-	contrib/ci/test-minio.sh ${IMAGE}
-
-.PHONY: all docker-build docker-push test
+.PHONY: all podman-build podman-push test
diff --git a/README.md b/README.md
index fa2c5a5..80225f9 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,6 @@
 
 # Drycc Postgres
-[![Build Status](https://drone.drycc.cc/api/badges/drycc/postgres/status.svg)](https://drone.drycc.cc/drycc/postgres)
+[![Build Status](https://woodpecker.drycc.cc/api/badges/drycc/database/status.svg)](https://woodpecker.drycc.cc/drycc/database)
 
 Drycc (pronounced DAY-iss) Workflow is an open source Platform as a Service (PaaS) that adds a developer-friendly layer to any [Kubernetes](http://kubernetes.io) cluster, making it easy to deploy and manage applications on your own servers.
 
@@ -8,10 +8,6 @@ For more information about the Drycc Workflow, please visit the main project pag
 
 We welcome your input! If you have feedback, please submit an [issue][issues]. If you'd like to participate in development, please read the "Development" section below and submit a [pull request][prs].
 
-# About
-
-This component is a PostgreSQL database for use in Kubernetes. It builds on the official [postgres](https://registry.hub.docker.com/_/postgres/) Docker image. While it's intended for use inside of the Drycc Workflow open source [PaaS](https://en.wikipedia.org/wiki/Platform_as_a_service), it's flexible enough to be used as a standalone pod on any Kubernetes cluster or even as a standalone Docker container.
-
 # Development
 
 The Drycc project welcomes contributions from all developers. The high level process for development matches many other open source projects. See below for an outline.
@@ -27,7 +23,7 @@ The Drycc project welcomes contributions from all developers. The high level pro
 In order to develop and test this component in a Drycc cluster, you'll need the following:
 
 * [GNU Make](https://www.gnu.org/software/make/)
-* [Docker](https://www.docker.com/) installed, configured and running
+* [Podman](https://podman.io/) installed, configured and running
 * A working Kubernetes cluster and `kubectl` installed and configured to talk to the cluster
  * If you don't have this setup, please see [the Kubernetes documentation][k8s-docs]
 
@@ -39,27 +35,27 @@ If your feature or bugfix doesn't easily lend itself to unit/integration testing
 
 ### Dogfooding
 
-Finally, we encourage you to [dogfood](https://en.wikipedia.org/wiki/Eating_your_own_dog_food) this component while you're writing code on it. To do so, you'll need to build and push Docker images with your changes.
+Finally, we encourage you to [dogfood](https://en.wikipedia.org/wiki/Eating_your_own_dog_food) this component while you're writing code on it. To do so, you'll need to build and push Container images with your changes.
 
 This project has a [Makefile](https://github.com/drycc/postgres/blob/main/Makefile) that makes these tasks significantly easier. It requires the following environment variables to be set:
 
-* `DRYCC_REGISTRY` - A Docker registry that you have push access to and your Kubernetes cluster can pull from
+* `DRYCC_REGISTRY` - A Container registry that you have push access to and your Kubernetes cluster can pull from
   * If this is [Docker Hub](https://hub.docker.com/), leave this variable empty
   * Otherwise, ensure it has a trailing `/`
-* `IMAGE_PREFIX` - The organization in the Docker repository. This defaults to `drycc`, but if you don't have access to that organization, set this to one you have push access to.
+* `IMAGE_PREFIX` - The organization in the Container repository. This defaults to `drycc`, but if you don't have access to that organization, set this to one you have push access to.
 * `SHORT_NAME` (optional) - The name of the image. This defaults to `postgres`
-* `VERSION` (optional) - The tag of the Docker image. This defaults to the current Git SHA (the output of `git rev-parse --short HEAD`)
+* `VERSION` (optional) - The tag of the Container image. This defaults to the current Git SHA (the output of `git rev-parse --short HEAD`)
 
-Assuming you have these variables set correctly, run `make docker-build` to build the new image, and `make docker-push` to push it. Here is an example command that would push to `example.com/arschles/postgres:devel`:
+Assuming you have these variables set correctly, run `make podman-build` to build the new image, and `make podman-push` to push it. Here is an example command that would push to `example.com/arschles/postgres:devel`:
 
 ```console
 export DRYCC_REGISTRY=example.com/
 export IMAGE_PREFIX=arschles
 export VERSION=devel
-make docker-build docker-push
+make podman-build podman-push
 ```
 
-Note that you'll have to push your image to a Docker repository (`make docker-push`) in order for your Kubernetes cluster to pull the image. This is important for testing in your cluster.
+Note that you'll have to push your image to a Container repository (`make podman-push`) in order for your Kubernetes cluster to pull the image. This is important for testing in your cluster.
 
 
 [issues]: https://github.com/drycc/postgres/issues
diff --git a/charts/database/Chart.yaml b/charts/database/Chart.yaml
index a27dd34..d12aee8 100644
--- a/charts/database/Chart.yaml
+++ b/charts/database/Chart.yaml
@@ -1,6 +1,12 @@
 name: database
-home: https://github.com/drycc/postgres
-version: v1.0.0
+apiVersion: v2
+appVersion: 1.0.0
+dependencies:
+  - name: common
+    repository: oci://registry.drycc.cc/charts
+    version: ~1.1.2
+home: https://github.com/drycc/database
+version: v1.1.0
 description: A PostgreSQL database used by Drycc Workflow.
 keywords:
   - database
diff --git a/charts/database/templates/_helper.tpl b/charts/database/templates/_helper.tpl
new file mode 100644
index 0000000..3d1638f
--- /dev/null
+++ b/charts/database/templates/_helper.tpl
@@ -0,0 +1,117 @@
+{{- define "database.envs" }}
+env:
+- name: RETAIN_BACKUPS_AGE
+  value: "{{.Values.cronjob.retainBackupsAge}}"
+{{- if (.Values.storageEndpoint) }}
+- name: "DRYCC_STORAGE_BUCKET"
+  valueFrom:
+    secretKeyRef:
+      name: database-creds
+      key: storage-bucket
+- name: "DRYCC_STORAGE_ENDPOINT"
+  valueFrom:
+    secretKeyRef:
+      name: database-creds
+      key: storage-endpoint
+- name: "DRYCC_STORAGE_ACCESSKEY"
+  valueFrom:
+    secretKeyRef:
+      name: database-creds
+      key: storage-accesskey
+- name: "DRYCC_STORAGE_SECRETKEY"
+  valueFrom:
+    secretKeyRef:
+      name: database-creds
+      key: storage-secretkey
+- name: "DRYCC_STORAGE_PATH_STYLE"
+  valueFrom:
+    secretKeyRef:
+      name: database-creds
+      key: storage-path-style
+{{- else if .Values.storage.enabled  }}
+- name: "DRYCC_STORAGE_BUCKET"
+  value: "database"
+- name: "DRYCC_STORAGE_ENDPOINT"
+  value: http://drycc-storage:9000
+- name: "DRYCC_STORAGE_ACCESSKEY"
+  valueFrom:
+    secretKeyRef:
+      name: storage-creds
+      key: accesskey
+- name: "DRYCC_STORAGE_SECRETKEY"
+  valueFrom:
+    secretKeyRef:
+      name: storage-creds
+      key: secretkey
+- name: "DRYCC_STORAGE_PATH_STYLE"
+  value: "true"
+{{- end }}
+{{- if eq .Values.debug "true" }}
+- name: PATRONI_LOG_LEVEL
+  value: DEBUG
+- name: PATRONI_LOG_TRACEBACK_LEVEL
+  value: DEBUG
+{{- end }}
+- name: PGCTLTIMEOUT
+  value: "{{.Values.timeout}}"
+- name: PATRONI_KUBERNETES_POD_IP
+  valueFrom:
+    fieldRef:
+      fieldPath: status.podIP
+- name: PATRONI_KUBERNETES_NAMESPACE
+  valueFrom:
+    fieldRef:
+      fieldPath: metadata.namespace
+- name: PATRONI_KUBERNETES_BYPASS_API_SERVICE
+  value: 'true'
+- name: PATRONI_KUBERNETES_USE_ENDPOINTS
+  value: 'true'
+- name: PATRONI_KUBERNETES_LABELS
+  value: '{app: drycc-database, cluster-name: drycc-database}'
+- name: PATRONI_SCOPE
+  value: drycc-database
+- name: PATRONI_NAME
+  valueFrom:
+    fieldRef:
+      fieldPath: metadata.name
+- name: PATRONI_POSTGRESQL_PGPASS
+  value: /tmp/pgpass
+- name: PATRONI_POSTGRESQL_LISTEN
+  value: '0.0.0.0:5432'
+- name: PATRONI_RESTAPI_LISTEN
+  value: '0.0.0.0:8008'
+- name: "DRYCC_DATABASE_INIT_NAMES"
+  value: "{{.Values.initDatabases}}"
+- name: "DRYCC_DATABASE_EXTENSIONS"
+  value: "{{.Values.databaseExtensions}}"
+- name: DRYCC_DATABASE_SUPERUSER
+  valueFrom:
+    secretKeyRef:
+      name: database-creds
+      key: superuser
+- name: DRYCC_DATABASE_SUPERUSER_PASSWORD
+  valueFrom:
+    secretKeyRef:
+      name: database-creds
+      key: superuser-password
+- name: DRYCC_DATABASE_REPLICATOR
+  valueFrom:
+    secretKeyRef:
+      name: database-creds
+      key: replicator
+- name: DRYCC_DATABASE_REPLICATOR_PASSWORD
+  valueFrom:
+    secretKeyRef:
+      name: database-creds
+      key: replicator-password
+- name: "DRYCC_DATABASE_USER"
+  valueFrom:
+    secretKeyRef:
+      name: database-creds
+      key: user
+- name: "DRYCC_DATABASE_PASSWORD"
+  valueFrom:
+    secretKeyRef:
+      name: database-creds
+      key: password
+{{- end }}
diff --git a/charts/database/templates/database-clusterrole.yaml b/charts/database/templates/database-clusterrole.yaml
new file mode 100644
index 0000000..066c2e1
--- /dev/null
+++ b/charts/database/templates/database-clusterrole.yaml
@@ -0,0 +1,13 @@
+apiVersion: rbac.authorization.k8s.io/v1
+kind: ClusterRole
+metadata:
+  name: {{ printf "%s:drycc-database" .Release.Namespace | quote }}
+rules:
+- apiGroups:
+  - ""
+  resources:
+  - endpoints
+  resourceNames:
+  - kubernetes
+  verbs:
+  - get
diff --git a/charts/database/templates/database-clusterrolebinding.yaml b/charts/database/templates/database-clusterrolebinding.yaml
new file mode 100644
index 0000000..24e3fa6
--- /dev/null
+++ b/charts/database/templates/database-clusterrolebinding.yaml
@@ -0,0 +1,12 @@
+apiVersion: rbac.authorization.k8s.io/v1
+kind: ClusterRoleBinding
+metadata:
+  name: {{ printf "%s:drycc-database" .Release.Namespace | quote }}
+roleRef:
+  apiGroup: rbac.authorization.k8s.io
+  kind: ClusterRole
+  name: {{ printf "%s:drycc-database" .Release.Namespace | quote }}
+subjects:
+- kind: ServiceAccount
+  name: drycc-database
+  namespace: {{ .Release.Namespace }}
diff --git a/charts/database/templates/database-cronjob-backup.yaml b/charts/database/templates/database-cronjob-backup.yaml
new file mode 100644
index 0000000..ee4e042
--- /dev/null
+++ b/charts/database/templates/database-cronjob-backup.yaml
@@ -0,0 +1,29 @@
+{{- if .Values.cronjob.enabled }}
+apiVersion: {{ include "common.capabilities.cronjob.apiVersion" . }}
+kind: CronJob
+metadata:
+  name: drycc-database-cronjob-backup
+  labels:
+    heritage: drycc
+  annotations:
+    component.drycc.cc/version: {{ .Values.imageTag }}
+
+spec:
+  schedule: "{{ .Values.cronjob.scheduleCronJob }}"
+  failedJobsHistoryLimit: 1
+  successfulJobsHistoryLimit: 1
+  jobTemplate:
+    spec:
+      template:
+        spec:
+          restartPolicy: OnFailure              
+          containers:         
+          - name: drycc-database-cronjob-backup
+            image: {{.Values.imageRegistry}}/{{.Values.imageOrg}}/database:{{.Values.imageTag}}
+            imagePullPolicy: {{.Values.imagePullPolicy}}
+            command:
+            - init-stack
+            args:  
+            - /usr/share/scripts/backup.sh
+            {{- include "database.envs" . | indent 12 }}
+{{- end -}}
\ No newline at end of file
diff --git a/charts/database/templates/database-deployment.yaml b/charts/database/templates/database-deployment.yaml
deleted file mode 100644
index a7f0223..0000000
--- a/charts/database/templates/database-deployment.yaml
+++ /dev/null
@@ -1,78 +0,0 @@
-{{- if eq .Values.global.database_location "on-cluster" }}
-apiVersion: apps/v1
-kind: Deployment
-metadata:
-  name: drycc-database
-  labels:
-    heritage: drycc
-  annotations:
-    component.drycc.cc/version: {{ .Values.image_tag }}
-spec:
-  replicas: 1
-  strategy:
-    type: Recreate
-  selector:
-    matchLabels:
-      app: drycc-database
-  template:
-    metadata:
-      labels:
-        app: drycc-database
-    spec:
-      serviceAccount: drycc-database
-      initContainers:
-      - name: drycc-database-init
-        image: docker.io/drycc/python-dev:latest
-        imagePullPolicy: {{.Values.image_pull_policy}}
-        command:
-          - netcat
-          - -v
-          - -a
-          - $(DRYCC_MINIO_SERVICE_HOST):$(DRYCC_MINIO_SERVICE_PORT)
-      containers:
-        - name: drycc-database
-          image: {{.Values.image_registry}}/{{.Values.image_org}}/postgres:{{.Values.image_tag}}
-          imagePullPolicy: {{.Values.image_pull_policy}}
-          ports:
-            - containerPort: 5432
-{{- if or (.Values.limits_cpu) (.Values.limits_memory)}}
-          resources:
-            limits:
-{{- if (.Values.limits_cpu) }}
-              cpu: {{.Values.limits_cpu}}
-{{- end}}
-{{- if (.Values.limits_memory) }}
-              memory: {{.Values.limits_memory}}
-{{- end}}
-{{- end}}
-          env:
-            - name: DATABASE_STORAGE
-              value: "{{.Values.global.storage}}"
-            - name: PGCTLTIMEOUT
-              value: "{{.Values.timeout}}"
-          lifecycle:
-            preStop:
-              exec:
-                command:
-                  - gosu
-                  - postgres
-                  - do_backup
-          readinessProbe:
-            exec:
-              command:
-                - is_running
-            initialDelaySeconds: 30
-            timeoutSeconds: 1
-          volumeMounts:
-            - name: database-creds
-              mountPath: /var/run/secrets/drycc/database/creds
-            - name: objectstore-creds
-              mountPath: /var/run/secrets/drycc/objectstore/creds
-      volumes:
-        - name: database-creds
-          secret:
-            secretName: database-creds
-        - name: objectstore-creds
-          secret:
-            secretName: objectstorage-keyfile
-{{- end }}
diff --git a/charts/database/templates/database-role-binding.yaml b/charts/database/templates/database-role-binding.yaml
new file mode 100644
index 0000000..e927dab
--- /dev/null
+++ b/charts/database/templates/database-role-binding.yaml
@@ -0,0 +1,11 @@
+apiVersion: rbac.authorization.k8s.io/v1
+kind: RoleBinding
+metadata:
+  name: drycc-database
+roleRef:
+  apiGroup: rbac.authorization.k8s.io
+  kind: Role
+  name: drycc-database
+subjects:
+- kind: ServiceAccount
+  name: drycc-database
diff --git a/charts/database/templates/database-role.yaml b/charts/database/templates/database-role.yaml
new file mode 100644
index 0000000..8957f9b
--- /dev/null
+++ b/charts/database/templates/database-role.yaml
@@ -0,0 +1,54 @@
+apiVersion: rbac.authorization.k8s.io/v1
+kind: Role
+metadata:
+  name: drycc-database
+rules:
+- apiGroups:
+  - ""
+  resources:
+  - configmaps
+  verbs:
+  - create
+  - get
+  - list
+  - patch
+  - update
+  - watch
+  # delete and deletecollection are required only for 'patronictl remove'
+  - delete
+  - deletecollection
+- apiGroups:
+  - ""
+  resources:
+  - endpoints
+  verbs:
+  - get
+  - patch
+  - update
+  # the following three privileges are necessary only when using endpoints
+  - create
+  - list
+  - watch
+  # delete and deletecollection are required only for for 'patronictl remove'
+  - delete
+  - deletecollection
+- apiGroups:
+  - ""
+  resources:
+  - pods
+  verbs:
+  - get
+  - list
+  - patch
+  - update
+  - watch
+# The following privilege is only necessary for creation of headless service
+# for drycc-database-config endpoint, in order to prevent cleaning it up by the
+# k8s master. You can avoid giving this privilege by explicitly creating the
+# service like it is done in this manifest (lines 2..10)
+- apiGroups:
+  - ""
+  resources:
+  - services
+  verbs:
+  - create
diff --git a/charts/database/templates/database-secret-creds.yaml b/charts/database/templates/database-secret-creds.yaml
index eee2b80..6b7f01d 100644
--- a/charts/database/templates/database-secret-creds.yaml
+++ b/charts/database/templates/database-secret-creds.yaml
@@ -1,4 +1,3 @@
-{{ if eq .Values.global.database_location "on-cluster"}}
 apiVersion: v1
 kind: Secret
 metadata:
@@ -6,11 +5,17 @@ metadata:
   labels:
     app: drycc-database
     heritage: drycc
-  annotations:
-    "helm.sh/hook": pre-install
 data:
-  user: {{ if .Values.username | default "" | ne "" }}{{ .Values.username | b64enc }}{{ else }}{{ randAlphaNum 32 | b64enc }}{{ end }}
-  password: {{ if .Values.password | default "" | ne "" }}{{ .Values.password | b64enc }}{{ else }}{{ randAlphaNum 32 | b64enc }}{{ end }}
-  controller-database-name: {{ if .Values.controller_database_name | default "" | ne "" }}{{ .Values.controller_database_name | b64enc }}{{ else }}{{ randAlphaNum 32 | b64enc }}{{ end }}
-  passport-database-name: {{ if .Values.passport_database_name | default "" | ne "" }}{{ .Values.passport_database_name | b64enc }}{{ else }}{{ randAlphaNum 32 | b64enc }}{{ end }}
-{{- end }}
+  superuser: {{ include "common.secrets.lookup" (dict "secret" "database-creds" "key" "superuser" "defaultValue" (.Values.superuser | default (randAlpha 32) | lower) "context" $) }}
+  superuser-password: {{ include "common.secrets.lookup" (dict "secret" "database-creds" "key" "superuser-password" "defaultValue" (.Values.superuserPassword | default (randAlphaNum 32)) "context" $) }}
+  replicator: {{ include "common.secrets.lookup" (dict "secret" "database-creds" "key" "replicator" "defaultValue" (.Values.replicator | default (randAlpha 32) | lower) "context" $) }}
+  replicator-password: {{ include "common.secrets.lookup" (dict "secret" "database-creds" "key" "replicator-password" "defaultValue" (.Values.replicatorPassword | default (randAlphaNum 32) | lower) "context" $) }}
+  user: {{ include "common.secrets.lookup" (dict "secret" "database-creds" "key" "user" "defaultValue" (.Values.user | default (randAlpha 32) | lower) "context" $) }}
+  password: {{ include "common.secrets.lookup" (dict "secret" "database-creds" "key" "password" "defaultValue" (.Values.password | default (randAlphaNum 32)) "context" $) }}
+  {{- if (.Values.storageEndpoint) }}
+  storage-bucket: {{ .Values.storageBucket | b64enc }}
+  storage-endpoint: {{ .Values.storageEndpoint | b64enc }}
+  storage-accesskey: {{ .Values.storageAccesskey | b64enc }}
+  storage-secretkey: {{ .Values.storageSecretkey | b64enc }}
+  storage-path-style: {{ .Values.storagePathStyle | b64enc }}
+  {{- end }}
diff --git a/charts/database/templates/database-service-account.yaml b/charts/database/templates/database-service-account.yaml
index 094eef2..d429cfa 100644
--- a/charts/database/templates/database-service-account.yaml
+++ b/charts/database/templates/database-service-account.yaml
@@ -1,8 +1,6 @@
-{{- if eq .Values.global.database_location "on-cluster" }}
 apiVersion: v1
 kind: ServiceAccount
 metadata:
   name: drycc-database
   labels:
     heritage: drycc
-{{- end }}
diff --git a/charts/database/templates/database-service-replica.yaml b/charts/database/templates/database-service-replica.yaml
new file mode 100644
index 0000000..e168d0d
--- /dev/null
+++ b/charts/database/templates/database-service-replica.yaml
@@ -0,0 +1,21 @@
+apiVersion: v1
+kind: Service
+metadata:
+  name: drycc-database-replica
+  annotations:
+    {{- with .Values.service.annotations }}
+    {{- toYaml . | nindent 4 }}
+    {{- end }}
+  labels:
+    heritage: drycc
+    app: drycc-database
+    role: replica
+spec:
+  type: ClusterIP
+  ports:
+    - name: postgres
+      port: 5432
+      targetPort: 5432
+  selector:
+    app: drycc-database
+    role: replica
diff --git a/charts/database/templates/database-service.yaml b/charts/database/templates/database-service.yaml
index cefe91d..0638885 100644
--- a/charts/database/templates/database-service.yaml
+++ b/charts/database/templates/database-service.yaml
@@ -1,14 +1,15 @@
-{{- if eq .Values.global.database_location "on-cluster" }}
 apiVersion: v1
 kind: Service
 metadata:
   name: drycc-database
+  annotations:
+    {{- with .Values.service.annotations }}
+    {{- toYaml . | nindent 4 }}
+    {{- end }}
   labels:
     heritage: drycc
 spec:
+  type: ClusterIP
   ports:
-    - name: postgres
-      port: 5432
-  selector:
-    app: drycc-database
-{{- end }}
+    - port: 5432
+      targetPort: 5432
diff --git a/charts/database/templates/database-statefulset.yaml b/charts/database/templates/database-statefulset.yaml
new file mode 100644
index 0000000..300bc7b
--- /dev/null
+++ b/charts/database/templates/database-statefulset.yaml
@@ -0,0 +1,159 @@
+apiVersion: apps/v1
+kind: StatefulSet
+metadata:
+  name: drycc-database
+  labels:
+    heritage: drycc
+  annotations:
+    component.drycc.cc/version: {{ .Values.imageTag }}
+spec:
+  replicas: {{ .Values.replicas }}
+  serviceName: drycc-database
+  selector:
+    matchLabels:
+      app: drycc-database
+      cluster-name: drycc-database
+  template:
+    metadata:
+      annotations:
+        prometheus.io/path: /metrics
+        prometheus.io/port: "9187"
+        prometheus.io/scrape: "true"
+      labels: {{- include "common.labels.standard" . | nindent 8 }}
+        app: drycc-database
+        cluster-name: drycc-database
+    spec:
+      affinity:
+        podAffinity: {{- include "common.affinities.pods" (dict "type" .Values.podAffinityPreset.type "component" "" "extraMatchLabels" .Values.podAffinityPreset.extraMatchLabels "topologyKey" "" "context" $) | nindent 10 }}
+        podAntiAffinity: {{- include "common.affinities.pods" (dict "type" .Values.podAntiAffinityPreset.type "component" "" "extraMatchLabels" .Values.podAntiAffinityPreset.extraMatchLabels "topologyKey" "" "context" $) | nindent 10 }}
+        nodeAffinity: {{- include "common.affinities.nodes" (dict "type" .Values.nodeAffinityPreset.type "key" .Values.nodeAffinityPreset.key "values" .Values.nodeAffinityPreset.values ) | nindent 10 }}
+      serviceAccountName: drycc-database
+      containers:
+      - name: drycc-database
+        image: {{.Values.imageRegistry}}/{{.Values.imageOrg}}/database:{{.Values.imageTag}}
+        imagePullPolicy: {{.Values.imagePullPolicy}}
+        {{- if .Values.diagnosticMode.enabled }}
+        command: {{- include "common.tplvalues.render" (dict "value" .Values.diagnosticMode.command "context" $) | nindent 10 }}
+        args: {{- include "common.tplvalues.render" (dict "value" .Values.diagnosticMode.args "context" $) | nindent 10 }}
+        {{- end }}
+        ports:
+        - containerPort: 8008
+          protocol: TCP
+        - containerPort: 5432
+          protocol: TCP
+        {{- include "database.envs" . | indent 8 }}
+        {{- with index .Values "resources" }}
+        resources:
+          {{- toYaml . | nindent 10 }}
+        {{- end }}
+        {{- if not .Values.diagnosticMode.enabled }}
+        lifecycle:
+          preStop:
+            exec:
+              command:
+                - /usr/bin/env
+                - bash
+                - -c
+                - |
+                  # switch leader pod if the current pod is the leader
+                  if curl --fail http://localhost:8008/read-write; then
+                    init-stack patronictl switchover --force
+                  fi
+        livenessProbe:
+          failureThreshold: 3                            
+          httpGet:       
+            path: /liveness
+            port: 8008
+            scheme: HTTP   
+          initialDelaySeconds: 10
+          periodSeconds: 10
+          successThreshold: 1
+          timeoutSeconds: 5
+        readinessProbe:
+          exec:
+            command:
+              - init-stack
+              - pg_isready
+              - -q
+          initialDelaySeconds: 10
+          timeoutSeconds: 5
+          failureThreshold: 3
+        {{- end }}
+        volumeMounts:
+        - name: database-data
+          mountPath: /data
+      - name: drycc-database-metrics
+        image: {{.Values.imageRegistry}}/{{.Values.imageOrg}}/database:{{.Values.imageTag}}
+        imagePullPolicy: {{.Values.imagePullPolicy}}
+        {{- if .Values.diagnosticMode.enabled }}
+        command: {{- include "common.tplvalues.render" (dict "value" .Values.diagnosticMode.command "context" $) | nindent 10 }}
+        args: {{- include "common.tplvalues.render" (dict "value" .Values.diagnosticMode.args "context" $) | nindent 10 }}
+        {{- else }}
+        command:
+        - init-stack
+        args:
+        - postgres_exporter
+        {{- end }}
+        ports:
+        - containerPort: 9187
+          protocol: TCP
+        env:
+        - name: DATA_SOURCE_URI
+          value: "127.0.0.1:5432/postgres?sslmode=disable"
+        - name: DATA_SOURCE_USER
+          valueFrom:
+            secretKeyRef:
+              name: database-creds
+              key: user
+        - name: DATA_SOURCE_PASS
+          valueFrom:
+            secretKeyRef:
+              name: database-creds
+              key: password
+        startupProbe:
+          initialDelaySeconds: 10
+          tcpSocket:
+              port: 9187
+          periodSeconds: 10
+          timeoutSeconds: 1
+          failureThreshold: 15
+          successThreshold: 1
+        livenessProbe:
+          initialDelaySeconds: 5
+          httpGet:
+            path: /
+            port: 9187
+          periodSeconds: 10
+          timeoutSeconds: 5
+          failureThreshold: 6
+          successThreshold: 1
+        readinessProbe:
+          initialDelaySeconds: 5
+          httpGet:
+            path: /
+            port: 9187
+          periodSeconds: 10
+          timeoutSeconds: 5
+          failureThreshold: 6
+          successThreshold: 1
+  {{- if .Values.persistence.enabled }}
+  volumeClaimTemplates:
+  - metadata:
+      name: database-data
+    spec:
+      accessModes: [ "ReadWriteOnce" ]
+      {{- if .Values.persistence.storageClass }}
+      {{- if (eq "-" .Values.persistence.storageClass) }}
+      storageClassName: ""
+      {{- else }}
+      storageClassName: "{{ .Values.persistence.storageClass }}"
+      {{- end }}
+      {{- end }}
+      resources:
+        requests:
+          storage: {{ .Values.persistence.size | quote }}
+  {{- else }}
+      volumes:
+      - name: database-data
+        emptyDir: {}
+  {{- end }}
diff --git a/charts/database/values.yaml b/charts/database/values.yaml
index ec2e51d..e856429 100644
--- a/charts/database/values.yaml
+++ b/charts/database/values.yaml
@@ -1,13 +1,94 @@
-image_org: "drycc"
-image_pull_policy: "Always"
-image_tag: "canary"
-image_registry: "docker.io"
-# limits_cpu: "100m"
-# limits_memory: "50Mi"
+imageOrg: "drycc"
+imagePullPolicy: "Always"
+imageTag: "canary"
+imageRegistry: "registry.drycc.cc"
+
+replicas: 3
+
+## Enable diagnostic mode
+##
+diagnosticMode:
+  ## @param diagnosticMode.enabled Enable diagnostic mode (all probes will be disabled and the command will be overridden)
+  ##
+  enabled: false
+  ## @param diagnosticMode.command Command to override all containers
+  ##
+  command:
+    - sleep
+  ## @param diagnosticMode.args Args to override all containers
+  ##
+  args:
+    - infinity
+
+resources: {}
+  # limits:
+  #   cpu: 200m
+  #   memory: 50Mi
+  # requests:
+  #   cpu: 100m
+  #   memory: 30Mi
+
+nodeAffinityPreset:
+  key: "drycc.cc/node"
+  type: "soft"
+  values:
+  - "true"
+
+podAffinityPreset:
+  type: ""
+  extraMatchLabels:
+    security: "drycc-security"
+
+podAntiAffinityPreset:
+  type: "soft"
+  extraMatchLabels:
+    app: "drycc-database"
+
+debug: "false"
+# Patroni pg_ctl timeout
 timeout: "1200"
+
+# The following parameters will no longer use the built-in storage component.
+storageBucket: "database"
+storageEndpoint: ""
+storageAccesskey: ""
+storageSecretkey: ""
+storagePathStyle: "true"
+
+storage:
+  enabled: true
+
+cronjob:
+  enabled: true
+  scheduleCronJob: "0 3 * * *"
+  retainBackupsAge: 30d
+
+# Service
+service:
+  # Provide any additional service annotations
+  annotations: {}
+# GCP PDs and EBS volumes are supported only
+persistence:
+  enabled: false # Set to true to enable persistence
+  size: 5Gi # PVC size
+  ## database data Persistent Volume Storage Class
+  ## If defined, storageClassName: <storageClass>
+  ## If set to "-", storageClassName: "", which disables dynamic provisioning
+  ## If undefined (the default) or set to null, no storageClassName spec is
+  ##   set, choosing the default provisioner.  (gp2 on AWS, standard on
+  ##   GKE, AWS & OpenStack)
+  ##
+  ## Storage class of PV to bind. By default it looks for standard storage class.
+  ## If the PV uses a different storage class, specify that here.
+  storageClass: ""
 # The username and password to be used by the on-cluster database.
-# If left empty they will be generated using randAlphaNum
-username: ""
+# If left empty they will be generated
+# The user name should be set to lowercase letters
+superuser: "postgres"
+superuserPassword: ""
+replicator: "standby"
+replicatorPassword: ""
+user: ""
 password: ""
-controller_database_name: "drycc_controller"
-passport_database_name: "drycc_passport"
+initDatabases: "controller,passport,grafana,quickwit"
+databaseExtensions: ""
diff --git a/contrib/ci/test-minio.sh b/contrib/ci/test-minio.sh
deleted file mode 100755
index 1d071c5..0000000
--- a/contrib/ci/test-minio.sh
+++ /dev/null
@@ -1,76 +0,0 @@
-#!/usr/bin/env bash
-
-set -eof pipefail
-
-cleanup() {
-  kill-containers "${MINIO_JOB}" "${PG_JOB}"
-}
-trap cleanup EXIT
-
-TEST_ROOT=$(dirname "${BASH_SOURCE[0]}")/
-# shellcheck source=/dev/null
-source "${TEST_ROOT}/test.sh"
-
-# make sure we are in this dir
-CURRENT_DIR=$(cd "$(dirname "$0")"; pwd)
-
-create-postgres-creds
-
-puts-step "creating fake minio credentials"
-
-mkdir -p "${CURRENT_DIR}"/tmp/aws-user
-echo "us-east-1" > "${CURRENT_DIR}"/tmp/aws-user/region
-echo "database-bucket" > "${CURRENT_DIR}"/tmp/aws-user/database-bucket
-echo "1234567890123456789012345678901234567890" > "${CURRENT_DIR}"/tmp/aws-user/accesskey
-echo "1234567890123456789012345678901234567890" > "${CURRENT_DIR}"/tmp/aws-user/secretkey
-
-# boot minio
-mkdir -p "${CURRENT_DIR}"/tmp/bin
-echo "ls /data/*/*/basebackups_005" > "${CURRENT_DIR}"/tmp/bin/backups.sh
-MINIO_JOB=$(docker run -d \
-  -v "${CURRENT_DIR}"/tmp/bin:/tmp/bin \
-  -v "${CURRENT_DIR}"/tmp/aws-user:/var/run/secrets/drycc/objectstore/creds \
-  drycc/minio:canary server /data/)
-
-
-puts-step "minio starting, wait 30s."
-sleep 30
-
-# boot postgres, linking the minio container and setting DRYCC_MINIO_SERVICE_HOST and DRYCC_MINIO_SERVICE_PORT
-MINIO_IP=$(docker inspect --format "{{ .NetworkSettings.IPAddress }}" "${MINIO_JOB}")
-PG_CMD="docker run -d --add-host minio:${MINIO_IP} -e PGCTLTIMEOUT=1200 \
-  -e BACKUP_FREQUENCY=1s -e DATABASE_STORAGE=minio \
-  -e DRYCC_MINIO_SERVICE_HOST=minio -e DRYCC_MINIO_SERVICE_PORT=9000 \
-  -v ${CURRENT_DIR}/tmp/creds:/var/run/secrets/drycc/database/creds \
-  -v ${CURRENT_DIR}/tmp/aws-user:/var/run/secrets/drycc/objectstore/creds $1"
-
-start-postgres "${PG_CMD}"
-
-# display logs for debugging purposes
-puts-step "displaying minio logs"
-docker logs "${MINIO_JOB}"
-
-check-postgres "${PG_JOB}"
-
-# check if minio has the 5 backups
-puts-step "checking if minio has 5 backups"
-BACKUPS="$(docker exec "${MINIO_JOB}" sh /tmp/bin/backups.sh | grep json)"
-NUM_BACKUPS="$(echo "${BACKUPS}" | wc -w)"
-# NOTE (bacongobbler): the BACKUP_FREQUENCY is only 1 second, so we could technically be checking
-# in the middle of a backup. Instead of failing, let's consider N+1 backups an acceptable case
-if [[ "${NUM_BACKUPS}" -lt "5" ]]; then
-  puts-error "the number of backups is less than 5 (found $NUM_BACKUPS)"
-  puts-error "${BACKUPS}"
-  exit 1
-fi
-
-# kill off postgres, then reboot and see if it's running after recovering from backups
-puts-step "shutting off postgres, then rebooting to test data recovery"
-kill-containers "${PG_JOB}"
-
-start-postgres "${PG_CMD}"
-
-check-postgres "${PG_JOB}"
-
-puts-step "tests PASSED!"
-exit 0
diff --git a/contrib/ci/test.sh b/contrib/ci/test.sh
deleted file mode 100755
index 963f1fb..0000000
--- a/contrib/ci/test.sh
+++ /dev/null
@@ -1,45 +0,0 @@
-#!/usr/bin/env bash
-
-set -eof pipefail
-
-puts-step() {
-  echo "-----> $*"
-}
-
-puts-error() {
-  echo "!!!    $*"
-}
-
-kill-containers() {
-	puts-step "destroying containers $*"
-	docker rm -f "$@"
-}
-
-create-postgres-creds() {
-  puts-step "creating fake postgres credentials"
-
-  # create fake postgres credentials
-  mkdir -p "${CURRENT_DIR}"/tmp/creds
-  echo "testuser" > "${CURRENT_DIR}"/tmp/creds/user
-  echo "icanttellyou" > "${CURRENT_DIR}"/tmp/creds/password
-  echo "drycc_controller" > "${CURRENT_DIR}"/tmp/creds/controller-database-name
-  echo "drycc_passport" > "${CURRENT_DIR}"/tmp/creds/passport-database-name
-}
-
-start-postgres() {
-  export PG_JOB
-  PG_JOB=$($1)
-  # wait for postgres to boot
-  puts-step "sleeping for 30s while postgres is booting..."
-  sleep 30s
-}
-
-check-postgres() {
-  # display logs for debugging purposes
-  puts-step "displaying postgres logs"
-  docker logs "$1"
-
-  # check if postgres is running
-  puts-step "checking if postgres is running"
-  docker exec "$1" is_running
-}
diff --git a/rootfs/bin/backup b/rootfs/bin/backup
deleted file mode 100755
index a56f52e..0000000
--- a/rootfs/bin/backup
+++ /dev/null
@@ -1,8 +0,0 @@
-#!/usr/bin/env bash
-
-export BACKUP_FREQUENCY=${BACKUP_FREQUENCY:-4h}
-
-while true; do
-    sleep "$BACKUP_FREQUENCY"
-    do_backup
-done
diff --git a/rootfs/bin/create_bucket b/rootfs/bin/create_bucket
deleted file mode 100755
index 196a744..0000000
--- a/rootfs/bin/create_bucket
+++ /dev/null
@@ -1,19 +0,0 @@
-#!/usr/bin/env bash
-
-set -e
-
-# shellcheck disable=SC1091
-source /bin/normalize_storage
-
-has_bucket(){
-    mc ls minio -json|jq -r '.key'|grep -w "${MINIO_BUCKET}"
-}
-
-if  [ -z "$(has_bucket)" ] ;then
-    mc mb minio/"${MINIO_BUCKET}"
-    if  [ -z "$(has_bucket)" ] ;then
-        echo "create bucket ${MINIO_BUCKET} error"
-        exit 1
-    fi
-fi
-echo "create bucket ${MINIO_BUCKET} success"
diff --git a/rootfs/bin/do_backup b/rootfs/bin/do_backup
deleted file mode 100755
index dfe8766..0000000
--- a/rootfs/bin/do_backup
+++ /dev/null
@@ -1,15 +0,0 @@
-#!/usr/bin/env bash
-
-export BACKUPS_TO_RETAIN=${BACKUPS_TO_RETAIN:-5}
-
-echo "Performing a base backup..."
-if [[ -f "$PGDATA/recovery.signal" ]] ; then
-    echo "Database is currently recovering from a backup. Aborting"
-    sleep 9
-else
-    # perform a backup
-    envdir "$WALG_ENVDIR" wal-g backup-push "$PGDATA"
-    # only retain the latest BACKUPS_TO_RETAIN backups
-    envdir "$WALG_ENVDIR" wal-g delete --confirm retain "$BACKUPS_TO_RETAIN"
-    echo "Backup has been completed."
-fi
diff --git a/rootfs/bin/is_running b/rootfs/bin/is_running
deleted file mode 100755
index 0286977..0000000
--- a/rootfs/bin/is_running
+++ /dev/null
@@ -1,11 +0,0 @@
-#!/bin/bash
-
-# fail fast
-set -e
-
-if [[ -f "$PGDATA/recovery.signal" ]]; then
-  # postgres is in recovery mode, so we know it's not ready to accept incoming connections.
-  exit 1
-fi
-
-gosu postgres pg_ctl status
diff --git a/rootfs/bin/normalize_storage b/rootfs/bin/normalize_storage
deleted file mode 100755
index 62b81ec..0000000
--- a/rootfs/bin/normalize_storage
+++ /dev/null
@@ -1,21 +0,0 @@
-#!/usr/bin/env sh
-BUCKET_FILE="/var/run/secrets/drycc/objectstore/creds/database-bucket"
-ACCESS_KEY_FILE="/var/run/secrets/drycc/objectstore/creds/accesskey"
-SECRET_KEY_FILE="/var/run/secrets/drycc/objectstore/creds/secretkey"
-
-if [ -f $BUCKET_FILE ]; then
-  MINIO_BUCKET=$(cat "$BUCKET_FILE")
-  export MINIO_BUCKET
-fi
-if [ -f $ACCESS_KEY_FILE ]; then
-  MINIO_ACCESS_KEY=$(cat "$ACCESS_KEY_FILE")
-  export MINIO_ACCESS_KEY
-fi
-if [ -f $SECRET_KEY_FILE ]; then
-  MINIO_SECRET_KEY=$(cat "$SECRET_KEY_FILE")
-  export MINIO_SECRET_KEY
-fi
-
-export MINIO_ENDPOINT=http://"${DRYCC_MINIO_SERVICE_HOST}:${DRYCC_MINIO_SERVICE_PORT}"
-
-mc config host add minio "${MINIO_ENDPOINT}" "${MINIO_ACCESS_KEY}" "${MINIO_SECRET_KEY}"
diff --git a/rootfs/docker-entrypoint-initdb.d/001_setup_envdir.sh b/rootfs/docker-entrypoint-initdb.d/001_setup_envdir.sh
deleted file mode 100755
index 096818c..0000000
--- a/rootfs/docker-entrypoint-initdb.d/001_setup_envdir.sh
+++ /dev/null
@@ -1,15 +0,0 @@
-#!/usr/bin/env bash
-
-cd "$WALG_ENVDIR"
-
-AWS_ACCESS_KEY_ID=$(cat /var/run/secrets/drycc/objectstore/creds/accesskey)
-AWS_SECRET_ACCESS_KEY=$(cat /var/run/secrets/drycc/objectstore/creds/secretkey)
-BUCKET_NAME=$(cat /var/run/secrets/drycc/objectstore/creds/database-bucket)
-
-echo $AWS_ACCESS_KEY_ID > AWS_ACCESS_KEY_ID
-echo $AWS_SECRET_ACCESS_KEY > AWS_SECRET_ACCESS_KEY
-echo "s3://$BUCKET_NAME/$PG_MAJOR" > WALE_S3_PREFIX
-echo "http://$DRYCC_MINIO_SERVICE_HOST:$DRYCC_MINIO_SERVICE_PORT" > AWS_ENDPOINT
-echo "true" > AWS_S3_FORCE_PATH_STYLE
-echo $AWS_REGION > S3_REGION
-echo $BUCKET_NAME > BUCKET_NAME
diff --git a/rootfs/docker-entrypoint-initdb.d/002_create_bucket.sh b/rootfs/docker-entrypoint-initdb.d/002_create_bucket.sh
deleted file mode 100755
index 316af45..0000000
--- a/rootfs/docker-entrypoint-initdb.d/002_create_bucket.sh
+++ /dev/null
@@ -1,4 +0,0 @@
-#!/usr/bin/env bash
-
-# ensure WAL log bucket exists
-envdir "$WALG_ENVDIR" create_bucket
diff --git a/rootfs/docker-entrypoint-initdb.d/003_restore_from_backup.sh b/rootfs/docker-entrypoint-initdb.d/003_restore_from_backup.sh
deleted file mode 100755
index 6caedc5..0000000
--- a/rootfs/docker-entrypoint-initdb.d/003_restore_from_backup.sh
+++ /dev/null
@@ -1,69 +0,0 @@
-#!/usr/bin/env bash
-
-# check if there are any backups -- if so, let's restore
-# we could probably do better than just testing number of lines -- one line is just a heading, meaning no backups
-
-if [[ $(envdir "$WALG_ENVDIR" wal-g backup-list | wc -l) -gt "1" ]]; then
-  echo "Found backups. Restoring from backup..."
-  {
-    gosu postgres pg_ctl -D "$PGDATA" -w stop > /dev/null 2>&1
-  } || {
-    echo "ignore script errors"
-  }
-  rm -rf "$PGDATA"
-  envdir "$WALG_ENVDIR" wal-g backup-fetch "$PGDATA" LATEST
-  touch "$PGDATA/recovery.signal"
-  cat << EOF > "$PGDATA/postgresql.conf"
-# These settings are initialized by initdb, but they can be changed.
-log_timezone = 'UTC'
-lc_messages = 'C'     # locale for system error message
-lc_monetary = 'C'     # locale for monetary formatting
-lc_numeric = 'C'      # locale for number formatting
-lc_time = 'C'       # locale for time formatting
-default_text_search_config = 'pg_catalog.english'
-wal_level = archive
-archive_mode = on
-archive_command = 'envdir "${WALG_ENVDIR}" wal-g wal-push %p'
-archive_timeout = 60
-listen_addresses = '*'
-max_connections = 1024
-restore_command = 'envdir "${WALG_ENVDIR}" wal-g wal-fetch \"%f\" \"%p\"'
-EOF
-  cat << EOF > "$PGDATA/pg_hba.conf"
-# "local" is for Unix domain socket connections only
-local   all             all                                     trust
-# IPv4 local connections:
-host    all             all             127.0.0.1/32            trust
-# IPv6 local connections:
-host    all             all             ::1/128                 trust
-# IPv4 global connections
-host    all             all             0.0.0.0/0               md5
-EOF
-  touch "$PGDATA/pg_ident.conf"
-  touch "$PGDATA/recovery.signal"
-  chown -R postgres:postgres "$PGDATA"
-  chmod 0700 "$PGDATA"
-  gosu postgres pg_ctl -D "$PGDATA" \
-      -o "-c listen_addresses=''" \
-      -w start
-else
-  cat << EOF >> "$PGDATA/postgresql.conf"
-wal_level = archive
-archive_mode = on
-archive_command = 'envdir "${WALG_ENVDIR}" wal-g wal-push %p'
-archive_timeout = 60
-max_connections = 1024
-EOF
-
-  # ensure $PGDATA has the right permissions
-  chown -R postgres:postgres "$PGDATA"
-  chmod 0700 "$PGDATA"
-
-  # reboot the server for wal_level to be set before backing up
-  echo "Rebooting postgres to enable archive mode"
-  gosu postgres pg_ctl -D "$PGDATA" -w restart
-fi
-
-# ensure $PGDATA has the right permissions
-chown -R postgres:postgres "$PGDATA"
-chmod 0700 "$PGDATA"
diff --git a/rootfs/docker-entrypoint-initdb.d/004_run_backups.sh b/rootfs/docker-entrypoint-initdb.d/004_run_backups.sh
deleted file mode 100755
index d311bd4..0000000
--- a/rootfs/docker-entrypoint-initdb.d/004_run_backups.sh
+++ /dev/null
@@ -1,4 +0,0 @@
-#!/usr/bin/env bash
-
-# Run periodic backups in the background
-gosu postgres backup &
diff --git a/rootfs/docker-entrypoint.sh b/rootfs/docker-entrypoint.sh
deleted file mode 100755
index b9fcf28..0000000
--- a/rootfs/docker-entrypoint.sh
+++ /dev/null
@@ -1,116 +0,0 @@
-#!/bin/bash
-#
-# Originally copied and modified from
-# https://github.com/docker-library/postgres/blob/ec5ce80ca914e02c2d5eb9fde424039d4cee032e/9.4/docker-entrypoint.sh
-#
-set -e
-
-set_listen_addresses() {
-	sedEscapedValue="$(echo "$1" | sed 's/[\/&]/\\&/g')"
-	sed -ri "s/^#?(listen_addresses\s*=\s*)\S+/\1'$sedEscapedValue'/" "$PGDATA/postgresql.conf"
-}
-
-POSTGRES_USER="$(cat /var/run/secrets/drycc/database/creds/user)"
-POSTGRES_PASSWORD="$(cat /var/run/secrets/drycc/database/creds/password)"
-POSTGRES_CONTROLLER="$(cat /var/run/secrets/drycc/database/creds/controller-database-name)"
-POSTGRES_PASSPORT="$(cat /var/run/secrets/drycc/database/creds/passport-database-name)"
-
-if [ "$1" = 'postgres' ]; then
-	mkdir -p "$PGDATA"
-	chmod 700 "$PGDATA"
-	chown -R postgres "$PGDATA"
-
-	chmod g+s /run/postgresql
-	chown -R postgres /run/postgresql
-
-	# look specifically for PG_VERSION, as it is expected in the DB dir
-	if [ ! -s "$PGDATA/PG_VERSION" ]; then
-		gosu postgres initdb
-
-		# check password first so we can output the warning before postgres
-		# messes it up
-		if [ "$POSTGRES_PASSWORD" ]; then
-			pass="PASSWORD '$POSTGRES_PASSWORD'"
-			authMethod=md5
-		else
-			# The - option suppresses leading tabs but *not* spaces. :)
-			cat >&2 <<-'EOWARN'
-				****************************************************
-				WARNING: No password has been set for the database.
-				         This will allow anyone with access to the
-				         Postgres port to access your database. In
-				         Docker's default configuration, this is
-				         effectively any other container on the same
-				         system.
-
-				         Use "-e POSTGRES_PASSWORD=password" to set
-				         it in "docker run".
-				****************************************************
-			EOWARN
-
-			pass=
-			authMethod=trust
-		fi
-
-		{ echo; echo "host all all 0.0.0.0/0 $authMethod"; } >> "$PGDATA/pg_hba.conf"
-
-		# internal start of server in order to allow set-up using psql-client
-		# does not listen on TCP/IP and waits until start finishes
-		gosu postgres pg_ctl -D "$PGDATA" \
-			-o "-c listen_addresses=''" \
-			-w start
-
-		: ${POSTGRES_USER:=postgres}
-		export POSTGRES_USER
-
-		if [ "$POSTGRES_CONTROLLER" != '' ]; then
-			psql --username postgres <<-EOSQL
-				CREATE DATABASE "$POSTGRES_CONTROLLER" ;
-			EOSQL
-			echo
-		fi
-
-		if [ "$POSTGRES_PASSPORT" != '' ]; then
-			psql --username postgres <<-EOSQL
-				CREATE DATABASE "$POSTGRES_PASSPORT" ;
-			EOSQL
-			echo
-		fi
-
-		if [ "$POSTGRES_USER" = 'postgres' ]; then
-			op='ALTER'
-		else
-			op='CREATE'
-		fi
-
-		psql --username postgres <<-EOSQL
-			$op USER "$POSTGRES_USER" WITH SUPERUSER $pass ;
-		EOSQL
-		echo
-
-		echo
-		for f in /docker-entrypoint-initdb.d/*; do
-			case "$f" in
-				*.sh)  echo "$0: running $f"; . "$f" ;;
-				*.sql)
-					echo "$0: running $f";
-					psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" < "$f"
-					echo
-					;;
-				*)     echo "$0: ignoring $f" ;;
-			esac
-			echo
-		done
-
-		gosu postgres pg_ctl -D "$PGDATA" -m fast -w stop
-		set_listen_addresses '*'
-
-		echo
-		echo 'PostgreSQL init process complete; ready for start up.'
-		echo
-	fi
-
-	exec gosu postgres "$@"
-fi
-
-exec "$@"
diff --git a/rootfs/entrypoint.sh b/rootfs/entrypoint.sh
new file mode 100755
index 0000000..8865438
--- /dev/null
+++ b/rootfs/entrypoint.sh
@@ -0,0 +1,68 @@
+#!/bin/bash
+if [[ $UID -ge 10000 ]]; then
+    GID=$(id -g)
+    sed -e "s/^postgres:x:[^:]*:[^:]*:/postgres:x:$UID:$GID:/" /etc/passwd > /tmp/passwd
+    cat /tmp/passwd > /etc/passwd
+    rm /tmp/passwd
+fi
+
+cat > /data/patroni.yaml <<__EOF__
+bootstrap:
+  dcs:
+    ttl: 30
+    loop_wait: 10
+    retry_timeout: 10
+    maximum_lag_on_failover: 1048576
+    failsafe_mode: true
+    postgresql:
+      use_pg_rewind: true
+      use_slots: true
+  initdb:
+  - auth-host: scram-sha-256
+  - auth-local: trust
+  - encoding: UTF8
+  - locale: ${LANG}
+  - data-checksums
+  pg_hba:
+  - host all all 0.0.0.0/0 scram-sha-256
+  - host replication ${DRYCC_DATABASE_REPLICATOR} ${PATRONI_KUBERNETES_POD_IP}/16 scram-sha-256
+  post_bootstrap: /usr/share/scripts/patroni/post_init.sh
+restapi:
+  connect_address: '${PATRONI_KUBERNETES_POD_IP}:8008'
+postgresql:
+  data_dir: '${PGDATA}'
+  parameters:
+    shared_preload_libraries: 'auto_explain,pg_stat_statements'
+    hot_standby: "on"
+    max_connections: 1005
+    max_worker_processes: 8
+    max_wal_senders: 10
+    max_replication_slots: 10
+    hot_standby_feedback: on
+    max_prepared_transactions: 0
+    max_locks_per_transaction: 64
+    wal_log_hints: "on"
+    wal_level: logical
+    track_commit_timestamp: "off"
+    archive_mode: "on"
+    archive_timeout: 300s
+    archive_command: "/bin/true"
+    log_min_duration_statement: 1000
+    log_lock_waits: on
+    log_statement: 'ddl' 
+    jit: off
+  connect_address: '${PATRONI_KUBERNETES_POD_IP}:5432'
+  authentication:
+    superuser:
+      username: '${DRYCC_DATABASE_SUPERUSER}'
+      password: '${DRYCC_DATABASE_SUPERUSER_PASSWORD}'
+    replication:
+      username: '${DRYCC_DATABASE_REPLICATOR}'
+      password: '${DRYCC_DATABASE_REPLICATOR_PASSWORD}'
+watchdog:
+  mode: off
+__EOF__
+
+unset DRYCC_DATABASE_SUPERUSER_PASSWORD DRYCC_DATABASE_REPLICATION_PASSWORD
+
+exec patroni /data/patroni.yaml
diff --git a/rootfs/usr/share/scripts/backup.sh b/rootfs/usr/share/scripts/backup.sh
new file mode 100755
index 0000000..441c33e
--- /dev/null
+++ b/rootfs/usr/share/scripts/backup.sh
@@ -0,0 +1,66 @@
+#!/bin/bash
+set -e
+
+# Setup Rclone 
+/usr/share/scripts/create_bucket
+
+# Backup PostgreSQL databases to S3-compatible object storage
+export PGPASSWORD=$DRYCC_DATABASE_SUPERUSER_PASSWORD
+PGPORT=$DRYCC_DATABASE_REPLICA_SERVICE_PORT_POSTGRES
+PGUSER=postgres
+POSTGRES_HOST=$DRYCC_DATABASE_REPLICA_SERVICE_HOST
+RETAIN_BACKUPS_AGE=$RETAIN_BACKUPS_AGE
+
+# PostgreSQL global objects backup 
+BACKUP_PATH="${DRYCC_STORAGE_BUCKET}/$(date +%Y%m%d%H%M)"
+echo "DB: ${POSTGRES_USER}@${POSTGRES_HOST}"
+echo "S3 Storage: storage:${BACKUP_PATH}"
+# Backup global objects
+if pg_dumpall -g -U "${POSTGRES_USER}" -h "${POSTGRES_HOST}" \
+  | pigz -c -p 4 -6 \
+  | rclone rcat \
+      "storage:${BACKUP_PATH}/roles_globals.sql.gz" \
+      --bwlimit 10M \
+      --transfers 4 \
+      --s3-chunk-size 64M \
+      --stats 5s \
+      --progress \
+      --retries 3; then  
+  echo "✅ PostgreSQL global objects backup complated!" 
+fi 
+  # fetch the list of databases
+  DATABASES=$(psql -U "$POSTGRES_USER" -h "$POSTGRES_HOST" -t -c "SELECT datname FROM pg_database WHERE datistemplate = false;")
+
+  # backup each database individually
+  for DB in $DATABASES; do
+    echo "Backing up $DB to $MINIO_PATH/$DB.sql.gz"
+    if pg_dump -U "${POSTGRES_USER}" -h "${POSTGRES_HOST}" "$DB" \
+        | pigz -c -p 4 -6 \
+        | rclone rcat \
+            "storage:${BACKUP_PATH}/$DB.sql.gz" \
+            --bwlimit 10M \
+            --transfers 4 \
+            --s3-chunk-size 64M \
+            --stats 5s \
+            --progress \
+            --retries 3; then
+        echo "✅ PostgreSQL $DB global objects backup completed!"
+    fi
+  done
+
+  echo "Backup process completed!"
+
+  echo "delete storage before ${RETAIN_BACKUPS_AGE} ..."
+  rclone delete "storage:${DRYCC_STORAGE_BUCKET}" \
+    --min-age ${RETAIN_BACKUPS_AGE} \
+    --include "*.sql.gz" \
+    --dry-run \
+    -v  || true
+
+  rclone delete "storage:${DRYCC_STORAGE_BUCKET}" \
+    --min-age ${RETAIN_BACKUPS_AGE} \
+    --include "*.sql.gz" \
+    || true
+  echo "delete completed."
+
+echo "=== backup completed: $(date) ==="
diff --git a/rootfs/usr/share/scripts/create_bucket b/rootfs/usr/share/scripts/create_bucket
new file mode 100755
index 0000000..addadaa
--- /dev/null
+++ b/rootfs/usr/share/scripts/create_bucket
@@ -0,0 +1,19 @@
+#!/usr/bin/env bash
+
+set -e
+
+mkdir -p ~/.config/rclone
+touch ~/.config/rclone/rclone.conf
+rclone config create storage s3 \
+  provider=Other \
+  access_key_id="${DRYCC_STORAGE_ACCESSKEY}" \
+  secret_access_key="${DRYCC_STORAGE_SECRETKEY}" \
+  endpoint="${DRYCC_STORAGE_ENDPOINT}" \
+  force_path_style="${DRYCC_STORAGE_PATH_STYLE:-true}" --no-output
+
+if ! rclone lsd storage: > /dev/null 2>&1; then
+  sleep 9s
+  echo "waiting for object storage to become ready..."
+fi
+
+rclone mkdir "storage:${DRYCC_STORAGE_BUCKET}"
diff --git a/rootfs/usr/share/scripts/patroni/post_init.sh b/rootfs/usr/share/scripts/patroni/post_init.sh
new file mode 100755
index 0000000..a8f75f5
--- /dev/null
+++ b/rootfs/usr/share/scripts/patroni/post_init.sh
@@ -0,0 +1,24 @@
+#!/usr/bin/env bash
+set -Eeu
+
+if [[ ( -n "$DRYCC_DATABASE_USER") &&  ( -n "$DRYCC_DATABASE_PASSWORD")]]; then
+  echo "Creating user ${DRYCC_DATABASE_USER}"
+  psql "$1" -w -c "create user ${DRYCC_DATABASE_USER} WITH LOGIN ENCRYPTED PASSWORD '${DRYCC_DATABASE_PASSWORD}'"
+  psql "$1" -w -c "GRANT pg_monitor TO ${DRYCC_DATABASE_USER}"
+  for dbname in ${DRYCC_DATABASE_INIT_NAMES//,/ }
+  do
+    echo "Creating database ${dbname}"
+    psql "$1" -w -c "CREATE DATABASE ${dbname} OWNER ${DRYCC_DATABASE_USER}"
+    for extension in ${DRYCC_DATABASE_EXTENSIONS//,/ }
+    do
+      echo "Creating extension ${extension}"
+      psql "$1" -w << EOF
+\c ${dbname};
+create extension ${extension};
+EOF
+    done
+  done
+else
+  echo "Skipping user creation"
+  echo "Skipping database creation"
+fi
diff --git a/versioning.mk b/versioning.mk
index fd4a488..10e3d7b 100644
--- a/versioning.mk
+++ b/versioning.mk
@@ -10,13 +10,13 @@ info:
 	@echo "Immutable tag:   ${IMAGE}"
 	@echo "Mutable tag:     ${MUTABLE_IMAGE}"
 
-.PHONY: docker-push
-docker-push: docker-immutable-push docker-mutable-push
+.PHONY: podman-push
+podman-push: podman-immutable-push podman-mutable-push
 
-.PHONY: docker-immutable-push
-docker-immutable-push:
-	docker push ${IMAGE}
+.PHONY: podman-immutable-push
+podman-immutable-push:
+	podman push ${IMAGE}
 
-.PHONY: docker-mutable-push
-docker-mutable-push:
-	docker push ${MUTABLE_IMAGE}
+.PHONY: podman-mutable-push
+podman-mutable-push:
+	podman push ${MUTABLE_IMAGE}
