pgAdmin - PostgreSQL Management Tool
Table of Contents
Overview
pgAdmin is a comprehensive web-based management tool for PostgreSQL deployed in the Fako cluster. It provides a graphical interface for database administration, query execution, and monitoring. This deployment is pre-configured to connect to the PostgreSQL cluster with both read-write and read-only endpoints, making database management accessible through a web browser.
Key Features
- Web-Based Interface: Full-featured PostgreSQL management from browser
- Pre-Configured Servers: Automatic connection to cluster databases
- Query Tool: Advanced SQL editor with syntax highlighting
- Visual Database Designer: ERD and schema visualization
- Backup/Restore: GUI for database backup operations
- Server Monitoring: Real-time database statistics
- User Management: Graphical user and role administration
Architecture
Components
- Deployment: Single-replica deployment
- Service: ClusterIP service on port 80
- Ingress: HTTPS access (when configured)
- Storage: PersistentVolumeClaim for pgAdmin data
- ConfigMap: Server configuration and connection settings
- External Secrets: Database passwords from AWS Secrets Manager
Resource Requirements
- Memory: 256Mi (request), 512Mi (limit)
- CPU: 250m (request), 500m (limit)
- Storage: Persistent volume for pgAdmin data and sessions
Configuration
Environment Settings
| Parameter | Value | Description |
|---|---|---|
PGADMIN_DEFAULT_EMAIL | [email protected] | Admin login email |
PGADMIN_CONFIG_SERVER_MODE | False | Desktop mode (single user) |
PGADMIN_CONFIG_MASTER_PASSWORD_REQUIRED | False | No master password needed |
PGADMIN_SERVER_JSON_FILE | /pgadmin4/servers.json | Pre-configured servers |
Pre-Configured Database Servers
PostgreSQL Cluster (Read-Write)
- Host:
postgres-cluster-rw.postgres.svc.cluster.local - Port: 5432
- Database:
app - User:
app
- Host:
PostgreSQL Cluster (Read-Only)
- Host:
postgres-cluster-ro.postgres.svc.cluster.local - Port: 5432
- Database:
app - User:
app
- Host:
Usage
Accessing pgAdmin
External access (requires ingress):
https://pgadmin.your-domain.com
Internal access:
http://pgadmin.pgadmin.svc.cluster.local
Port forwarding for local access:
kubectl port-forward -n pgadmin svc/pgadmin 8080:80
# Access at http://localhost:8080
Initial Login
- Navigate to pgAdmin URL
- Login with:
- Email:
[email protected] - Password: From
pgadmin-secret
- Email:
Common Tasks
Connect to Database
- Servers are pre-configured
- Click on “PostgreSQL Cluster” in left panel
- Enter password when prompted
- Browse databases, schemas, tables
Execute Queries
- Right-click on database
- Select “Query Tool”
- Write and execute SQL
- View results in grid or chart
Create Database Backup
- Right-click on database
- Select “Backup…”
- Configure backup options
- Save to pgAdmin storage
Monitor Database Activity
- Select server in tree
- Click “Dashboard” tab
- View real-time metrics:
- Active connections
- Transaction rates
- Database sizes
- Query performance
Operations
Checking Service Status
# Check pod status
kubectl get pods -n pgadmin
# View logs
kubectl logs -n pgadmin deployment/pgadmin
# Check storage usage
kubectl exec -n pgadmin deployment/pgadmin -- df -h /var/lib/pgadmin
Managing Server Connections
Add New Server
- Right-click “Servers” → “Create” → “Server”
- Configure connection details
- Save password (optional)
Export Server List
# Get current server configuration
kubectl exec -n pgadmin deployment/pgadmin -- \
cat /var/lib/pgadmin/pgadmin4.db
Password Management
Passwords are stored via:
.pgpassfile for automatic authentication- External Secrets from AWS Secrets Manager
- pgAdmin’s internal password storage
Troubleshooting
Cannot Login
- Check secret:
kubectl get secret pgadmin-secret -n pgadmin -o yaml
- Reset admin password:
kubectl exec -it -n pgadmin deployment/pgadmin -- \
python /pgadmin4/setup.py --email [email protected] --password NewPassword
Connection Failed to Database
- Test connectivity:
kubectl exec -n pgadmin deployment/pgadmin -- \
nc -zv postgres-cluster-rw.postgres.svc.cluster.local 5432
- Check pgpass file:
kubectl exec -n pgadmin deployment/pgadmin -- cat /var/lib/pgadmin/.pgpass
- Verify credentials:
kubectl get secret -n pgadmin pgadmin-pgpass -o yaml
Performance Issues
- Check resource usage:
kubectl top pod -n pgadmin
Clear query history:
- Settings → Clear Query History
- Remove old backup files
Restart pod:
kubectl rollout restart deployment/pgadmin -n pgadmin
Storage Full
- Check usage:
kubectl exec -n pgadmin deployment/pgadmin -- \
du -sh /var/lib/pgadmin/*
- Clean up:
- Remove old backups
- Clear session data
- Delete query history
Security Considerations
Authentication
- Default setup uses single admin account
- Consider implementing:
- LDAP/AD integration
- OAuth with Keycloak
- Multi-user mode
Network Security
- No TLS by default (use ingress)
- Implement network policies
- Restrict database access
Best Practices
- Change default email: Update admin email
- Strong passwords: Use complex passwords
- Regular updates: Keep pgAdmin updated
- Audit logs: Enable and monitor logs
- Backup pgAdmin data: Include in backup strategy
Advanced Configuration
Enable Multi-User Mode
# In configmap
PGADMIN_CONFIG_SERVER_MODE: "True"
PGADMIN_CONFIG_MAIL_SERVER: "smtp.example.com"
PGADMIN_CONFIG_MAIL_PORT: "587"
Add SSL/TLS
# In deployment
env:
- name: PGADMIN_ENABLE_TLS
value: "True"
volumeMounts:
- name: certs
mountPath: /certs
Configure External Authentication
# OAuth2 with Keycloak
PGADMIN_CONFIG_AUTHENTICATION_SOURCES: ["oauth2"]
PGADMIN_CONFIG_OAUTH2_CLIENT_ID: "pgadmin"
PGADMIN_CONFIG_OAUTH2_CLIENT_SECRET: "${CLIENT_SECRET}"
PGADMIN_CONFIG_OAUTH2_TOKEN_URL: "https://auth.landryzetam.net/realms/master/protocol/openid-connect/token"
Monitoring
Key Metrics
- Login success/failure rates
- Query execution times
- Active user sessions
- Storage usage
- Memory consumption
Health Checks
Add health check endpoint:
livenessProbe:
httpGet:
path: /misc/ping
port: 80
initialDelaySeconds: 30
periodSeconds: 10
Integration Examples
With Grafana
Create PostgreSQL datasource:
- Use connection details from pgAdmin
- Configure in Grafana
- Build dashboards
With Backup Tools
Configure pgAdmin for automated backups:
# Backup script
import subprocess
subprocess.run([
"pg_dump",
"-h", "postgres-cluster-rw.postgres.svc.cluster.local",
"-U", "app",
"-d", "mydb",
"-f", "/backups/mydb.sql"
])
With CI/CD
Use pgAdmin for database migrations:
- Store migration scripts
- Execute via Query Tool
- Track schema versions
Maintenance
Regular Tasks
Daily:
- Monitor active connections
- Check for failed queries
Weekly:
- Review storage usage
- Clean old session data
- Check for updates
Monthly:
- Audit user access
- Review server configurations
- Update pgAdmin version
Upgrade Procedure
- Backup pgAdmin data:
kubectl exec -n pgadmin deployment/pgadmin -- \
tar -czf /tmp/pgadmin-backup.tar.gz /var/lib/pgadmin
- Update image:
image: dpage/pgadmin4:9.7.0
- Verify functionality:
- Test login
- Check server connections
- Verify saved queries
Performance Optimization
Query Performance
- Use EXPLAIN ANALYZE
- Create appropriate indexes
- Monitor slow queries
- Optimize query plans
pgAdmin Performance
- Limit query result size
- Use pagination
- Clear old data regularly
- Increase resources if needed
Database Connection
- Use connection pooling
- Set appropriate timeouts
- Monitor connection count
- Close idle connections
Future Improvements
- Implement SSO with Keycloak
- Add automated backup scheduling
- Create custom dashboards
- Implement query approval workflow
- Add database migration tracking
- Configure email notifications
- Create user access reports
- Add query performance analytics
- Implement schema version control
- Add cost tracking for queries