@@ -18,8 +18,9 @@ STAT_EXTENSION_SQL=@STAT_EXTENSION_SQL@
18
18
19
19
# Start PostgreSQL using nix
20
20
start_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 "
23
24
echo " PostgreSQL started."
24
25
}
25
26
@@ -31,16 +32,15 @@ cleanup() {
31
32
if pgrep -f " postgres" > /dev/null; then
32
33
echo " Stopping PostgreSQL gracefully..."
33
34
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
36
37
37
38
# Wait a bit for graceful shutdown
38
39
sleep 5
39
40
40
- # If processes are still running, force kill
41
+ # Check if processes are still running
41
42
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."
44
44
fi
45
45
else
46
46
echo " PostgreSQL is not running, skipping stop."
@@ -53,9 +53,6 @@ cleanup() {
53
53
else
54
54
echo " Cleanup completed successfully"
55
55
fi
56
-
57
- # Explicitly exit with 0 to prevent workflow failure
58
- exit 0
59
56
}
60
57
61
58
0 commit comments