postgres.go raw
1 package linodego
2
3 import (
4 "context"
5 "encoding/json"
6 "time"
7
8 "github.com/linode/linodego/internal/parseabletime"
9 )
10
11 type PostgresDatabaseTarget string
12
13 const (
14 PostgresDatabaseTargetPrimary PostgresDatabaseTarget = "primary"
15 PostgresDatabaseTargetSecondary PostgresDatabaseTarget = "secondary"
16 )
17
18 type PostgresCommitType string
19
20 const (
21 PostgresCommitTrue PostgresCommitType = "true"
22 PostgresCommitFalse PostgresCommitType = "false"
23 PostgresCommitLocal PostgresCommitType = "local"
24 PostgresCommitRemoteWrite PostgresCommitType = "remote_write"
25 PostgresCommitRemoteApply PostgresCommitType = "remote_apply"
26 )
27
28 type PostgresReplicationType string
29
30 const (
31 PostgresReplicationNone PostgresReplicationType = "none"
32 PostgresReplicationAsynch PostgresReplicationType = "asynch"
33 PostgresReplicationSemiSynch PostgresReplicationType = "semi_synch"
34 )
35
36 // A PostgresDatabase is an instance of Linode Postgres Managed Databases
37 type PostgresDatabase struct {
38 ID int `json:"id"`
39 Status DatabaseStatus `json:"status"`
40 Label string `json:"label"`
41 Region string `json:"region"`
42 Type string `json:"type"`
43 Engine string `json:"engine"`
44 Version string `json:"version"`
45 AllowList []string `json:"allow_list"`
46 Port int `json:"port"`
47
48 ClusterSize int `json:"cluster_size"`
49 Platform DatabasePlatform `json:"platform"`
50
51 // Members has dynamic keys so it is a map
52 Members map[string]DatabaseMemberType `json:"members"`
53
54 // Deprecated: ReplicationCommitType is a deprecated property, as it is no longer supported in DBaaS V2.
55 ReplicationCommitType PostgresCommitType `json:"replication_commit_type"`
56 // Deprecated: ReplicationType is a deprecated property, as it is no longer supported in DBaaS V2.
57 ReplicationType PostgresReplicationType `json:"replication_type"`
58 // Deprecated: SSLConnection is a deprecated property, as it is no longer supported in DBaaS V2.
59 SSLConnection bool `json:"ssl_connection"`
60 // Deprecated: Encrypted is a deprecated property, as it is no longer supported in DBaaS V2.
61 Encrypted bool `json:"encrypted"`
62
63 Hosts DatabaseHost `json:"hosts"`
64 Updates DatabaseMaintenanceWindow `json:"updates"`
65 Created *time.Time `json:"-"`
66 Updated *time.Time `json:"-"`
67 Fork *DatabaseFork `json:"fork"`
68 OldestRestoreTime *time.Time `json:"-"`
69 UsedDiskSizeGB int `json:"used_disk_size_gb"`
70 TotalDiskSizeGB int `json:"total_disk_size_gb"`
71 EngineConfig PostgresDatabaseEngineConfig `json:"engine_config"`
72 PrivateNetwork *DatabasePrivateNetwork `json:"private_network,omitempty"`
73 }
74
75 type PostgresDatabaseEngineConfig struct {
76 PG *PostgresDatabaseEngineConfigPG `json:"pg,omitempty"`
77 PGStatMonitorEnable *bool `json:"pg_stat_monitor_enable,omitempty"`
78 PGLookout *PostgresDatabaseEngineConfigPGLookout `json:"pglookout,omitempty"`
79 SharedBuffersPercentage *float64 `json:"shared_buffers_percentage,omitempty"`
80 WorkMem *int `json:"work_mem,omitempty"`
81 }
82
83 type PostgresDatabaseEngineConfigPG struct {
84 AutovacuumAnalyzeScaleFactor *float64 `json:"autovacuum_analyze_scale_factor,omitempty"`
85 AutovacuumAnalyzeThreshold *int32 `json:"autovacuum_analyze_threshold,omitempty"`
86 AutovacuumMaxWorkers *int `json:"autovacuum_max_workers,omitempty"`
87 AutovacuumNaptime *int `json:"autovacuum_naptime,omitempty"`
88 AutovacuumVacuumCostDelay *int `json:"autovacuum_vacuum_cost_delay,omitempty"`
89 AutovacuumVacuumCostLimit *int `json:"autovacuum_vacuum_cost_limit,omitempty"`
90 AutovacuumVacuumScaleFactor *float64 `json:"autovacuum_vacuum_scale_factor,omitempty"`
91 AutovacuumVacuumThreshold *int32 `json:"autovacuum_vacuum_threshold,omitempty"`
92 BGWriterDelay *int `json:"bgwriter_delay,omitempty"`
93 BGWriterFlushAfter *int `json:"bgwriter_flush_after,omitempty"`
94 BGWriterLRUMaxPages *int `json:"bgwriter_lru_maxpages,omitempty"`
95 BGWriterLRUMultiplier *float64 `json:"bgwriter_lru_multiplier,omitempty"`
96 DeadlockTimeout *int `json:"deadlock_timeout,omitempty"`
97 DefaultToastCompression *string `json:"default_toast_compression,omitempty"`
98 IdleInTransactionSessionTimeout *int `json:"idle_in_transaction_session_timeout,omitempty"`
99 JIT *bool `json:"jit,omitempty"`
100 MaxFilesPerProcess *int `json:"max_files_per_process,omitempty"`
101 MaxLocksPerTransaction *int `json:"max_locks_per_transaction,omitempty"`
102 MaxLogicalReplicationWorkers *int `json:"max_logical_replication_workers,omitempty"`
103 MaxParallelWorkers *int `json:"max_parallel_workers,omitempty"`
104 MaxParallelWorkersPerGather *int `json:"max_parallel_workers_per_gather,omitempty"`
105 MaxPredLocksPerTransaction *int `json:"max_pred_locks_per_transaction,omitempty"`
106 MaxReplicationSlots *int `json:"max_replication_slots,omitempty"`
107 MaxSlotWALKeepSize *int32 `json:"max_slot_wal_keep_size,omitempty"`
108 MaxStackDepth *int `json:"max_stack_depth,omitempty"`
109 MaxStandbyArchiveDelay *int `json:"max_standby_archive_delay,omitempty"`
110 MaxStandbyStreamingDelay *int `json:"max_standby_streaming_delay,omitempty"`
111 MaxWALSenders *int `json:"max_wal_senders,omitempty"`
112 MaxWorkerProcesses *int `json:"max_worker_processes,omitempty"`
113 PasswordEncryption *string `json:"password_encryption,omitempty"`
114 PGPartmanBGWInterval *int `json:"pg_partman_bgw.interval,omitempty"`
115 PGPartmanBGWRole *string `json:"pg_partman_bgw.role,omitempty"`
116 PGStatMonitorPGSMEnableQueryPlan *bool `json:"pg_stat_monitor.pgsm_enable_query_plan,omitempty"`
117 PGStatMonitorPGSMMaxBuckets *int `json:"pg_stat_monitor.pgsm_max_buckets,omitempty"`
118 PGStatStatementsTrack *string `json:"pg_stat_statements.track,omitempty"`
119 TempFileLimit *int32 `json:"temp_file_limit,omitempty"`
120 Timezone *string `json:"timezone,omitempty"`
121 TrackActivityQuerySize *int `json:"track_activity_query_size,omitempty"`
122 TrackCommitTimestamp *string `json:"track_commit_timestamp,omitempty"`
123 TrackFunctions *string `json:"track_functions,omitempty"`
124 TrackIOTiming *string `json:"track_io_timing,omitempty"`
125 WALSenderTimeout *int `json:"wal_sender_timeout,omitempty"`
126 WALWriterDelay *int `json:"wal_writer_delay,omitempty"`
127 }
128
129 type PostgresDatabaseEngineConfigPGLookout struct {
130 MaxFailoverReplicationTimeLag *int64 `json:"max_failover_replication_time_lag,omitempty"`
131 }
132
133 type PostgresDatabaseConfigInfo struct {
134 PG PostgresDatabaseConfigInfoPG `json:"pg"`
135 PGStatMonitorEnable PostgresDatabaseConfigInfoPGStatMonitorEnable `json:"pg_stat_monitor_enable"`
136 PGLookout PostgresDatabaseConfigInfoPGLookout `json:"pglookout"`
137 SharedBuffersPercentage PostgresDatabaseConfigInfoSharedBuffersPercentage `json:"shared_buffers_percentage"`
138 WorkMem PostgresDatabaseConfigInfoWorkMem `json:"work_mem"`
139 }
140
141 type PostgresDatabaseConfigInfoPG struct {
142 AutovacuumAnalyzeScaleFactor AutovacuumAnalyzeScaleFactor `json:"autovacuum_analyze_scale_factor"`
143 AutovacuumAnalyzeThreshold AutovacuumAnalyzeThreshold `json:"autovacuum_analyze_threshold"`
144 AutovacuumMaxWorkers AutovacuumMaxWorkers `json:"autovacuum_max_workers"`
145 AutovacuumNaptime AutovacuumNaptime `json:"autovacuum_naptime"`
146 AutovacuumVacuumCostDelay AutovacuumVacuumCostDelay `json:"autovacuum_vacuum_cost_delay"`
147 AutovacuumVacuumCostLimit AutovacuumVacuumCostLimit `json:"autovacuum_vacuum_cost_limit"`
148 AutovacuumVacuumScaleFactor AutovacuumVacuumScaleFactor `json:"autovacuum_vacuum_scale_factor"`
149 AutovacuumVacuumThreshold AutovacuumVacuumThreshold `json:"autovacuum_vacuum_threshold"`
150 BGWriterDelay BGWriterDelay `json:"bgwriter_delay"`
151 BGWriterFlushAfter BGWriterFlushAfter `json:"bgwriter_flush_after"`
152 BGWriterLRUMaxPages BGWriterLRUMaxPages `json:"bgwriter_lru_maxpages"`
153 BGWriterLRUMultiplier BGWriterLRUMultiplier `json:"bgwriter_lru_multiplier"`
154 DeadlockTimeout DeadlockTimeout `json:"deadlock_timeout"`
155 DefaultToastCompression DefaultToastCompression `json:"default_toast_compression"`
156 IdleInTransactionSessionTimeout IdleInTransactionSessionTimeout `json:"idle_in_transaction_session_timeout"`
157 JIT JIT `json:"jit"`
158 MaxFilesPerProcess MaxFilesPerProcess `json:"max_files_per_process"`
159 MaxLocksPerTransaction MaxLocksPerTransaction `json:"max_locks_per_transaction"`
160 MaxLogicalReplicationWorkers MaxLogicalReplicationWorkers `json:"max_logical_replication_workers"`
161 MaxParallelWorkers MaxParallelWorkers `json:"max_parallel_workers"`
162 MaxParallelWorkersPerGather MaxParallelWorkersPerGather `json:"max_parallel_workers_per_gather"`
163 MaxPredLocksPerTransaction MaxPredLocksPerTransaction `json:"max_pred_locks_per_transaction"`
164 MaxReplicationSlots MaxReplicationSlots `json:"max_replication_slots"`
165 MaxSlotWALKeepSize MaxSlotWALKeepSize `json:"max_slot_wal_keep_size"`
166 MaxStackDepth MaxStackDepth `json:"max_stack_depth"`
167 MaxStandbyArchiveDelay MaxStandbyArchiveDelay `json:"max_standby_archive_delay"`
168 MaxStandbyStreamingDelay MaxStandbyStreamingDelay `json:"max_standby_streaming_delay"`
169 MaxWALSenders MaxWALSenders `json:"max_wal_senders"`
170 MaxWorkerProcesses MaxWorkerProcesses `json:"max_worker_processes"`
171 PasswordEncryption PasswordEncryption `json:"password_encryption"`
172 PGPartmanBGWInterval PGPartmanBGWInterval `json:"pg_partman_bgw.interval"`
173 PGPartmanBGWRole PGPartmanBGWRole `json:"pg_partman_bgw.role"`
174 PGStatMonitorPGSMEnableQueryPlan PGStatMonitorPGSMEnableQueryPlan `json:"pg_stat_monitor.pgsm_enable_query_plan"`
175 PGStatMonitorPGSMMaxBuckets PGStatMonitorPGSMMaxBuckets `json:"pg_stat_monitor.pgsm_max_buckets"`
176 PGStatStatementsTrack PGStatStatementsTrack `json:"pg_stat_statements.track"`
177 TempFileLimit TempFileLimit `json:"temp_file_limit"`
178 Timezone Timezone `json:"timezone"`
179 TrackActivityQuerySize TrackActivityQuerySize `json:"track_activity_query_size"`
180 TrackCommitTimestamp TrackCommitTimestamp `json:"track_commit_timestamp"`
181 TrackFunctions TrackFunctions `json:"track_functions"`
182 TrackIOTiming TrackIOTiming `json:"track_io_timing"`
183 WALSenderTimeout WALSenderTimeout `json:"wal_sender_timeout"`
184 WALWriterDelay WALWriterDelay `json:"wal_writer_delay"`
185 }
186
187 type AutovacuumAnalyzeScaleFactor struct {
188 Description string `json:"description"`
189 Maximum float64 `json:"maximum"`
190 Minimum float64 `json:"minimum"`
191 RequiresRestart bool `json:"requires_restart"`
192 Type string `json:"type"`
193 }
194
195 type AutovacuumAnalyzeThreshold struct {
196 Description string `json:"description"`
197 Maximum int32 `json:"maximum"`
198 Minimum int32 `json:"minimum"`
199 RequiresRestart bool `json:"requires_restart"`
200 Type string `json:"type"`
201 }
202
203 type AutovacuumMaxWorkers struct {
204 Description string `json:"description"`
205 Maximum int `json:"maximum"`
206 Minimum int `json:"minimum"`
207 RequiresRestart bool `json:"requires_restart"`
208 Type string `json:"type"`
209 }
210
211 type AutovacuumNaptime struct {
212 Description string `json:"description"`
213 Maximum int `json:"maximum"`
214 Minimum int `json:"minimum"`
215 RequiresRestart bool `json:"requires_restart"`
216 Type string `json:"type"`
217 }
218
219 type AutovacuumVacuumCostDelay struct {
220 Description string `json:"description"`
221 Maximum int `json:"maximum"`
222 Minimum int `json:"minimum"`
223 RequiresRestart bool `json:"requires_restart"`
224 Type string `json:"type"`
225 }
226
227 type AutovacuumVacuumCostLimit struct {
228 Description string `json:"description"`
229 Maximum int `json:"maximum"`
230 Minimum int `json:"minimum"`
231 RequiresRestart bool `json:"requires_restart"`
232 Type string `json:"type"`
233 }
234
235 type AutovacuumVacuumScaleFactor struct {
236 Description string `json:"description"`
237 Maximum float64 `json:"maximum"`
238 Minimum float64 `json:"minimum"`
239 RequiresRestart bool `json:"requires_restart"`
240 Type string `json:"type"`
241 }
242
243 type AutovacuumVacuumThreshold struct {
244 Description string `json:"description"`
245 Maximum int32 `json:"maximum"`
246 Minimum int32 `json:"minimum"`
247 RequiresRestart bool `json:"requires_restart"`
248 Type string `json:"type"`
249 }
250
251 type BGWriterDelay struct {
252 Description string `json:"description"`
253 Example int `json:"example"`
254 Maximum int `json:"maximum"`
255 Minimum int `json:"minimum"`
256 RequiresRestart bool `json:"requires_restart"`
257 Type string `json:"type"`
258 }
259
260 type BGWriterFlushAfter struct {
261 Description string `json:"description"`
262 Example int `json:"example"`
263 Maximum int `json:"maximum"`
264 Minimum int `json:"minimum"`
265 RequiresRestart bool `json:"requires_restart"`
266 Type string `json:"type"`
267 }
268
269 type BGWriterLRUMaxPages struct {
270 Description string `json:"description"`
271 Example int `json:"example"`
272 Maximum int `json:"maximum"`
273 Minimum int `json:"minimum"`
274 RequiresRestart bool `json:"requires_restart"`
275 Type string `json:"type"`
276 }
277
278 type BGWriterLRUMultiplier struct {
279 Description string `json:"description"`
280 Example float64 `json:"example"`
281 Maximum float64 `json:"maximum"`
282 Minimum float64 `json:"minimum"`
283 RequiresRestart bool `json:"requires_restart"`
284 Type string `json:"type"`
285 }
286
287 type DeadlockTimeout struct {
288 Description string `json:"description"`
289 Example int `json:"example"`
290 Maximum int `json:"maximum"`
291 Minimum int `json:"minimum"`
292 RequiresRestart bool `json:"requires_restart"`
293 Type string `json:"type"`
294 }
295
296 type DefaultToastCompression struct {
297 Description string `json:"description"`
298 Enum []string `json:"enum"`
299 Example string `json:"example"`
300 RequiresRestart bool `json:"requires_restart"`
301 Type string `json:"type"`
302 }
303
304 type IdleInTransactionSessionTimeout struct {
305 Description string `json:"description"`
306 Maximum int `json:"maximum"`
307 Minimum int `json:"minimum"`
308 RequiresRestart bool `json:"requires_restart"`
309 Type string `json:"type"`
310 }
311
312 type JIT struct {
313 Description string `json:"description"`
314 Example bool `json:"example"`
315 RequiresRestart bool `json:"requires_restart"`
316 Type string `json:"type"`
317 }
318
319 type MaxFilesPerProcess struct {
320 Description string `json:"description"`
321 Maximum int `json:"maximum"`
322 Minimum int `json:"minimum"`
323 RequiresRestart bool `json:"requires_restart"`
324 Type string `json:"type"`
325 }
326
327 type MaxLocksPerTransaction struct {
328 Description string `json:"description"`
329 Maximum int `json:"maximum"`
330 Minimum int `json:"minimum"`
331 RequiresRestart bool `json:"requires_restart"`
332 Type string `json:"type"`
333 }
334
335 type MaxLogicalReplicationWorkers struct {
336 Description string `json:"description"`
337 Maximum int `json:"maximum"`
338 Minimum int `json:"minimum"`
339 RequiresRestart bool `json:"requires_restart"`
340 Type string `json:"type"`
341 }
342
343 type MaxParallelWorkers struct {
344 Description string `json:"description"`
345 Maximum int `json:"maximum"`
346 Minimum int `json:"minimum"`
347 RequiresRestart bool `json:"requires_restart"`
348 Type string `json:"type"`
349 }
350
351 type MaxParallelWorkersPerGather struct {
352 Description string `json:"description"`
353 Maximum int `json:"maximum"`
354 Minimum int `json:"minimum"`
355 RequiresRestart bool `json:"requires_restart"`
356 Type string `json:"type"`
357 }
358
359 type MaxPredLocksPerTransaction struct {
360 Description string `json:"description"`
361 Maximum int `json:"maximum"`
362 Minimum int `json:"minimum"`
363 RequiresRestart bool `json:"requires_restart"`
364 Type string `json:"type"`
365 }
366
367 type MaxReplicationSlots struct {
368 Description string `json:"description"`
369 Maximum int `json:"maximum"`
370 Minimum int `json:"minimum"`
371 RequiresRestart bool `json:"requires_restart"`
372 Type string `json:"type"`
373 }
374
375 type MaxSlotWALKeepSize struct {
376 Description string `json:"description"`
377 Maximum int32 `json:"maximum"`
378 Minimum int32 `json:"minimum"`
379 RequiresRestart bool `json:"requires_restart"`
380 Type string `json:"type"`
381 }
382
383 type MaxStackDepth struct {
384 Description string `json:"description"`
385 Maximum int `json:"maximum"`
386 Minimum int `json:"minimum"`
387 RequiresRestart bool `json:"requires_restart"`
388 Type string `json:"type"`
389 }
390
391 type MaxStandbyArchiveDelay struct {
392 Description string `json:"description"`
393 Maximum int `json:"maximum"`
394 Minimum int `json:"minimum"`
395 RequiresRestart bool `json:"requires_restart"`
396 Type string `json:"type"`
397 }
398
399 type MaxStandbyStreamingDelay struct {
400 Description string `json:"description"`
401 Maximum int `json:"maximum"`
402 Minimum int `json:"minimum"`
403 RequiresRestart bool `json:"requires_restart"`
404 Type string `json:"type"`
405 }
406
407 type MaxWALSenders struct {
408 Description string `json:"description"`
409 Maximum int `json:"maximum"`
410 Minimum int `json:"minimum"`
411 RequiresRestart bool `json:"requires_restart"`
412 Type string `json:"type"`
413 }
414
415 type MaxWorkerProcesses struct {
416 Description string `json:"description"`
417 Maximum int `json:"maximum"`
418 Minimum int `json:"minimum"`
419 RequiresRestart bool `json:"requires_restart"`
420 Type string `json:"type"`
421 }
422
423 type PasswordEncryption struct {
424 Description string `json:"description"`
425 Enum []string `json:"enum"`
426 Example string `json:"example"`
427 RequiresRestart bool `json:"requires_restart"`
428 Type string `json:"type"`
429 }
430
431 type PGPartmanBGWInterval struct {
432 Description string `json:"description"`
433 Example int `json:"example"`
434 Maximum int `json:"maximum"`
435 Minimum int `json:"minimum"`
436 RequiresRestart bool `json:"requires_restart"`
437 Type string `json:"type"`
438 }
439
440 type PGPartmanBGWRole struct {
441 Description string `json:"description"`
442 Example string `json:"example"`
443 MaxLength int `json:"maxLength"`
444 Pattern string `json:"pattern"`
445 RequiresRestart bool `json:"requires_restart"`
446 Type string `json:"type"`
447 }
448
449 type PGStatMonitorPGSMEnableQueryPlan struct {
450 Description string `json:"description"`
451 Example bool `json:"example"`
452 RequiresRestart bool `json:"requires_restart"`
453 Type string `json:"type"`
454 }
455
456 type PGStatMonitorPGSMMaxBuckets struct {
457 Description string `json:"description"`
458 Example int `json:"example"`
459 Maximum int `json:"maximum"`
460 Minimum int `json:"minimum"`
461 RequiresRestart bool `json:"requires_restart"`
462 Type string `json:"type"`
463 }
464
465 type PGStatStatementsTrack struct {
466 Description string `json:"description"`
467 Enum []string `json:"enum"`
468 RequiresRestart bool `json:"requires_restart"`
469 Type string `json:"type"`
470 }
471
472 type TempFileLimit struct {
473 Description string `json:"description"`
474 Example int32 `json:"example"`
475 Maximum int32 `json:"maximum"`
476 Minimum int32 `json:"minimum"`
477 RequiresRestart bool `json:"requires_restart"`
478 Type string `json:"type"`
479 }
480
481 type Timezone struct {
482 Description string `json:"description"`
483 Example string `json:"example"`
484 MaxLength int `json:"maxLength"`
485 Pattern string `json:"pattern"`
486 RequiresRestart bool `json:"requires_restart"`
487 Type string `json:"type"`
488 }
489
490 type TrackActivityQuerySize struct {
491 Description string `json:"description"`
492 Example int `json:"example"`
493 Maximum int `json:"maximum"`
494 Minimum int `json:"minimum"`
495 RequiresRestart bool `json:"requires_restart"`
496 Type string `json:"type"`
497 }
498
499 type TrackCommitTimestamp struct {
500 Description string `json:"description"`
501 Enum []string `json:"enum"`
502 Example string `json:"example"`
503 RequiresRestart bool `json:"requires_restart"`
504 Type string `json:"type"`
505 }
506
507 type TrackFunctions struct {
508 Description string `json:"description"`
509 Enum []string `json:"enum"`
510 RequiresRestart bool `json:"requires_restart"`
511 Type string `json:"type"`
512 }
513
514 type TrackIOTiming struct {
515 Description string `json:"description"`
516 Enum []string `json:"enum"`
517 Example string `json:"example"`
518 RequiresRestart bool `json:"requires_restart"`
519 Type string `json:"type"`
520 }
521
522 type WALSenderTimeout struct {
523 Description string `json:"description"`
524 Example int `json:"example"`
525 RequiresRestart bool `json:"requires_restart"`
526 Type string `json:"type"`
527 }
528
529 type WALWriterDelay struct {
530 Description string `json:"description"`
531 Example int `json:"example"`
532 Maximum int `json:"maximum"`
533 Minimum int `json:"minimum"`
534 RequiresRestart bool `json:"requires_restart"`
535 Type string `json:"type"`
536 }
537
538 type PostgresDatabaseConfigInfoPGStatMonitorEnable struct {
539 Description string `json:"description"`
540 RequiresRestart bool `json:"requires_restart"`
541 Type string `json:"type"`
542 }
543
544 type PostgresDatabaseConfigInfoPGLookout struct {
545 PGLookoutMaxFailoverReplicationTimeLag PGLookoutMaxFailoverReplicationTimeLag `json:"max_failover_replication_time_lag"`
546 }
547
548 type PGLookoutMaxFailoverReplicationTimeLag struct {
549 Description string `json:"description"`
550 Maximum int64 `json:"maximum"`
551 Minimum int64 `json:"minimum"`
552 RequiresRestart bool `json:"requires_restart"`
553 Type string `json:"type"`
554 }
555
556 type PostgresDatabaseConfigInfoSharedBuffersPercentage struct {
557 Description string `json:"description"`
558 Example float64 `json:"example"`
559 Maximum float64 `json:"maximum"`
560 Minimum float64 `json:"minimum"`
561 RequiresRestart bool `json:"requires_restart"`
562 Type string `json:"type"`
563 }
564
565 type PostgresDatabaseConfigInfoWorkMem struct {
566 Description string `json:"description"`
567 Example int `json:"example"`
568 Maximum int `json:"maximum"`
569 Minimum int `json:"minimum"`
570 RequiresRestart bool `json:"requires_restart"`
571 Type string `json:"type"`
572 }
573
574 func (d *PostgresDatabase) UnmarshalJSON(b []byte) error {
575 type Mask PostgresDatabase
576
577 p := struct {
578 *Mask
579
580 Created *parseabletime.ParseableTime `json:"created"`
581 Updated *parseabletime.ParseableTime `json:"updated"`
582 OldestRestoreTime *parseabletime.ParseableTime `json:"oldest_restore_time"`
583 }{
584 Mask: (*Mask)(d),
585 }
586
587 if err := json.Unmarshal(b, &p); err != nil {
588 return err
589 }
590
591 d.Created = (*time.Time)(p.Created)
592 d.Updated = (*time.Time)(p.Updated)
593 d.OldestRestoreTime = (*time.Time)(p.OldestRestoreTime)
594
595 return nil
596 }
597
598 // PostgresCreateOptions fields are used when creating a new Postgres Database
599 type PostgresCreateOptions struct {
600 Label string `json:"label"`
601 Region string `json:"region"`
602 Type string `json:"type"`
603 Engine string `json:"engine"`
604 AllowList []string `json:"allow_list,omitempty"`
605 ClusterSize int `json:"cluster_size,omitempty"`
606
607 // Deprecated: Encrypted is a deprecated property, as it is no longer supported in DBaaS V2.
608 Encrypted bool `json:"encrypted,omitempty"`
609 // Deprecated: SSLConnection is a deprecated property, as it is no longer supported in DBaaS V2.
610 SSLConnection bool `json:"ssl_connection,omitempty"`
611 // Deprecated: ReplicationType is a deprecated property, as it is no longer supported in DBaaS V2.
612 ReplicationType PostgresReplicationType `json:"replication_type,omitempty"`
613 // Deprecated: ReplicationCommitType is a deprecated property, as it is no longer supported in DBaaS V2.
614 ReplicationCommitType PostgresCommitType `json:"replication_commit_type,omitempty"`
615
616 Fork *DatabaseFork `json:"fork,omitempty"`
617
618 EngineConfig *PostgresDatabaseEngineConfig `json:"engine_config,omitempty"`
619 PrivateNetwork *DatabasePrivateNetwork `json:"private_network,omitempty"`
620 }
621
622 // PostgresUpdateOptions fields are used when altering the existing Postgres Database
623 type PostgresUpdateOptions struct {
624 Label string `json:"label,omitempty"`
625 AllowList *[]string `json:"allow_list,omitempty"`
626 Updates *DatabaseMaintenanceWindow `json:"updates,omitempty"`
627 Type string `json:"type,omitempty"`
628 ClusterSize int `json:"cluster_size,omitempty"`
629 Version string `json:"version,omitempty"`
630 EngineConfig *PostgresDatabaseEngineConfig `json:"engine_config,omitempty"`
631 PrivateNetwork *DatabasePrivateNetwork `json:"private_network,omitempty"`
632 }
633
634 // PostgresDatabaseSSL is the SSL Certificate to access the Linode Managed Postgres Database
635 type PostgresDatabaseSSL struct {
636 CACertificate []byte `json:"ca_certificate"`
637 }
638
639 // PostgresDatabaseCredential is the Root Credentials to access the Linode Managed Database
640 type PostgresDatabaseCredential struct {
641 Username string `json:"username"`
642 Password string `json:"password"`
643 }
644
645 // ListPostgresDatabases lists all Postgres Databases associated with the account
646 func (c *Client) ListPostgresDatabases(ctx context.Context, opts *ListOptions) ([]PostgresDatabase, error) {
647 return getPaginatedResults[PostgresDatabase](ctx, c, "databases/postgresql/instances", opts)
648 }
649
650 // PostgresDatabaseBackup is information for interacting with a backup for the existing Postgres Database
651 //
652 // Deprecated: PostgresDatabaseBackup is a deprecated struct, as the backup endpoints are no longer supported in DBaaS V2.
653 // In DBaaS V2, databases can be backed up via database forking.
654 type PostgresDatabaseBackup struct {
655 ID int `json:"id"`
656 Label string `json:"label"`
657 Type string `json:"type"`
658 Created *time.Time `json:"-"`
659 }
660
661 func (d *PostgresDatabaseBackup) UnmarshalJSON(b []byte) error {
662 type Mask PostgresDatabaseBackup
663
664 p := struct {
665 *Mask
666
667 Created *parseabletime.ParseableTime `json:"created"`
668 }{
669 Mask: (*Mask)(d),
670 }
671
672 if err := json.Unmarshal(b, &p); err != nil {
673 return err
674 }
675
676 d.Created = (*time.Time)(p.Created)
677
678 return nil
679 }
680
681 // PostgresBackupCreateOptions are options used for CreatePostgresDatabaseBackup(...)
682 //
683 // Deprecated: PostgresBackupCreateOptions is a deprecated struct, as the backup endpoints are no longer supported in DBaaS V2.
684 // In DBaaS V2, databases can be backed up via database forking.
685 type PostgresBackupCreateOptions struct {
686 Label string `json:"label"`
687 Target PostgresDatabaseTarget `json:"target"`
688 }
689
690 // ListPostgresDatabaseBackups lists all Postgres Database Backups associated with the given Postgres Database
691 //
692 // Deprecated: ListPostgresDatabaseBackups is a deprecated method, as the backup endpoints are no longer supported in DBaaS V2.
693 // In DBaaS V2, databases can be backed up via database forking.
694 func (c *Client) ListPostgresDatabaseBackups(ctx context.Context, databaseID int, opts *ListOptions) ([]PostgresDatabaseBackup, error) {
695 return getPaginatedResults[PostgresDatabaseBackup](ctx, c, formatAPIPath("databases/postgresql/instances/%d/backups", databaseID), opts)
696 }
697
698 // GetPostgresDatabase returns a single Postgres Database matching the id
699 func (c *Client) GetPostgresDatabase(ctx context.Context, databaseID int) (*PostgresDatabase, error) {
700 e := formatAPIPath("databases/postgresql/instances/%d", databaseID)
701 return doGETRequest[PostgresDatabase](ctx, c, e)
702 }
703
704 // CreatePostgresDatabase creates a new Postgres Database using the createOpts as configuration, returns the new Postgres Database
705 func (c *Client) CreatePostgresDatabase(ctx context.Context, opts PostgresCreateOptions) (*PostgresDatabase, error) {
706 return doPOSTRequest[PostgresDatabase](ctx, c, "databases/postgresql/instances", opts)
707 }
708
709 // DeletePostgresDatabase deletes an existing Postgres Database with the given id
710 func (c *Client) DeletePostgresDatabase(ctx context.Context, databaseID int) error {
711 e := formatAPIPath("databases/postgresql/instances/%d", databaseID)
712 return doDELETERequest(ctx, c, e)
713 }
714
715 // UpdatePostgresDatabase updates the given Postgres Database with the provided opts, returns the PostgresDatabase with the new settings
716 func (c *Client) UpdatePostgresDatabase(ctx context.Context, databaseID int, opts PostgresUpdateOptions) (*PostgresDatabase, error) {
717 e := formatAPIPath("databases/postgresql/instances/%d", databaseID)
718 return doPUTRequest[PostgresDatabase](ctx, c, e, opts)
719 }
720
721 // PatchPostgresDatabase applies security patches and updates to the underlying operating system of the Managed Postgres Database
722 func (c *Client) PatchPostgresDatabase(ctx context.Context, databaseID int) error {
723 e := formatAPIPath("databases/postgresql/instances/%d/patch", databaseID)
724 return doPOSTRequestNoRequestResponseBody(ctx, c, e)
725 }
726
727 // GetPostgresDatabaseCredentials returns the Root Credentials for the given Postgres Database
728 func (c *Client) GetPostgresDatabaseCredentials(ctx context.Context, databaseID int) (*PostgresDatabaseCredential, error) {
729 e := formatAPIPath("databases/postgresql/instances/%d/credentials", databaseID)
730 return doGETRequest[PostgresDatabaseCredential](ctx, c, e)
731 }
732
733 // ResetPostgresDatabaseCredentials returns the Root Credentials for the given Postgres Database (may take a few seconds to work)
734 func (c *Client) ResetPostgresDatabaseCredentials(ctx context.Context, databaseID int) error {
735 e := formatAPIPath("databases/postgresql/instances/%d/credentials/reset", databaseID)
736 return doPOSTRequestNoRequestResponseBody(ctx, c, e)
737 }
738
739 // GetPostgresDatabaseSSL returns the SSL Certificate for the given Postgres Database
740 func (c *Client) GetPostgresDatabaseSSL(ctx context.Context, databaseID int) (*PostgresDatabaseSSL, error) {
741 e := formatAPIPath("databases/postgresql/instances/%d/ssl", databaseID)
742 return doGETRequest[PostgresDatabaseSSL](ctx, c, e)
743 }
744
745 // GetPostgresDatabaseBackup returns a specific Postgres Database Backup with the given ids
746 //
747 // Deprecated: GetPostgresDatabaseBackup is a deprecated method, as the backup endpoints are no longer supported in DBaaS V2.
748 // In DBaaS V2, databases can be backed up via database forking.
749 func (c *Client) GetPostgresDatabaseBackup(ctx context.Context, databaseID int, backupID int) (*PostgresDatabaseBackup, error) {
750 e := formatAPIPath("databases/postgresql/instances/%d/backups/%d", databaseID, backupID)
751 return doGETRequest[PostgresDatabaseBackup](ctx, c, e)
752 }
753
754 // RestorePostgresDatabaseBackup returns the given Postgres Database with the given Backup
755 //
756 // Deprecated: RestorePostgresDatabaseBackup is a deprecated method, as the backup endpoints are no longer supported in DBaaS V2.
757 // In DBaaS V2, databases can be backed up via database forking.
758 func (c *Client) RestorePostgresDatabaseBackup(ctx context.Context, databaseID int, backupID int) error {
759 e := formatAPIPath("databases/postgresql/instances/%d/backups/%d/restore", databaseID, backupID)
760 return doPOSTRequestNoRequestResponseBody(ctx, c, e)
761 }
762
763 // CreatePostgresDatabaseBackup creates a snapshot for the given Postgres database
764 //
765 // Deprecated: CreatePostgresDatabaseBackup is a deprecated method, as the backup endpoints are no longer supported in DBaaS V2.
766 // In DBaaS V2, databases can be backed up via database forking.
767 func (c *Client) CreatePostgresDatabaseBackup(ctx context.Context, databaseID int, opts PostgresBackupCreateOptions) error {
768 e := formatAPIPath("databases/postgresql/instances/%d/backups", databaseID)
769 return doPOSTRequestNoResponseBody(ctx, c, e, opts)
770 }
771
772 // SuspendPostgresDatabase suspends a PostgreSQL Managed Database, releasing idle resources and keeping only necessary data.
773 // All service data is lost if there are no backups available.
774 func (c *Client) SuspendPostgresDatabase(ctx context.Context, databaseID int) error {
775 e := formatAPIPath("databases/postgresql/instances/%d/suspend", databaseID)
776 return doPOSTRequestNoRequestResponseBody(ctx, c, e)
777 }
778
779 // ResumePostgresDatabase resumes a suspended PostgreSQL Managed Database
780 func (c *Client) ResumePostgresDatabase(ctx context.Context, databaseID int) error {
781 e := formatAPIPath("databases/postgresql/instances/%d/resume", databaseID)
782 return doPOSTRequestNoRequestResponseBody(ctx, c, e)
783 }
784
785 // GetPostgresDatabaseConfig returns a detailed list of all the configuration options for PostgreSQL Databases
786 func (c *Client) GetPostgresDatabaseConfig(ctx context.Context) (*PostgresDatabaseConfigInfo, error) {
787 return doGETRequest[PostgresDatabaseConfigInfo](ctx, c, "databases/postgresql/config")
788 }
789