@@ -583,12 +583,12 @@ def test_pg_cron_extension(host):
583583 ssh = host ['ssh' ]
584584
585585 # Check prestart script
586- result = run_ssh_command (ssh , 'ls -l /etc/postgresql/prestart.d /postgres_prestart.sh' )
586+ result = run_ssh_command (ssh , 'ls -l /usr/local/bin /postgres_prestart.sh' )
587587 assert result ['succeeded' ], f"Failed to find prestart script: { result ['stderr' ]} "
588588 logger .info (f"Prestart script details: { result ['stdout' ]} " )
589589
590590 # Check if extensions file exists
591- result = run_ssh_command (ssh , 'cat /root/pg_extensions.json' )
591+ result = run_ssh_command (ssh , 'sudo cat /root/pg_extensions.json' )
592592 assert result ['succeeded' ], f"Failed to read extensions file: { result ['stderr' ]} "
593593 logger .info (f"Extensions file contents: { result ['stdout' ]} " )
594594
@@ -597,6 +597,33 @@ def test_pg_cron_extension(host):
597597 assert result ['succeeded' ], f"Failed to find version switcher: { result ['stderr' ]} "
598598 logger .info (f"Version switcher details: { result ['stdout' ]} " )
599599
600+ # Check systemd service status
601+ logger .info ("Checking systemd service status..." )
602+ result = run_ssh_command (ssh , 'sudo systemctl list-units --type=service | grep postgres' )
603+ logger .info (f"PostgreSQL services: { result ['stdout' ]} " )
604+ result = run_ssh_command (ssh , 'sudo systemctl status postgresql' )
605+ logger .info (f"PostgreSQL service status: { result ['stdout' ]} " )
606+
607+ # Restart PostgreSQL through systemd
608+ logger .info ("Restarting PostgreSQL through systemd..." )
609+ result = run_ssh_command (ssh , 'sudo systemctl stop postgresql' )
610+ logger .info (f"Stop result: { result ['stdout' ]} " )
611+ result = run_ssh_command (ssh , 'sudo systemctl start postgresql' )
612+ logger .info (f"Start result: { result ['stdout' ]} " )
613+
614+ # Wait for PostgreSQL to be ready
615+ logger .info ("Waiting for PostgreSQL to be ready..." )
616+ max_attempts = 30
617+ for attempt in range (max_attempts ):
618+ result = run_ssh_command (ssh , 'sudo -u postgres /usr/bin/pg_isready -U postgres' )
619+ if result ['succeeded' ]:
620+ logger .info ("PostgreSQL is ready" )
621+ break
622+ logger .warning (f"PostgreSQL not ready yet (attempt { attempt + 1 } /{ max_attempts } )" )
623+ sleep (2 )
624+ else :
625+ raise Exception ("PostgreSQL failed to start through systemd" )
626+
600627 # Create the extension
601628 result = run_ssh_command (ssh , 'sudo -u postgres psql -d postgres -c "CREATE EXTENSION pg_cron WITH SCHEMA pg_catalog VERSION \' 1.3.1\' ;"' )
602629 assert result ['succeeded' ], f"Failed to create pg_cron extension: { result ['stderr' ]} "
0 commit comments