@@ -18,8 +18,9 @@ STAT_EXTENSION_SQL=@STAT_EXTENSION_SQL@
1818
1919# Start PostgreSQL using nix
2020start_postgres () {
21- echo " Starting PostgreSQL..."
22- nix run " $FLAKE_URL #start-server" -- " $PSQL_VERSION " --skip-migrations --daemonize
21+ DATDIR=$( mktemp -d)
22+ echo " Starting PostgreSQL in directory: $DATDIR " # Create the DATDIR if it doesn't exist
23+ nix run " $FLAKE_URL #start-server" -- " $PSQL_VERSION " --skip-migrations --daemonize --datdir " $DATDIR "
2324 echo " PostgreSQL started."
2425}
2526
@@ -31,16 +32,15 @@ cleanup() {
3132 if pgrep -f " postgres" > /dev/null; then
3233 echo " Stopping PostgreSQL gracefully..."
3334
34- # Use a more specific signal handling approach
35- pkill -15 -f " postgres " # Send SIGTERM
35+ # Use pg_ctl to stop PostgreSQL
36+ pg_ctl -D " $DATDIR " stop
3637
3738 # Wait a bit for graceful shutdown
3839 sleep 5
3940
40- # If processes are still running, force kill
41+ # Check if processes are still running
4142 if pgrep -f " postgres" > /dev/null; then
42- echo " Forcing PostgreSQL processes to stop..."
43- pkill -9 -f " postgres" # Send SIGKILL if SIGTERM didn't work
43+ echo " Warning: Some PostgreSQL processes could not be stopped gracefully."
4444 fi
4545 else
4646 echo " PostgreSQL is not running, skipping stop."
@@ -53,9 +53,6 @@ cleanup() {
5353 else
5454 echo " Cleanup completed successfully"
5555 fi
56-
57- # Explicitly exit with 0 to prevent workflow failure
58- exit 0
5956}
6057
6158
0 commit comments