PostgreSQL DBA Complete Notes
1. Introduction
PostgreSQL is one of the most advanced open-source RDBMS used by organizations for critical
applications.
Architecture includes:
- Shared Buffers
- WAL (Write-Ahead Logging)
- Background Processes
2. Installation
Steps to Install PostgreSQL on RHEL:
1. Install Repository
2. yum install postgresql-server
3. Initialize Database: postgresql-setup initdb
4. Start Service: systemctl start postgresql
3. User & Role Management
- CREATE USER admin WITH PASSWORD 'password';
- GRANT ALL PRIVILEGES ON DATABASE mydb TO admin;
- ALTER ROLE admin WITH SUPERUSER;
4. Backup & Restore
- Logical Backup: pg_dump -U user -d dbname > backup.sql
- Physical Backup: Base Backup with pg_basebackup
- PITR: Recovery with WAL Archiving
5. Replication
Steps to Configure Streaming Replication:
1. Enable wal_level = replica
2. Setup primary_conninfo
3. Start replica service
6. Performance Tuning
- Shared Buffers Tuning
- Autovacuum Configuration
- Index Optimization
7. Troubleshooting
- Deadlocks: Identify with pg_stat_activity
- Replication Lag: Check with pg_stat_replication
- WAL Full Issue
8. AWS RDS PostgreSQL
- Create RDS PostgreSQL Instance
- Automated Backups
- Monitoring Metrics
9. Real-time Scenarios
- How to perform PITR?
- How to recover replication?
- WAL Archiving Troubleshooting
10. Interview Questions
1. What is PostgreSQL Architecture?
2. How to set up Streaming Replication?
3. What is Autovacuum?
4. What is WAL Archiving?
5. How to tune PostgreSQL Performance?