Create a PostgreSQL instance

Create a PostgreSQL instance with its first database and an admin user.

POST https://{availability_zone}.betterstackcloud.com/v1/postgres
Authorization string required

Bearer $TOKEN

Content-Type string

application/json

name string required

The instance's name, at most 255 characters. Must be unique among your organization's PostgreSQL instances that aren't destroyed or failed.

type string required

The instance's type, such as PG1, which sets its size. Get the types via List PostgreSQL types. To change it later, rescale the instance.

team_id string required

The ID of the team that owns the instance. Get the team ID via List teams. Can't be changed after the instance is created.

engine_version string

The PostgreSQL major version, such as 19. Get the versions via List PostgreSQL versions. Defaults to the newest version we offer. To change it later, upgrade the instance.

statement_timeout integer default: 0

How long a statement can run before PostgreSQL cancels it, in milliseconds, from 0 to 3600000. Set it to 0 for no limit.

idle_in_transaction_session_timeout integer default: 0

How long a session can stay idle inside a transaction before PostgreSQL ends it, in milliseconds, from 0 to 86400000. Set it to 0 for no limit.

work_mem_mb integer default: 4

The memory each sort or hash operation can use, in MiB, from 1 to 256.

log_min_duration_statement integer default: -1

How long a statement must run before PostgreSQL logs it, in milliseconds, from -1 to 600000. Set it to -1 to log none.

public_access boolean default: false

Whether clients can also connect to the instance from the internet. Connections use TLS.

replica_count integer default: 0

How many read replicas the instance has, from 0 to 2.

database string default: defaultdb

The name of the instance's first database. Defaults to defaultdb.

network_ids array of strings

The IDs of the private networks attached to every node. Each network must be in the instance's team. To change them later, use Attach a network to a PostgreSQL instance and Detach a network from a PostgreSQL instance. Order doesn't matter.

firewall_ids array of strings

The ID of the firewall attached to every node. An instance can have at most one firewall. To change it later, use Attach a firewall to a PostgreSQL instance and Detach a firewall from a PostgreSQL instance. Order doesn't matter.

term string default: monthly

The billing term.
Valid values:
monthly: Billed each month.
annual: Paid for a year at a time.

metadata object

Your own tags, as string keys and values. At most 10. Accepts any keys.

202

Returns the newly created PostgreSQL instance.

202 Accepted
{
  "id": "example",
  "name": "Example PostgreSQL instance",
  "type": "PG1",
  "usable_storage_gb": 1,
  "max_connections": 1,
  "max_pooled_connections": 1,
  "engine_version": "1.4.2",
  "engine_patch_version": "1.4.2",
  "available_engine_versions": [
    "1.4.2"
  ],
  "status": "provisioning",
  "status_message": "example",
  "statement_timeout": 0,
  "idle_in_transaction_session_timeout": 0,
  "work_mem_mb": 4,
  "log_min_duration_statement": -1,
  "public_access": false,
  "replica_count": 0,
  "read_only": false,
  "endpoint": {
    "hostname": "proxy.example.com",
    "public_hostname": "proxy.example.com",
    "port": 443,
    "pooled_port": 443,
    "private_ips": [
      {
        "network_id": "123456789",
        "ip_address": "example"
      }
    ],
    "public_ips": [
      {
        "ip": "example",
        "type": "example"
      }
    ]
  },
  "members": [
    {
      "id": "example",
      "role": "primary",
      "status": "provisioning",
      "replication_lag_seconds": 1.5,
      "disk_used_bytes": 1,
      "private_ips": [
        {
          "network_id": "123456789",
          "ip_address": "example"
        }
      ],
      "created_at": "2026-07-01T12:00:00.000Z"
    }
  ],
  "databases": [
    "example"
  ],
  "users": [
    {
      "id": "example",
      "username": "example",
      "default_user": false,
      "privileges": {
        "key": "value"
      },
      "created_at": "2026-07-01T12:00:00.000Z"
    }
  ],
  "network_ids": [
    "123456789"
  ],
  "firewall_ids": [
    "123456789"
  ],
  "latest_snapshot_at": "2026-07-01T12:00:00.000Z",
  "term": "monthly",
  "created_at": "2026-07-01T12:00:00.000Z",
  "updated_at": "2026-07-01T12:00:00.000Z",
  "team_id": "t123",
  "metadata": {
    "example": "value"
  }
}
400

The body isn't valid JSON.

400 Bad Request
{
  "error": {
    "message": "Malformed JSON body.",
    "code": "bad_request"
  }
}
401

The API token is missing or invalid.

401 Unauthorized
{
  "error": {
    "message": "Missing or invalid token.",
    "code": "unauthorized"
  }
}
402

Your organization hasn't made its first payment yet, with the code payment_required. The error can also have first_purchase, with the url of a page where you make the payment. Paying creates the PostgreSQL instance. The page works until expires_at, 24 hours after the response.

403

Your organization has reached its limit of PostgreSQL instances, with the code quota_exceeded.

404

The team, type, network or firewall doesn't exist.

409

The zone has no capacity, with the code no_capacity.

422

A value isn't valid, with the code validation_failed. The error's details list the messages for each field.

423

We've locked the resource, with the code locked. Every change to a locked resource is refused, and so is a change that involves one.

429

Too many requests, with the code rate_limited. We limit requests per client IP and per organization, and some costly endpoints have a stricter limit. Wait as long as the Retry-After header says.

500

An unexpected, temporary error on our side, with the code internal_error. Try again.

500 Internal Server Error
{
  "error": {
    "message": "The request could not be completed right now. Please try again in a few moments.",
    "code": "internal_error"
  }
}
503

Another PostgreSQL action is running in your organization at the same time, with the code concurrent_create_limit. Or we couldn't set up the instance, with the code orchestration_failed. Try again shortly.

id string

The instance's ID, a UUID.

name string

The instance's name, at most 255 characters.

type string

The instance's type, such as PG1, which sets its size. Get the types via List PostgreSQL types.

usable_storage_gb integer

The disk space for your data, in GiB.

max_connections integer

How many clients can connect straight to PostgreSQL at once, without going through PgBouncer.

max_pooled_connections integer

How many clients can connect through PgBouncer at once.

engine_version string

The PostgreSQL major version, such as 19. Get the versions via List PostgreSQL versions.

engine_patch_version string or null

The exact PostgreSQL version the instance runs, such as 19.0, or null until we know it.

available_engine_versions array of strings

The major versions you can upgrade the instance to. An upgrade can't be undone.

status string

The instance's status. After you create or restore an instance, get it until its status is running. A failed or destroyed instance stays that way.
Valid values:
provisioning: We're setting up the instance.
running: The instance is ready.
degraded: A node is down, replication is broken or the disk is nearly full. status_message says which.
rescaling: We're changing the instance's type.
upgrading: We're upgrading PostgreSQL to a new major version.
restoring: We're restoring the instance from a snapshot.
failed: Setting up the instance failed. status_message says why.
destroyed: The instance is deleted.

status_message string or null

More about the status, such as why the instance failed or is degraded, that a replica is being rebuilt, or that an action didn't finish.

statement_timeout integer

How long a statement can run before PostgreSQL cancels it, in milliseconds, from 0 to 3600000. Set it to 0 for no limit.

idle_in_transaction_session_timeout integer

How long a session can stay idle inside a transaction before PostgreSQL ends it, in milliseconds, from 0 to 86400000. Set it to 0 for no limit.

work_mem_mb integer

The memory each sort or hash operation can use, in MiB, from 1 to 256.

log_min_duration_statement integer

How long a statement must run before PostgreSQL logs it, in milliseconds, from -1 to 600000. Set it to -1 to log none.

public_access boolean

Whether clients can also connect to the instance from the internet. Connections use TLS.

replica_count integer

How many read replicas the instance has, from 0 to 2.

read_only boolean

Whether the instance accepts only reads because its disk is nearly full.

endpoint object

Where to connect to the instance. Connect straight to PostgreSQL on port, or through PgBouncer on pooled_port.

endpoint.hostname string

The hostname to connect to from your private networks. Resolves to the primary's addresses in your private networks.

endpoint.public_hostname string or null

The hostname to connect to from the internet, or null when public_access is off. Resolves to the primary's public addresses.

endpoint.port integer

The port for connecting straight to PostgreSQL, 5432.

endpoint.pooled_port integer

The port for connecting through PgBouncer, 6432.

endpoint.private_ips array of objects

The primary's addresses in your private networks.

endpoint.private_ips[].network_id string

The ID of the private network.

endpoint.private_ips[].ip_address string

The address in that network.

endpoint.public_ips array of objects

The primary's public addresses, when public_access is on.

endpoint.public_ips[].ip string

The public address.

endpoint.public_ips[].type string

Whether it's an ipv4 or ipv6 address.

members array of objects

The instance's nodes, the primary and its replicas.

members[].id string

The node's ID.

members[].role string

Whether the node is the primary or a replica.
Valid values:
primary: The node that accepts writes.
replica: A read-only copy of the primary.

members[].status string

The node's status. Possible values: provisioning, syncing, running, down.

members[].replication_lag_seconds number or null

How far the replica is behind the primary, in seconds, or null on the primary.

members[].disk_used_bytes integer

The disk space the node uses, in bytes.

members[].private_ips array of objects

The node's addresses in your private networks.

members[].private_ips[].network_id string

The ID of the private network.

members[].private_ips[].ip_address string

The address in that network.

members[].created_at datetime

When the node was created. In ISO 8601 format, such as 2026-07-01T12:00:00Z.

databases array of strings

The names of the instance's databases. Add databases via Create a PostgreSQL database.

users array of objects

The instance's users. Add users via Create a PostgreSQL user, and get a user's password via Get a PostgreSQL user's credentials.

users[].id string

The id.

users[].username string

The username.

users[].default_user boolean

The default user.

users[].privileges object

The privileges.

users[].created_at datetime

In ISO 8601 format, such as 2026-07-01T12:00:00Z.

network_ids array of strings

The IDs of the private networks attached to every node. Order doesn't matter.

firewall_ids array of strings

The ID of the firewall attached to every node. An instance can have at most one firewall. Order doesn't matter.

latest_snapshot_at datetime or null

When the newest available snapshot was taken. In ISO 8601 format, such as 2026-07-01T12:00:00Z.

term string

The billing term.
Valid values:
monthly: Billed each month.
annual: Paid for a year at a time.

created_at datetime

When the instance was created. In ISO 8601 format, such as 2026-07-01T12:00:00Z.

updated_at datetime

When the instance was last updated. In ISO 8601 format, such as 2026-07-01T12:00:00Z.

team_id string

The ID of the team that owns the instance. Get the team ID via List teams.

metadata object

Your own tags, as string keys and values. At most 10.