79795603

Date: 2025-10-21 08:38:22
Score: 0.5
Natty:
Report link

Maybe this helps. for me it work nicely. and sets like 11 postgres processes to the cores i want on the cpu i want (multi CPU sever). its a part of a startup script when server restarts.

SET "POSTGRES_SERVICE_NAME=postgresql-x64-18"
:: --- CPU Affinity Masks ---
:: PostgreSQL: 7 physical cores on CPU 1 (logical processors 16-29)
SET "AFFINITY_POSTGRES=0x3FFF0000"
:: --- 1. Start PostgreSQL Service ---
echo [1/3] PostgreSQL Service
echo ---------------------------------------------------

echo Checking PostgreSQL service state...
sc query %POSTGRES_SERVICE_NAME% | find "STATE" | find "RUNNING" > nul
if %errorlevel% == 0 (
    echo   [OK] PostgreSQL is already RUNNING.
) else (
    echo    Starting PostgreSQL service...
    net start %POSTGRES_SERVICE_NAME% >nul 2>&1
    
    echo    Waiting for PostgreSQL to initialize...
    for /l %%i in (1,1,15) do (
        timeout /t 1 /nobreak > nul
        sc query %POSTGRES_SERVICE_NAME% | find "STATE" | find "RUNNING" > nul
        if !errorlevel! == 0 (
            goto :postgres_started
        )
    )
    
    :: If we get here, timeout expired
    echo   [ERROR] PostgreSQL service failed to start within 15 seconds. Check logs.
    pause & goto :eof
    
    :postgres_started
    echo   [OK] PostgreSQL service started.
)

:: Wait a moment for all postgres.exe processes to spawn
echo    Waiting for PostgreSQL processes to spawn...
timeout /t 3 /nobreak > nul

:: Apply affinity to ALL postgres.exe processes using PowerShell
echo    Setting PostgreSQL affinity to %AFFINITY_POSTGRES%...
powershell -NoProfile -ExecutionPolicy Bypass -Command "$procs = Get-Process -Name postgres -ErrorAction SilentlyContinue; $count = 0; foreach($p in $procs) { try { $p.ProcessorAffinity = %AFFINITY_POSTGRES%; $count++ } catch {} }; Write-Host \"  [OK] Affinity set for $count postgres.exe processes.\" -ForegroundColor Green"
Reasons:
  • RegEx Blacklisted phrase (1): i want
  • Long answer (-1):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: Jonas Bergant