PostgreSQL: 4. Create the service

This documentation is part of the Automate with the CLI guide. View the full guide here: Start PostgreSQL, retrieve its credentials, and change its configuration programmatically with the Stackhero CLI.

👋 Welcome to the Stackhero documentation!

Stackhero provides a fully managed PostgreSQL cloud service, designed for reliability and speed:

  • Unlimited connections and data transfers for seamless scaling.
  • PgAdmin web UI included for intuitive database management.
  • Popular extensions included, such as PostGIS, TimescaleDB, and PgVector.
  • Simple, one-click updates keep your database secure and current.
  • High performance and strong security on private, dedicated infrastructure.

You can get started with Stackhero's PostgreSQL cloud hosting in just a few minutes. Enjoy a reliable database experience and save valuable time managing your data.

Here is a sample script that creates a stack, adds your PostgreSQL service to it, waits for it to start, retrieves its configuration (including generated credentials), and then applies a new configuration.

#!/bin/bash
set -e

export STACKHERO_TOKEN="usr-xxxxxx:your-token"

serviceStore="postgresql"   # The PostgreSQL service store name (see step 2)
instance="..."                # An instance size from step 3
region="europe"               # A region name from step 3

# Create a stack for your service (uses your default organization; add --organization if needed)
stackId=$(stackhero --format=script stack-create \
  --name="My PostgreSQL stack")
echo "Stack created: ${stackId}"

# Add PostgreSQL to the stack (names are resolved automatically)
serviceId=$(stackhero --format=script service-add \
  --stack="My PostgreSQL stack" \
  --service-store="${serviceStore}" \
  --instance="${instance}" \
  --region="${region}")
echo "Service added: postgresql"

# Wait for the service to be fully running (this may take a couple of minutes)
stackhero service-wait-for --service="postgresql"

# Retrieve the service configuration, including generated credentials
stackhero service-configuration-get --service="postgresql" --format=json