@vorionsys/infrastructure 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/LICENSE +190 -0
- package/README.md +89 -0
- package/dist/database/index.d.ts +14 -0
- package/dist/database/index.d.ts.map +1 -0
- package/dist/database/index.js +14 -0
- package/dist/database/index.js.map +1 -0
- package/dist/database/replication.d.ts +493 -0
- package/dist/database/replication.d.ts.map +1 -0
- package/dist/database/replication.js +920 -0
- package/dist/database/replication.js.map +1 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +17 -0
- package/dist/index.js.map +1 -0
- package/package.json +85 -0
|
@@ -0,0 +1,493 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PostgreSQL High Availability Replication Module
|
|
3
|
+
*
|
|
4
|
+
* Provides infrastructure for PostgreSQL HA with:
|
|
5
|
+
* - Streaming replication configuration
|
|
6
|
+
* - Patroni cluster management helpers
|
|
7
|
+
* - pg_auto_failover setup and monitoring
|
|
8
|
+
* - Automatic failover configuration
|
|
9
|
+
* - Replication lag monitoring
|
|
10
|
+
* - Health check endpoints for replicas
|
|
11
|
+
*
|
|
12
|
+
* @packageDocumentation
|
|
13
|
+
*/
|
|
14
|
+
import { Counter, Gauge, Histogram, Registry } from 'prom-client';
|
|
15
|
+
import { EventEmitter } from 'events';
|
|
16
|
+
/**
|
|
17
|
+
* Replication mode for PostgreSQL
|
|
18
|
+
*/
|
|
19
|
+
export type ReplicationMode = 'streaming' | 'logical' | 'synchronous';
|
|
20
|
+
/**
|
|
21
|
+
* Cluster orchestration type
|
|
22
|
+
*/
|
|
23
|
+
export type ClusterOrchestrator = 'patroni' | 'pg_auto_failover' | 'manual';
|
|
24
|
+
/**
|
|
25
|
+
* Replica node status
|
|
26
|
+
*/
|
|
27
|
+
export type ReplicaStatus = 'streaming' | 'catchup' | 'potential' | 'disconnected' | 'failed' | 'unknown';
|
|
28
|
+
/**
|
|
29
|
+
* Node role in the cluster
|
|
30
|
+
*/
|
|
31
|
+
export type NodeRole = 'primary' | 'replica' | 'witness' | 'unknown';
|
|
32
|
+
/**
|
|
33
|
+
* Failover reason
|
|
34
|
+
*/
|
|
35
|
+
export type FailoverReason = 'primary_failure' | 'manual_switchover' | 'scheduled_maintenance' | 'replication_lag_exceeded' | 'health_check_failure';
|
|
36
|
+
/**
|
|
37
|
+
* Configuration for a PostgreSQL node
|
|
38
|
+
*/
|
|
39
|
+
export interface PostgresNodeConfig {
|
|
40
|
+
/** Node identifier */
|
|
41
|
+
nodeId: string;
|
|
42
|
+
/** Host address */
|
|
43
|
+
host: string;
|
|
44
|
+
/** Port number */
|
|
45
|
+
port: number;
|
|
46
|
+
/** Database name */
|
|
47
|
+
database: string;
|
|
48
|
+
/** Username */
|
|
49
|
+
user: string;
|
|
50
|
+
/** Password */
|
|
51
|
+
password: string;
|
|
52
|
+
/** SSL configuration */
|
|
53
|
+
ssl?: boolean | {
|
|
54
|
+
rejectUnauthorized?: boolean;
|
|
55
|
+
ca?: string;
|
|
56
|
+
cert?: string;
|
|
57
|
+
key?: string;
|
|
58
|
+
};
|
|
59
|
+
/** Connection timeout in milliseconds */
|
|
60
|
+
connectionTimeoutMs?: number;
|
|
61
|
+
/** Idle timeout in milliseconds */
|
|
62
|
+
idleTimeoutMs?: number;
|
|
63
|
+
/** Maximum connections */
|
|
64
|
+
maxConnections?: number;
|
|
65
|
+
/** Application name */
|
|
66
|
+
applicationName?: string;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Replication cluster configuration
|
|
70
|
+
*/
|
|
71
|
+
export interface ReplicationClusterConfig {
|
|
72
|
+
/** Cluster name */
|
|
73
|
+
clusterName: string;
|
|
74
|
+
/** Replication mode */
|
|
75
|
+
replicationMode: ReplicationMode;
|
|
76
|
+
/** Cluster orchestrator */
|
|
77
|
+
orchestrator: ClusterOrchestrator;
|
|
78
|
+
/** Primary node configuration */
|
|
79
|
+
primary: PostgresNodeConfig;
|
|
80
|
+
/** Replica node configurations */
|
|
81
|
+
replicas: PostgresNodeConfig[];
|
|
82
|
+
/** Maximum acceptable replication lag in bytes */
|
|
83
|
+
maxReplicationLagBytes?: number;
|
|
84
|
+
/** Maximum acceptable replication lag in seconds */
|
|
85
|
+
maxReplicationLagSeconds?: number;
|
|
86
|
+
/** Health check interval in milliseconds */
|
|
87
|
+
healthCheckIntervalMs?: number;
|
|
88
|
+
/** Failover timeout in milliseconds */
|
|
89
|
+
failoverTimeoutMs?: number;
|
|
90
|
+
/** Whether automatic failover is enabled */
|
|
91
|
+
autoFailoverEnabled?: boolean;
|
|
92
|
+
/** Minimum replicas required for synchronous commit */
|
|
93
|
+
synchronousStandbyCount?: number;
|
|
94
|
+
/** Patroni-specific configuration */
|
|
95
|
+
patroni?: PatroniConfig;
|
|
96
|
+
/** pg_auto_failover specific configuration */
|
|
97
|
+
pgAutoFailover?: PgAutoFailoverConfig;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Patroni cluster configuration
|
|
101
|
+
*/
|
|
102
|
+
export interface PatroniConfig {
|
|
103
|
+
/** Patroni REST API endpoint */
|
|
104
|
+
apiEndpoint: string;
|
|
105
|
+
/** API username */
|
|
106
|
+
apiUsername?: string;
|
|
107
|
+
/** API password */
|
|
108
|
+
apiPassword?: string;
|
|
109
|
+
/** DCS (Distributed Configuration Store) type */
|
|
110
|
+
dcsType: 'etcd' | 'consul' | 'zookeeper' | 'kubernetes';
|
|
111
|
+
/** DCS connection string */
|
|
112
|
+
dcsEndpoint: string;
|
|
113
|
+
/** Namespace/scope */
|
|
114
|
+
namespace: string;
|
|
115
|
+
/** TTL for leader lock in seconds */
|
|
116
|
+
ttlSeconds?: number;
|
|
117
|
+
/** Loop wait time in seconds */
|
|
118
|
+
loopWaitSeconds?: number;
|
|
119
|
+
/** Retry timeout in seconds */
|
|
120
|
+
retryTimeoutSeconds?: number;
|
|
121
|
+
/** Maximum lag before failover (bytes) */
|
|
122
|
+
maximumLagOnFailover?: number;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* pg_auto_failover configuration
|
|
126
|
+
*/
|
|
127
|
+
export interface PgAutoFailoverConfig {
|
|
128
|
+
/** Monitor node connection string */
|
|
129
|
+
monitorConnectionString: string;
|
|
130
|
+
/** Formation name */
|
|
131
|
+
formation: string;
|
|
132
|
+
/** Group ID */
|
|
133
|
+
groupId: number;
|
|
134
|
+
/** Replication quorum */
|
|
135
|
+
replicationQuorum?: boolean;
|
|
136
|
+
/** Number sync standbys */
|
|
137
|
+
numberSyncStandbys?: number;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Replication statistics for a replica
|
|
141
|
+
*/
|
|
142
|
+
export interface ReplicationStats {
|
|
143
|
+
/** Replica node ID */
|
|
144
|
+
nodeId: string;
|
|
145
|
+
/** Current status */
|
|
146
|
+
status: ReplicaStatus;
|
|
147
|
+
/** Replication lag in bytes */
|
|
148
|
+
lagBytes: number;
|
|
149
|
+
/** Replication lag in seconds */
|
|
150
|
+
lagSeconds: number;
|
|
151
|
+
/** Last received LSN (Log Sequence Number) */
|
|
152
|
+
receivedLsn: string;
|
|
153
|
+
/** Last replayed LSN */
|
|
154
|
+
replayedLsn: string;
|
|
155
|
+
/** Replay lag in bytes */
|
|
156
|
+
replayLagBytes: number;
|
|
157
|
+
/** Write lag in bytes */
|
|
158
|
+
writeLagBytes: number;
|
|
159
|
+
/** Flush lag in bytes */
|
|
160
|
+
flushLagBytes: number;
|
|
161
|
+
/** Whether replica is in sync */
|
|
162
|
+
isInSync: boolean;
|
|
163
|
+
/** Timestamp of last stats collection */
|
|
164
|
+
collectedAt: Date;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Cluster health status
|
|
168
|
+
*/
|
|
169
|
+
export interface ClusterHealth {
|
|
170
|
+
/** Overall cluster health */
|
|
171
|
+
healthy: boolean;
|
|
172
|
+
/** Primary node health */
|
|
173
|
+
primaryHealthy: boolean;
|
|
174
|
+
/** Number of healthy replicas */
|
|
175
|
+
healthyReplicaCount: number;
|
|
176
|
+
/** Total replica count */
|
|
177
|
+
totalReplicaCount: number;
|
|
178
|
+
/** Current primary node ID */
|
|
179
|
+
currentPrimary: string;
|
|
180
|
+
/** Replication statistics per replica */
|
|
181
|
+
replicationStats: ReplicationStats[];
|
|
182
|
+
/** Average replication lag in bytes */
|
|
183
|
+
averageLagBytes: number;
|
|
184
|
+
/** Maximum replication lag in bytes */
|
|
185
|
+
maxLagBytes: number;
|
|
186
|
+
/** Any replicas exceeding lag threshold */
|
|
187
|
+
lagThresholdExceeded: boolean;
|
|
188
|
+
/** Last health check timestamp */
|
|
189
|
+
lastCheckAt: Date;
|
|
190
|
+
/** Health check duration in milliseconds */
|
|
191
|
+
checkDurationMs: number;
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Failover event
|
|
195
|
+
*/
|
|
196
|
+
export interface FailoverEvent {
|
|
197
|
+
/** Event ID */
|
|
198
|
+
eventId: string;
|
|
199
|
+
/** Previous primary node ID */
|
|
200
|
+
previousPrimary: string;
|
|
201
|
+
/** New primary node ID */
|
|
202
|
+
newPrimary: string;
|
|
203
|
+
/** Reason for failover */
|
|
204
|
+
reason: FailoverReason;
|
|
205
|
+
/** Failover initiated at */
|
|
206
|
+
initiatedAt: Date;
|
|
207
|
+
/** Failover completed at */
|
|
208
|
+
completedAt?: Date;
|
|
209
|
+
/** Whether failover was successful */
|
|
210
|
+
success: boolean;
|
|
211
|
+
/** Error message if failed */
|
|
212
|
+
errorMessage?: string;
|
|
213
|
+
/** Replication lag at failover time */
|
|
214
|
+
lagAtFailover?: number;
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Health check result for a single node
|
|
218
|
+
*/
|
|
219
|
+
export interface NodeHealthCheck {
|
|
220
|
+
/** Node ID */
|
|
221
|
+
nodeId: string;
|
|
222
|
+
/** Node role */
|
|
223
|
+
role: NodeRole;
|
|
224
|
+
/** Whether node is reachable */
|
|
225
|
+
reachable: boolean;
|
|
226
|
+
/** Response latency in milliseconds */
|
|
227
|
+
latencyMs: number;
|
|
228
|
+
/** PostgreSQL version */
|
|
229
|
+
pgVersion?: string;
|
|
230
|
+
/** Whether node is in recovery */
|
|
231
|
+
isInRecovery: boolean;
|
|
232
|
+
/** Transaction ID (XID) */
|
|
233
|
+
currentXid?: string;
|
|
234
|
+
/** Timeline ID */
|
|
235
|
+
timelineId?: number;
|
|
236
|
+
/** Error message if unhealthy */
|
|
237
|
+
errorMessage?: string;
|
|
238
|
+
/** Timestamp of check */
|
|
239
|
+
checkedAt: Date;
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Dedicated registry for replication metrics
|
|
243
|
+
*/
|
|
244
|
+
export declare const replicationRegistry: Registry<"text/plain; version=0.0.4; charset=utf-8">;
|
|
245
|
+
export declare const replicationLagBytesGauge: Gauge<"cluster" | "replica_id" | "replica_host">;
|
|
246
|
+
export declare const replicationLagSecondsGauge: Gauge<"cluster" | "replica_id" | "replica_host">;
|
|
247
|
+
export declare const replicaStatusGauge: Gauge<"cluster" | "replica_id" | "replica_host" | "status">;
|
|
248
|
+
export declare const clusterHealthGauge: Gauge<"cluster">;
|
|
249
|
+
export declare const healthyReplicaCountGauge: Gauge<"cluster">;
|
|
250
|
+
export declare const failoverEventsCounter: Counter<"cluster" | "reason" | "success">;
|
|
251
|
+
export declare const failoverDurationHistogram: Histogram<"cluster" | "reason">;
|
|
252
|
+
export declare const healthCheckDurationHistogram: Histogram<"cluster" | "node_id" | "role">;
|
|
253
|
+
export declare const healthCheckErrorsCounter: Counter<"cluster" | "node_id" | "error_type">;
|
|
254
|
+
/**
|
|
255
|
+
* PostgreSQL Replication Manager
|
|
256
|
+
*
|
|
257
|
+
* Manages PostgreSQL HA clusters with streaming replication,
|
|
258
|
+
* health monitoring, and failover coordination.
|
|
259
|
+
*
|
|
260
|
+
* @example
|
|
261
|
+
* ```typescript
|
|
262
|
+
* const manager = new ReplicationManager({
|
|
263
|
+
* clusterName: 'vorion-production',
|
|
264
|
+
* replicationMode: 'streaming',
|
|
265
|
+
* orchestrator: 'patroni',
|
|
266
|
+
* primary: { nodeId: 'primary', host: 'pg-primary', port: 5432, ... },
|
|
267
|
+
* replicas: [
|
|
268
|
+
* { nodeId: 'replica-1', host: 'pg-replica-1', port: 5432, ... },
|
|
269
|
+
* { nodeId: 'replica-2', host: 'pg-replica-2', port: 5432, ... },
|
|
270
|
+
* ],
|
|
271
|
+
* maxReplicationLagSeconds: 30,
|
|
272
|
+
* healthCheckIntervalMs: 10000,
|
|
273
|
+
* });
|
|
274
|
+
*
|
|
275
|
+
* await manager.start();
|
|
276
|
+
*
|
|
277
|
+
* // Get cluster health
|
|
278
|
+
* const health = await manager.getClusterHealth();
|
|
279
|
+
*
|
|
280
|
+
* // Get replication lag for a specific replica
|
|
281
|
+
* const stats = await manager.getReplicationStats('replica-1');
|
|
282
|
+
*
|
|
283
|
+
* // Manual switchover
|
|
284
|
+
* await manager.switchover('replica-1', 'scheduled_maintenance');
|
|
285
|
+
* ```
|
|
286
|
+
*/
|
|
287
|
+
export declare class ReplicationManager extends EventEmitter {
|
|
288
|
+
private config;
|
|
289
|
+
private primaryPool;
|
|
290
|
+
private replicaPools;
|
|
291
|
+
private healthCheckInterval;
|
|
292
|
+
private isRunning;
|
|
293
|
+
private currentPrimaryId;
|
|
294
|
+
private lastHealth;
|
|
295
|
+
constructor(config: ReplicationClusterConfig);
|
|
296
|
+
/**
|
|
297
|
+
* Start the replication manager
|
|
298
|
+
*/
|
|
299
|
+
start(): Promise<void>;
|
|
300
|
+
/**
|
|
301
|
+
* Stop the replication manager
|
|
302
|
+
*/
|
|
303
|
+
stop(): Promise<void>;
|
|
304
|
+
/**
|
|
305
|
+
* Start health check interval
|
|
306
|
+
*/
|
|
307
|
+
private startHealthChecks;
|
|
308
|
+
/**
|
|
309
|
+
* Update Prometheus metrics from health data
|
|
310
|
+
*/
|
|
311
|
+
private updateMetrics;
|
|
312
|
+
/**
|
|
313
|
+
* Get comprehensive cluster health status
|
|
314
|
+
*/
|
|
315
|
+
getClusterHealth(): Promise<ClusterHealth>;
|
|
316
|
+
/**
|
|
317
|
+
* Get replication statistics for all replicas
|
|
318
|
+
*/
|
|
319
|
+
getAllReplicationStats(): Promise<ReplicationStats[]>;
|
|
320
|
+
/**
|
|
321
|
+
* Get replication statistics for a specific replica
|
|
322
|
+
*/
|
|
323
|
+
getReplicationStats(nodeId: string): Promise<ReplicationStats | null>;
|
|
324
|
+
/**
|
|
325
|
+
* Check health of a specific node
|
|
326
|
+
*/
|
|
327
|
+
checkNodeHealth(nodeConfig: PostgresNodeConfig, role: NodeRole): Promise<NodeHealthCheck>;
|
|
328
|
+
/**
|
|
329
|
+
* Parse PostgreSQL interval to seconds
|
|
330
|
+
*/
|
|
331
|
+
private parseIntervalToSeconds;
|
|
332
|
+
/**
|
|
333
|
+
* Initiate manual switchover to a specified replica
|
|
334
|
+
* Note: For Patroni/pg_auto_failover, this coordinates with the orchestrator
|
|
335
|
+
*/
|
|
336
|
+
switchover(targetReplicaId: string, reason?: FailoverReason): Promise<FailoverEvent>;
|
|
337
|
+
/**
|
|
338
|
+
* Perform switchover via Patroni REST API
|
|
339
|
+
*/
|
|
340
|
+
private performPatroniSwitchover;
|
|
341
|
+
/**
|
|
342
|
+
* Perform switchover via pg_auto_failover
|
|
343
|
+
*/
|
|
344
|
+
private performPgAutoFailoverSwitchover;
|
|
345
|
+
/**
|
|
346
|
+
* Get the current cluster configuration
|
|
347
|
+
*/
|
|
348
|
+
getConfig(): ReplicationClusterConfig;
|
|
349
|
+
/**
|
|
350
|
+
* Get the current primary node ID
|
|
351
|
+
*/
|
|
352
|
+
getCurrentPrimary(): string;
|
|
353
|
+
/**
|
|
354
|
+
* Get the last cached health status
|
|
355
|
+
*/
|
|
356
|
+
getLastHealth(): ClusterHealth | null;
|
|
357
|
+
/**
|
|
358
|
+
* Check if the manager is running
|
|
359
|
+
*/
|
|
360
|
+
isManagerRunning(): boolean;
|
|
361
|
+
}
|
|
362
|
+
/**
|
|
363
|
+
* Generate PostgreSQL configuration for streaming replication
|
|
364
|
+
*/
|
|
365
|
+
export interface StreamingReplicationConfig {
|
|
366
|
+
/** Primary node configuration */
|
|
367
|
+
primary: {
|
|
368
|
+
/** postgresql.conf settings */
|
|
369
|
+
postgresqlConf: Record<string, string | number | boolean>;
|
|
370
|
+
/** pg_hba.conf entries */
|
|
371
|
+
pgHbaEntries: string[];
|
|
372
|
+
};
|
|
373
|
+
/** Replica node configuration */
|
|
374
|
+
replica: {
|
|
375
|
+
/** postgresql.conf settings */
|
|
376
|
+
postgresqlConf: Record<string, string | number | boolean>;
|
|
377
|
+
/** recovery.conf / standby.signal settings */
|
|
378
|
+
recoveryConf: Record<string, string>;
|
|
379
|
+
};
|
|
380
|
+
}
|
|
381
|
+
/**
|
|
382
|
+
* Generate streaming replication configuration
|
|
383
|
+
*/
|
|
384
|
+
export declare function generateStreamingReplicationConfig(options: {
|
|
385
|
+
/** Replication user name */
|
|
386
|
+
replicationUser: string;
|
|
387
|
+
/** Primary host address */
|
|
388
|
+
primaryHost: string;
|
|
389
|
+
/** Primary port */
|
|
390
|
+
primaryPort: number;
|
|
391
|
+
/** Replica hosts (for pg_hba.conf) */
|
|
392
|
+
replicaHosts: string[];
|
|
393
|
+
/** Synchronous replication mode */
|
|
394
|
+
synchronousMode?: 'off' | 'on' | 'remote_write' | 'remote_apply';
|
|
395
|
+
/** Synchronous standby names */
|
|
396
|
+
synchronousStandbyNames?: string[];
|
|
397
|
+
/** Max WAL senders */
|
|
398
|
+
maxWalSenders?: number;
|
|
399
|
+
/** Max replication slots */
|
|
400
|
+
maxReplicationSlots?: number;
|
|
401
|
+
/** WAL keep size in MB */
|
|
402
|
+
walKeepSize?: number;
|
|
403
|
+
/** Hot standby enabled */
|
|
404
|
+
hotStandby?: boolean;
|
|
405
|
+
/** Archive mode */
|
|
406
|
+
archiveMode?: boolean;
|
|
407
|
+
/** Archive command */
|
|
408
|
+
archiveCommand?: string;
|
|
409
|
+
}): StreamingReplicationConfig;
|
|
410
|
+
/**
|
|
411
|
+
* Generate Patroni cluster configuration
|
|
412
|
+
*/
|
|
413
|
+
export declare function generatePatroniConfig(options: {
|
|
414
|
+
/** Cluster name */
|
|
415
|
+
clusterName: string;
|
|
416
|
+
/** Node name */
|
|
417
|
+
nodeName: string;
|
|
418
|
+
/** PostgreSQL data directory */
|
|
419
|
+
dataDir: string;
|
|
420
|
+
/** PostgreSQL bin directory */
|
|
421
|
+
binDir?: string;
|
|
422
|
+
/** PostgreSQL port */
|
|
423
|
+
pgPort: number;
|
|
424
|
+
/** Patroni REST API port */
|
|
425
|
+
restApiPort: number;
|
|
426
|
+
/** DCS type */
|
|
427
|
+
dcsType: 'etcd' | 'consul' | 'zookeeper' | 'kubernetes';
|
|
428
|
+
/** DCS hosts */
|
|
429
|
+
dcsHosts: string[];
|
|
430
|
+
/** Superuser credentials */
|
|
431
|
+
superuser: {
|
|
432
|
+
username: string;
|
|
433
|
+
password: string;
|
|
434
|
+
};
|
|
435
|
+
/** Replication credentials */
|
|
436
|
+
replication: {
|
|
437
|
+
username: string;
|
|
438
|
+
password: string;
|
|
439
|
+
};
|
|
440
|
+
/** Bootstrap parameters */
|
|
441
|
+
bootstrap?: {
|
|
442
|
+
dcs?: Record<string, unknown>;
|
|
443
|
+
initdb?: string[];
|
|
444
|
+
pgHba?: string[];
|
|
445
|
+
};
|
|
446
|
+
}): Record<string, unknown>;
|
|
447
|
+
/**
|
|
448
|
+
* Generate pg_auto_failover setup commands
|
|
449
|
+
*/
|
|
450
|
+
export declare function generatePgAutoFailoverCommands(options: {
|
|
451
|
+
/** Formation name */
|
|
452
|
+
formation: string;
|
|
453
|
+
/** Node role */
|
|
454
|
+
role: 'monitor' | 'primary' | 'secondary';
|
|
455
|
+
/** PostgreSQL data directory */
|
|
456
|
+
dataDir: string;
|
|
457
|
+
/** PostgreSQL port */
|
|
458
|
+
pgPort: number;
|
|
459
|
+
/** Monitor connection string (for primary/secondary) */
|
|
460
|
+
monitorConnectionString?: string;
|
|
461
|
+
/** Node name */
|
|
462
|
+
nodeName: string;
|
|
463
|
+
/** Hostname/IP for connections */
|
|
464
|
+
hostname: string;
|
|
465
|
+
/** Group ID */
|
|
466
|
+
groupId?: number;
|
|
467
|
+
/** SSL mode */
|
|
468
|
+
sslMode?: 'disable' | 'require' | 'verify-ca' | 'verify-full';
|
|
469
|
+
}): string[];
|
|
470
|
+
/**
|
|
471
|
+
* HTTP handler for replica health check endpoint
|
|
472
|
+
* Returns JSON health status suitable for load balancer health checks
|
|
473
|
+
*/
|
|
474
|
+
export interface HealthCheckEndpointOptions {
|
|
475
|
+
/** Replication manager instance */
|
|
476
|
+
manager: ReplicationManager;
|
|
477
|
+
/** Maximum acceptable lag in bytes for healthy status */
|
|
478
|
+
maxLagBytes?: number;
|
|
479
|
+
/** Maximum acceptable lag in seconds for healthy status */
|
|
480
|
+
maxLagSeconds?: number;
|
|
481
|
+
/** Require at least N healthy replicas */
|
|
482
|
+
minHealthyReplicas?: number;
|
|
483
|
+
}
|
|
484
|
+
/**
|
|
485
|
+
* Create a health check response for load balancer integration
|
|
486
|
+
*/
|
|
487
|
+
export declare function createHealthCheckResponse(options: HealthCheckEndpointOptions): Promise<{
|
|
488
|
+
status: 'healthy' | 'unhealthy' | 'degraded';
|
|
489
|
+
statusCode: number;
|
|
490
|
+
body: Record<string, unknown>;
|
|
491
|
+
}>;
|
|
492
|
+
export default ReplicationManager;
|
|
493
|
+
//# sourceMappingURL=replication.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"replication.d.ts","sourceRoot":"","sources":["../../src/database/replication.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAGH,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAClE,OAAO,EAAE,YAAY,EAAE,MAA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