Point-in-Time Recovery (PITR) Database Setup
Imagine: at 14:37 someone accidentally drops the orders table, or at 09:15 a mass incorrect UPDATE hits a million rows. Without PITR, recovery is only to the last backup — all data after that is lost. We solve this by configuring Point-in-Time Recovery for PostgreSQL and MySQL, so you can roll back to any second. Standard backups protect against full failure, but not logical errors. PITR enables recovery with transaction-level precision. Key metrics: RPO (Recovery Point Objective) — maximum data loss. With archive_timeout=300, RPO ≤ 5 minutes. RTO (Recovery Time Objective) — recovery time. For a 100 GB database, 15–40 minutes. Without PITR, recovery can take days instead of hours, and lost data is often unrecoverable. According to PostgreSQL documentation, WAL archiving is the foundation of PITR. Savings from a single data deletion incident can exceed $5,000.
Why PITR Is a Necessity, Not an Option
Without PITR, you lose all changes after the last backup. This can cost hours of work and reputation damage. With PITR, you recover to the moment just before the error, losing only a few minutes. Time savings during rollback are 10x faster than re-entering data.
Supported Databases
- PostgreSQL — pgBackRest with replication to S3.
- MySQL — binary logs with
binlog_format=ROW.
How PITR Works
It requires two components: a base snapshot (full backup) and a continuous stream of transaction logs from the snapshot to the current time (WAL for PostgreSQL, binlog for MySQL). Recovery = base snapshot + replay of logs up to the desired point. Storage cost for WAL archives in S3 for a 100 GB database is about $15/month. Each WAL segment is 16 MB and has a unique Log Sequence Number (LSN), allowing precisely targeted recovery.
PITR Setup for PostgreSQL
WAL Archiving Configuration
In postgresql.conf:
wal_level = replica
archive_mode = on
archive_command = 'pgbackrest --stanza=myapp archive-push %p'
archive_timeout = 300
A PostgreSQL restart is required after changing wal_level.
pgBackRest: Complete PITR Configuration
# /etc/pgbackrest/pgbackrest.conf
[global]
repo1-path=/mnt/backup-storage/pgbackrest
repo1-retention-full=3
repo1-retention-archive=14
repo2-type=s3
repo2-path=/pgbackrest
repo2-s3-bucket=company-db-backups
repo2-s3-region=eu-west-1
repo2-retention-full=2
[myapp]
pg1-path=/var/lib/postgresql/14/main
pg1-port=5432
Point-in-Time Restore
systemctl stop postgresql
pgbackrest --stanza=myapp restore \
--target="YYYY-MM-DD HH:MM:SS" \
--target-action=promote \
--delta
systemctl start postgresql
Replace --target with the desired timestamp. --delta restores only changed files, speeding up the process.
PITR Setup for MySQL via binlog
Binary Log Configuration
# /etc/mysql/mysql.conf.d/mysqld.cnf
server_id = 1
log_bin = /var/log/mysql/mysql-bin.log
binlog_format = ROW
expire_logs_days = 14
max_binlog_size = 500M
binlog_row_image = FULL
Recovery Using mysqlbinlog
mysql -u root myapp < full_backup_YYYYMMDD.sql
mysqlbinlog \
--stop-datetime="YYYY-MM-DD HH:MM:SS" \
/var/log/mysql/mysql-bin.000040 \
/var/log/mysql/mysql-bin.000041 \
/var/log/mysql/mysql-bin.000042 | mysql -u root myapp
To skip a problematic transaction, specify --start-position and --stop-position in mysqlbinlog to exclude the corrupt event.
Choosing Between PITR on PostgreSQL and MySQL
| Parameter |
PostgreSQL (pgBackRest) |
MySQL (binlog) |
| Default RPO |
5 minutes |
≤ 1 minute (no delay) |
| RTO for 100 GB |
15–40 minutes |
10–30 minutes |
| Built-in replication |
Streaming (native) |
Async/semi-sync (native) |
| Archive storage |
S3, local, NFS |
Filesystem, S3 (via tools) |
| LSN-based recovery |
Yes |
No (time/position only) |
PostgreSQL offers more flexibility (LSN recovery, parallel apply) but requires more careful tuning. MySQL is simpler to configure, but binlog files can consume significant space with ROW format.
Local vs S3 Storage for WAL Archive
| Parameter |
Local Disk |
S3 (Cloud) |
| Write speed |
High (NVMe) |
Moderate (depends on bandwidth) |
| Reliability |
Limited (disk failure) |
High (7×9 replication) |
| Cost |
One-time |
Monthly (~$15/month for 100 GB) |
| Internet recovery |
Local only |
Anywhere |
| Recommendation |
For databases < 50 GB |
For databases > 50 GB and DR |
Our PITR Setup Process
-
Audit current infrastructure — determine database size, change frequency, RTO/RPO requirements.
-
Configure archiving — set up WAL/binlog, choose repository (local disk + S3).
-
Test restore — verify recovery to a random point in an isolated environment.
- Documentation — record procedures, create a runbook for on-call engineers.
- Training — conduct a workshop for your team on manual and automated recovery.
Common Mistakes and How to Avoid Them
- Missing WAL segment due to incorrect
archive_command — ensure the command exits with code 0. Use pgbackrest --stanza=myapp check.
- Too large
archive_timeout interval — increases RPO. Keep it at 5 minutes or less.
- No archive replication — we use S3 in another region for disaster recovery.
- Lack of regular drills — recovery without testing can fail at a critical moment.
Schedule a test restore at least once a quarter. We help with this.
What's Included
- Full PITR setup for PostgreSQL and/or MySQL.
- Configuration of pgBackRest or binlog with cloud backup.
- Test restore and results report.
- Recovery procedure documentation (runbook).
- Training for your engineers.
- Recovery guarantee to any point in time within the configured period.
Timeline and Cost
Setup time: 2 to 5 business days depending on infrastructure complexity (replication, S3, clustering). Cost starts from $2,500 for a single database setup. Order PITR setup now — protect your data. For a consultation, contact us: your personal manager will assess the system in one day.
We have over 10 years of experience in PostgreSQL and MySQL administration, completed more than 40 PITR projects. Our engineers are certified and regularly undergo training. We guarantee data recovery within agreed RTO/RPO. Contact us for a consultation.
For further reading: official PostgreSQL documentation on WAL and MySQL Binary Log.
We regularly encounter a situation: "The site is not opening" at 3 a.m. — and it turns out that the VPS disk is full because nginx logs haven't been rotated for six months. Or the server went down under load on the day of an advertising campaign launch because the shared hosting had a limit of 50 concurrent connections. Setting up hosting and deployment is not about "where it's cheaper" but about what happens when something goes wrong. Our team helps avoid such incidents by designing infrastructure that accounts for real load patterns.
When to choose Vercel and Netlify?
Vercel is built for Next.js — deploy in one push, preview deployments for every PR, automatic CDN, Edge Functions, ISR without configuration. For frontend projects and JAMstack, it's the optimal choice: no operational overhead, time-to-deploy measured in minutes.
Real limitations: Vercel Serverless Functions run in us-east-1 by default (latency for Europe +80–100ms), Function timeout 300 seconds on Pro, Bandwidth 1TB/month on Pro. For heavy backend, you need workers or a separate server.
Netlify is closer to static sites and Edge Functions based on Deno Deploy. Build minutes are the main limitation on the free tier.
| Criterion |
Vercel |
Netlify |
| Main specialization |
Next.js, frameworks |
Static, JAMstack |
| Edge Functions |
V8 isolates (Node.js) |
Deno Deploy |
| Preview Deployments |
Built-in |
Built-in |
| Serverless Functions |
Yes, 300s limit |
Yes, 10s limit |
| Free bandwidth limit |
100 GB |
100 GB |
Why is Docker the foundation of predictable deployment?
"It works on my machine" — classic. Docker solves this through environment containerization. But a bad Dockerfile creates new problems.
A typical mistake: copying everything into the image without .dockerignore, resulting in an 800MB image instead of 80MB. node_modules inside the image weighs as much. Correct approach: multi-stage build.
FROM node:20-alpine AS builder
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
COPY . .
RUN npm run build
FROM node:20-alpine AS runner
WORKDIR /app
COPY --from=builder /app/.next ./.next
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/package.json ./package.json
EXPOSE 3000
CMD ["npm", "start"]
Final image: 180MB instead of 1.2GB. CI build time is reduced due to layer caching — if package.json hasn't changed, the layer with npm ci is taken from cache.
Docker Compose for local development and simple production scenarios: application + PostgreSQL + Redis in one configuration. For production on a single server, it's a perfectly viable option if there's no requirement for horizontal scaling.
More about containerization — Wikipedia: Docker.
How to set up Nginx as a reverse proxy?
Nginx in front of the application is standard for VPS and dedicated servers. Main functions: SSL termination, gzip, static files, rate limiting, upstream load balancing.
A configuration often done incorrectly: worker_processes auto — number of processes equals CPU count. worker_connections 1024 — that's 1024 per worker process. With 4 CPUs and 1024 connections = 4096 concurrent connections. For a high-traffic site, you need worker_connections 4096 and set keepalive_timeout 65.
For static assets with hash in the filename:
location ~* \.(js|css|woff2|png|webp)$ {
expires 1y;
add_header Cache-Control "public, immutable";
}
immutable tells the browser: don't revalidate this file even on hard refresh. This only works correctly with content-hashed filenames (which Vite/webpack do by default). Documentation — Wikipedia: Nginx.
AWS: flexibility and complexity
EC2 + Auto Scaling Group — classic for horizontal scaling. AMI with pre-installed application, Launch Template, ASG with min/desired/max instances, Application Load Balancer. When CPU > 70% for 3 minutes — scale out, when CPU < 30% for 15 minutes — scale in. Health check via ALB removes unhealthy instances from rotation.
ECS Fargate — containers without managing EC2. Deploy a Docker image, specify CPU/memory (512 CPU units = 0.5 vCPU, from 512MB memory), Fargate launches it. More expensive than Lambda, but no cold start and no timeout limitations. Suitable for long-running processes, WebSocket servers, heavy workers.
RDS for PostgreSQL with Multi-AZ: automatic failover in 1–2 minutes when primary fails. Read Replicas for scaling reads. RDS Proxy for connection pooling — Lambda functions cannot hold long-term connections, the proxy buffers this.
Kubernetes: when it is justified
K8s adds significant operational complexity. Justified when: multiple teams deploy independent services, fine-grained resource allocation per service is needed, canary deployments and blue/green without downtime are required.
AWS EKS, GKE, or managed k8s from Hetzner (cheaper). Helm charts for standard services. Horizontal Pod Autoscaler based on CPU and custom metrics (RPS via Prometheus).
For most startups and medium-sized projects, Kubernetes is overkill. ECS or Fly.io provide 80% of the capabilities with 20% of the operational complexity.
Monitoring and alerting
A server without monitoring is waiting for an incident. Minimal stack: Prometheus + Grafana (or Grafana Cloud for managed), alerting on disk > 80%, memory > 85%, CPU > 90% over 5 minutes, error rate > 1%. Uptime via Better Uptime or Upptime (self-hosted).
Logs: Loki + Grafana or CloudWatch Logs Insights. Structured JSON logs (winston, pino) are mandatory — otherwise, log searching becomes a pain.
What is included in hosting setup
- Audit of current infrastructure and load profiling
- Selection of target architecture (VPS, AWS, serverless, Kubernetes)
- Setting up CI/CD pipeline (GitHub Actions, GitLab CI) with automatic deployment
- IaC via Terraform or Pulumi (infrastructure as code)
- Configuration of Nginx, SSL certificates, HTTP/2, brotli
- Monitoring and alerting (Prometheus + Grafana, PagerDuty)
- Documentation of runbooks and team training
Additionally, contact us if you need migration from current hosting or integration with external services.
Work process
- Audit of current infrastructure (2–5 days)
- Selection of target architecture with load and budget justification (1–3 days)
- Setting up CI/CD pipeline (GitHub Actions, GitLab CI) (2–5 days)
- IaC via Terraform or Pulumi (3–10 days)
- Setting up monitoring and alerting (2–5 days)
- Documentation of runbooks and team training (1–3 days)
Our experience — 7 years on the market, over 50 projects, guarantee of operability after deployment.
Timeline
- Basic deployment on VPS with Docker + Nginx + CI/CD: 1–2 weeks.
- Setting up AWS infrastructure with Auto Scaling, RDS, CDN: 3–6 weeks.
- Migration to EKS from scratch: 6–12 weeks.
- Setting up Vercel/Netlify for JAMstack: 3–5 days.
The cost is calculated individually depending on complexity and scope of work. Get a consultation — we'll evaluate your architecture in one day.