@@ -583,12 +583,12 @@ def test_pg_cron_extension(host):
583
583
ssh = host ['ssh' ]
584
584
585
585
# 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' )
587
587
assert result ['succeeded' ], f"Failed to find prestart script: { result ['stderr' ]} "
588
588
logger .info (f"Prestart script details: { result ['stdout' ]} " )
589
589
590
590
# 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' )
592
592
assert result ['succeeded' ], f"Failed to read extensions file: { result ['stderr' ]} "
593
593
logger .info (f"Extensions file contents: { result ['stdout' ]} " )
594
594
@@ -597,6 +597,33 @@ def test_pg_cron_extension(host):
597
597
assert result ['succeeded' ], f"Failed to find version switcher: { result ['stderr' ]} "
598
598
logger .info (f"Version switcher details: { result ['stdout' ]} " )
599
599
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
+
600
627
# Create the extension
601
628
result = run_ssh_command (ssh , 'sudo -u postgres psql -d postgres -c "CREATE EXTENSION pg_cron WITH SCHEMA pg_catalog VERSION \' 1.3.1\' ;"' )
602
629
assert result ['succeeded' ], f"Failed to create pg_cron extension: { result ['stderr' ]} "
0 commit comments