0

Update Postgres instance

by
Published Oct 17, 2025

Update a Postgres instance by ID.

Script render Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Render = {
3
	apiKey: string
4
}
5
/**
6
 * Update Postgres instance
7
 * Update a Postgres instance by ID.
8

9
 */
10
export async function main(
11
	auth: Render,
12
	postgresId: string,
13
	body: {
14
		name?: string
15
		plan?:
16
			| 'free'
17
			| 'starter'
18
			| 'standard'
19
			| 'pro'
20
			| 'pro_plus'
21
			| 'custom'
22
			| 'basic_256mb'
23
			| 'basic_1gb'
24
			| 'basic_4gb'
25
			| 'pro_4gb'
26
			| 'pro_8gb'
27
			| 'pro_16gb'
28
			| 'pro_32gb'
29
			| 'pro_64gb'
30
			| 'pro_128gb'
31
			| 'pro_192gb'
32
			| 'pro_256gb'
33
			| 'pro_384gb'
34
			| 'pro_512gb'
35
			| 'accelerated_16gb'
36
			| 'accelerated_32gb'
37
			| 'accelerated_64gb'
38
			| 'accelerated_128gb'
39
			| 'accelerated_256gb'
40
			| 'accelerated_384gb'
41
			| 'accelerated_512gb'
42
			| 'accelerated_768gb'
43
			| 'accelerated_1024gb'
44
		diskSizeGB?: number
45
		enableHighAvailability?: false | true
46
		datadogAPIKey?: string
47
		datadogSite?: string
48
		ipAllowList?: { cidrBlock: string; description: string }[]
49
		readReplicas?: { name: string }[]
50
	}
51
) {
52
	const url = new URL(`https://api.render.com/v1/postgres/${postgresId}`)
53

54
	const response = await fetch(url, {
55
		method: 'PATCH',
56
		headers: {
57
			'Content-Type': 'application/json',
58
			Authorization: 'Bearer ' + auth.apiKey
59
		},
60
		body: JSON.stringify(body)
61
	})
62
	if (!response.ok) {
63
		const text = await response.text()
64
		throw new Error(`${response.status} ${text}`)
65
	}
66
	return await response.json()
67
}
68