Updates project's Postgres config

Script supabase Verified

by hugo697 ยท 10/17/2025

The script

Submitted by hugo697 Bun
Verified 207 days ago
1
//native
2
type Supabase = {
3
	key: string
4
}
5
/**
6
 * Updates project's Postgres config
7
 *
8
 */
9
export async function main(
10
	auth: Supabase,
11
	ref: string,
12
	body: {
13
		effective_cache_size?: string
14
		logical_decoding_work_mem?: string
15
		maintenance_work_mem?: string
16
		track_activity_query_size?: string
17
		max_connections?: number
18
		max_locks_per_transaction?: number
19
		max_parallel_maintenance_workers?: number
20
		max_parallel_workers?: number
21
		max_parallel_workers_per_gather?: number
22
		max_replication_slots?: number
23
		max_slot_wal_keep_size?: string
24
		max_standby_archive_delay?: string
25
		max_standby_streaming_delay?: string
26
		max_wal_size?: string
27
		max_wal_senders?: number
28
		max_worker_processes?: number
29
		session_replication_role?: 'origin' | 'replica' | 'local'
30
		shared_buffers?: string
31
		statement_timeout?: string
32
		track_commit_timestamp?: false | true
33
		wal_keep_size?: string
34
		wal_sender_timeout?: string
35
		work_mem?: string
36
		restart_database?: false | true
37
	}
38
) {
39
	const url = new URL(`https://api.supabase.com/v1/projects/${ref}/config/database/postgres`)
40

41
	const response = await fetch(url, {
42
		method: 'PUT',
43
		headers: {
44
			'Content-Type': 'application/json',
45
			Authorization: 'Bearer ' + auth.key
46
		},
47
		body: JSON.stringify(body)
48
	})
49
	if (!response.ok) {
50
		const text = await response.text()
51
		throw new Error(`${response.status} ${text}`)
52
	}
53
	return await response.json()
54
}
55