0

Create or restore a PostgreSQL Managed Database

by
Published Oct 17, 2025

**Provision a PostgreSQL Managed Database** Use this operation to create a new PostgreSQL Managed Database.

Script linode Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Linode = {
3
  token: string;
4
};
5
/**
6
 * Create or restore a PostgreSQL Managed Database
7
 * **Provision a PostgreSQL Managed Database**
8

9
Use this operation to create a new PostgreSQL Managed Database.
10
 */
11
export async function main(
12
  auth: Linode,
13
  apiVersion: "v4" | "v4beta",
14
  body: {
15
    allow_list?: string[];
16
    cluster_size?: 1 | 2 | 3;
17
    engine: string;
18
    fork?: { restore_time?: string; source?: number } & {};
19
    label: string;
20
    region: string;
21
    ssl_connection?: false | true;
22
    type: string;
23
  },
24
) {
25
  const url = new URL(
26
    `https://api.linode.com/${apiVersion}/databases/postgresql/instances`,
27
  );
28

29
  const response = await fetch(url, {
30
    method: "POST",
31
    headers: {
32
      "Content-Type": "application/json",
33
      Authorization: "Bearer " + auth.token,
34
    },
35
    body: JSON.stringify(body),
36
  });
37
  if (!response.ok) {
38
    const text = await response.text();
39
    throw new Error(`${response.status} ${text}`);
40
  }
41
  return await response.json();
42
}
43