@@ -295,12 +295,30 @@ def get_ssh_connection(instance_ip, ssh_identity_file, max_retries=10):
295
295
)
296
296
297
297
def is_healthy (host , instance_ip , ssh_identity_file ) -> bool :
298
- status_checks = [
299
- "dpkg -l | grep postgresql" ,
300
- "systemctl status postgresql" ,
301
- "ls -la /var/lib/postgresql" ,
302
- "ps aux | grep postgres"
298
+ postgres_diagnostics = [
299
+ "sudo tail -n 50 /var/log/postgresql/postgresql-*.log" , # Get recent PostgreSQL logs
300
+ "sudo -u postgres /usr/bin/pg_isready -U postgres -v" , # Verbose pg_isready
301
+ "sudo systemctl status postgresql" , # Get service status
302
+ "sudo journalctl -u postgresql --no-pager -n 50" , # Get journal logs
303
+ "ps aux | grep postgres" , # Check running processes
304
+ "sudo ls -la /var/lib/postgresql/*/main/" , # Check data directory permissions
305
+ "sudo cat /var/lib/postgresql/*/main/postmaster.pid" , # Check if PID file exists
306
+ "sudo -u postgres psql -c 'SELECT version();' || true" # Try to connect and get version
303
307
]
308
+
309
+ logger .warning ("Running PostgreSQL diagnostic checks..." )
310
+ for check in postgres_diagnostics :
311
+ try :
312
+ result = host .run (check )
313
+ logger .warning (f"\n === { check } ===\n Return code: { result .rc } \n Output:\n { result .stdout } \n Errors:\n { result .stderr } " )
314
+ except Exception as e :
315
+ logger .warning (f"Failed to run { check } : { str (e )} " )
316
+ status_checks = [
317
+ "dpkg -l | grep postgresql" ,
318
+ "systemctl status postgresql" ,
319
+ "ls -la /var/lib/postgresql" ,
320
+ "ps aux | grep postgres"
321
+ ]
304
322
305
323
for check in status_checks :
306
324
result = host .run (check )
0 commit comments