Skip to main content

High Availability

Ensure your database stays online with automatic failover and standby replicas.

Overview​

High Availability (HA) in SailOps PostgreSQL provides:

  • Automatic failover - Less than 30 seconds
  • Standby replicas - In different availability zones
  • Zero data loss - Synchronous replication
  • Transparent to applications - Same connection string

Architecture​

Enabling High Availability​

During Database Creation​

  1. Go to Services > Create > PostgreSQL
  2. Toggle High Availability to ON
  3. Complete the configuration
  4. Click Create

On Existing Database​

  1. Go to your database
  2. Click Edit
  3. Toggle High Availability to ON
  4. Click Save
Enabling HA

Enabling HA on an existing database may cause a brief restart. Plan for a maintenance window.

How Failover Works​

Automatic Detection​

SailOps continuously monitors:

  • Database process health
  • Network connectivity
  • Disk I/O
  • Replication lag

Failover Process​

When a primary fails:

  1. Detection - Issue detected (< 10 seconds)
  2. Validation - Confirms primary is truly down
  3. Promotion - Standby promoted to primary (< 20 seconds)
  4. DNS Update - Connection endpoint updated
  5. Application reconnects - Automatic with proper error handling

Total failover time: < 30 seconds

Application Behavior​

During failover:

  • Connections to old primary are dropped
  • New connections route to new primary
  • Applications should retry failed queries

Connection Handling​

Same Connection String​

Your connection string stays the same (format: {service-name}.{namespace}):

postgresql://postgres:[email protected]:5432/postgres

The internal DNS automatically resolves to the current primary. The namespace is assigned to your project.

Application Requirements​

For seamless failover, applications should:

  1. Handle connection errors gracefully
  2. Implement retry logic
  3. Use connection pooling

Example: Node.js with Retry​

const { Pool } = require('pg');

const pool = new Pool({
connectionString: process.env.DATABASE_URL,
connectionTimeoutMillis: 5000,
});

async function queryWithRetry(sql, params, maxRetries = 3) {
for (let attempt = 1; attempt <= maxRetries; attempt++) {
try {
return await pool.query(sql, params);
} catch (error) {
if (attempt === maxRetries) throw error;
// Wait before retry
await new Promise(r => setTimeout(r, 1000 * attempt));
}
}
}

Replication Lag​

Synchronous Replication​

By default, HA uses synchronous replication:

  • Zero data loss - All writes confirmed on standby
  • Slightly higher latency - Waits for standby confirmation

Monitoring Lag​

View replication status:

SELECT
pg_wal_lsn_diff(pg_current_wal_lsn(), replay_lsn) as lag_bytes
FROM pg_stat_replication;

In the UI:

  1. Go to your database
  2. Click Metrics tab
  3. View Replication Lag chart

Lag Alerts​

Set up alerts for replication lag:

  1. Go to Monitoring > Alerts
  2. Create alert: Replication Lag > 1 MB
  3. Configure notifications

Testing Failover​

Simulate Failover​

Contact support to perform a planned failover test:

  1. Schedule maintenance window
  2. Support initiates failover
  3. Verify application behavior
  4. Confirm data integrity

What to Test​

  • Application reconnects successfully
  • No data is lost
  • Queries resume within acceptable time
  • Alerts fire correctly

Read Replicas​

Purpose​

Read replicas handle read-only queries:

  • Offload reporting queries
  • Reduce primary load
  • Geographic distribution (Enterprise)

Connection​

Read replicas have separate connection strings:

# Primary (read/write)
postgresql://user:password@{db-name}-rw.{project-name}:5432/postgres

# Replica (read-only)
postgresql://user:password@{db-name}-ro.{project-name}:5432/postgres

Example: A database named mydb in project production would have:

  • Primary: mydb-rw.production
  • Replica: mydb-ro.production

Application Pattern​

const primaryPool = new Pool({ connectionString: PRIMARY_URL });
const replicaPool = new Pool({ connectionString: REPLICA_URL });

// Use replica for reads
async function getUser(id) {
return replicaPool.query('SELECT * FROM users WHERE id = $1', [id]);
}

// Use primary for writes
async function createUser(data) {
return primaryPool.query('INSERT INTO users ...');
}

Maintenance Windows​

Planned Maintenance​

SailOps performs maintenance during:

  • Time: Off-peak hours (configurable)
  • Notice: 24 hours advance notice
  • Duration: Usually < 5 minutes

Maintenance Types​

TypeImpactFrequency
Minor updatesBrief failoverWeekly
Major updatesPlanned downtimeQuarterly
Security patchesBrief failoverAs needed

Configure Maintenance Window​

  1. Go to database settings
  2. Set preferred maintenance window
  3. Receive advance notifications

Monitoring HA​

Health Indicators​

IndicatorHealthyWarning
Primary statusReadyN/A
Standby statusReadyDown
Replication lag< 1 MB> 10 MB
Failover historyNoneRecent

HA Events​

View HA events:

  1. Go to database Events tab
  2. Filter by "Replication" or "Failover"
  3. Review history

Pricing​

High Availability doubles compute costs (standby replica running synchronously):

  • Primary instance: Full compute cost for selected class and resources
  • Standby replica: Additional compute cost (same as primary)

The exact cost depends on your selected compute class (Eco, Standard, Production) and flavor (Small, Medium, Large, XLarge). View current pricing in the dashboard when enabling HA.

Cost vs Downtime

For production workloads, the cost of HA is typically much less than the cost of downtime.

Troubleshooting​

Standby Not Syncing​

  • Check replication lag metrics
  • Review database logs
  • Contact support if persists

Failover Taking Too Long​

  • Check application retry logic
  • Verify DNS resolution
  • Review network configuration

Application Not Reconnecting​

  • Implement proper error handling
  • Use connection pooling
  • Set appropriate timeouts