Skip to content

PostgreSQL

This content is not available in your language yet.

This guide demonstrates how to deploy PostgreSQL to your applications using a Helm chart from Artifact Hub.

Ensure you have the following tools installed:

  • Helm: Installation Guide
  • Access to Registry URL: Obtain this from the Commands button on the Repositories page or Applications Services page
  1. Download the PostgreSQL Helm chart from Artifact Hub:

    Terminal window
    helm pull oci://registry-1.docker.io/bitnamicharts/postgresql --version 18.2.0

    This command downloads postgresql-18.2.0.tgz to your local directory.

  2. Upload the chart to your private registry:

    Terminal window
    helm push postgresql-18.2.0.tgz oci://<registry_url>/postgres --plain-http

    Replace <registry_url> with your actual registry URL (e.g., 192.168.196.42:5736).

    Example:

    Terminal window
    helm push postgresql-18.2.0.tgz oci://192.168.196.42:5736/postgres --plain-http
  3. After uploading, navigate to the Applications Store to deploy the Helm chart.

    To allow external connections and configure storage, adjust the deployment settings:

    service:
    type: NodePort
    port: 5432
    nodePort: 30432 # Port range: 30000-32767
    primary:
    persistence:
    size: 10Gi # PVC Storage Request for PostgreSQL volume (e.g., 10Gi, 20Gi, 100Gi)

    Configuration Details:

    • service.type: Set to NodePort to allow external connections
    • service.port: PostgreSQL service port (default: 5432)
    • service.nodePort: External port accessible from outside the cluster
    • primary.persistence.size: Storage size for the PostgreSQL data volume (adjust based on your needs)

    After deployment, you can connect externally using <node_ip>:<nodePort>.

  4. Retrieve the PostgreSQL password from Applications Secrets:

    • Navigate to the Applications Secrets page
    • Adjust the namespace filter in the top-right corner to select your namespace
    • Click on the postgres-related secret entry
    • Copy the password and decode it using base64:
      Terminal window
      echo "<copied_password>" | base64 --decode
      Or use this online tool: base64decode.org
    • Use the decoded password for your PostgreSQL connections

You can verify your PostgreSQL deployment by using Python to perform read and write operations.

Before running the test scripts, you’ll need:

  • Host: PostgreSQL service endpoint
  • Port: Database port (default: 5432)
  • Database: Database name (default: postgres)
  • User: Username (default: postgres)
  • Password: Database password
import psycopg2
try:
connection = psycopg2.connect(
host="<postgres_host>",
port=5432,
database="postgres",
user="postgres",
password="<password>"
)
cursor = connection.cursor()
cursor.execute("SELECT version();")
version = cursor.fetchone()
print("PostgreSQL version:", version)
cursor.close()
connection.close()
print("✓ Connection successful!")
except Exception as e:
print("✗ Connection failed:", str(e))