Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wcIhN-003FHg-2D for pgsql-bugs@arkaria.postgresql.org; Wed, 24 Jun 2026 08:11:05 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wcIhL-00G72S-20 for pgsql-bugs@arkaria.postgresql.org; Wed, 24 Jun 2026 08:11:03 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wcGtk-00FjrF-2t for pgsql-bugs@lists.postgresql.org; Wed, 24 Jun 2026 06:15:44 +0000 Received: from mail-pg1-x530.google.com ([2607:f8b0:4864:20::530]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wcGti-000000023OI-3wfW for pgsql-bugs@lists.postgresql.org; Wed, 24 Jun 2026 06:15:44 +0000 Received: by mail-pg1-x530.google.com with SMTP id 41be03b00d2f7-c88b7c92577so239749a12.3 for ; Tue, 23 Jun 2026 23:15:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1782281741; x=1782886541; darn=lists.postgresql.org; h=content-transfer-encoding:date:message-id:subject:to:mime-version :from:from:to:cc:subject:date:message-id:reply-to; bh=uQhUCRaJaXVlyOZz7QgFtoJSV6slEsbKV4B1Xmu/1w4=; b=cqRu2SGdTuVbD2QhiUziZtjRaaEdYkoO0DUf02B9RpIymQaCCTO3mGJhHd8dPobjj9 3IMrvz9ZjQkNTIJ6Xe+LbtKjPnb7aJsE4/VjCcPcCpegz6sWyMLl9qYJbrI2TM31AuGC xShsNOYY2nSeFUMB2aOgwJdchsZ+xkxR6a3N0ZBjHlkNTqwMoJpH8aRyeBn1zQZyNtzh GDCVy8vVU60pprm0z8UTNKQjW7CynxD4YEAkEItsCuPyCbjExOCTMeMlVfrJs/Gnx6jT U3RcuZKA/kd+MW88sHqqtjEWMAmvdUabo8PwhRV/Vl2TuWecayTNhxOjl8J0AaSrHvvz xrFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782281741; x=1782886541; h=content-transfer-encoding:date:message-id:subject:to:mime-version :from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=uQhUCRaJaXVlyOZz7QgFtoJSV6slEsbKV4B1Xmu/1w4=; b=O//zeBU6T9si3YWZw7wBLGeGbb5BSAUYz1QA15wmOeoP6yDvItyPD81eGJs3SM7r/h v1jJpRaWxf9WOeQ6fQd5BXZA7poG3kLdnMgz8QIXS5sxHqLG609EutEhQOA36Sx2DXQz hbVEnrLhDRUBKJIof8c0ZGz5q8ErV8usOLy9XYmGe4js47NzljqZuRVhiCD44koJl1jV YWO99cTgjFNx1nbFzFN0KaGgKW2XaJSqk9OiXJhA9b6Ig3lFqTq15kbuIpepLNQ9l/74 11J5D5cPFCwl+Dtec9LczHxYShOtGOpa/imMOA/w0wKVHRiQvdrjyUegRcoMGneXI6t8 vuTQ== X-Gm-Message-State: AOJu0YwsHj5gQc8aAbSTftW2fd9VXQHP5afjUvYCCJi3kGOVvTkEdNmJ HlGtFEEY06ZBhgvpHfZ6sbpVB9+HvaGYi8OWzu9FfCS1fNAZlbwNJvnLNBLyag== X-Gm-Gg: AfdE7cnA+rfAN9twME9Bf/gFWK/iWhfCXd4kpSi1jVwWqUc4N6aIPP4iu1yqz5VAxRt InxaVeG+lb9R99OOV4b5dpJUMCUqRpwFQJBC/5HwdxlSRhhTTrJZKQKNGD+vXLWEBiRm/YhxXV6 8gohQ9LYYLMdROmbfNhiAVmOdDcAWkg28KucIty4rVBzTsfc5TfzY+ECnFqO2n7YUE/+XYd4BBs PwTamuHrGH5pDBSzXADvuxhBLjXWppTNsu/F3qgFgbQjA3eXJj7JOGC31LRS6v5cLb8CFRvdFOD 27/MbYnAa64G/LGB0ViBk8u/RSJ+C9NIyRtBf+4zmJ9NNL+RTYDcSBTv+brK5m3WWpGQ52PQHBB DRcmk9WXeAQlGMKJnEqwMhUtMFIHneWikCMd0lXYr/bFl2STxePTroW7QAfCoJ7kn+6+I3AUIji dHQ5EMZoVXzkAxep6a01Fdf+YM2V747hthsH9VoO9hKTc0F9W96W4VjZitbXxTy2nZ8MhL6kz0i nY4k46HX+K+DgjgvICBftMCqw== X-Received: by 2002:a05:6a21:39b:b0:3a3:171f:6aff with SMTP id adf61e73a8af0-3bd2d04c08amr2674045637.2.1782281740701; Tue, 23 Jun 2026 23:15:40 -0700 (PDT) Received: from NBK11-64-T5J (97-113-225-217.tukw.qwest.net. [97.113.225.217]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-c8bc563c131sm13199984a12.18.2026.06.23.23.15.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Jun 2026 23:15:40 -0700 (PDT) From: wyuebei@gmail.com X-Google-Original-From: MIME-Version: 1.0 To: Subject: =?utf-8?Q?pg_ctl_start_spawns_visible_cmd.exe_console_window_on_Windows_=E2=80=94_C?= =?utf-8?Q?reateProcessAsUser_missing_CREATE_NO_WINDOW?= Message-ID: <18bbefccd530e218.a6bdbcf84d30dc08.260dd5df653405e8@NBK11-64-T5J> Date: Wed, 24 Jun 2026 06:15:40 +0000 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Dear PostgreSQL developers, We discovered this bug while debugging a cascading failure across three layers of software that ultimately traced back to pg_ctl.exe on Windows. ## The discovery chain We use a tool called pg0 (vectorize-io/pg0) which bundles PostgreSQL via the theseus-rs/postgresql-embedded Rust crate. On every PostgreSQL start, a cmd.exe console window flashed briefly. We traced the process tree: parent (CREATE_NO_WINDOW) =E2=86=92 pg0.exe =E2=86=92 postgresql_embedded = =E2=86=92 pg_ctl start =E2=86=92 cmd.exe /C "postgres.exe -D ... < nul >> start.log 2>&1" =E2= =86=90 console window! =E2=86=92 postgres.exe The theseus-rs crate already applies CREATE_NO_WINDOW (0x08000000) to its CreateProcess call when spawning pg_ctl.exe, so the parent=E2=86=92pg_ctl ed= ge was clean. The flash came from pg_ctl.exe itself spawning cmd.exe. ## Root cause File: src/bin/pg_ctl/pg_ctl.c Lines 510-511 explain the design choice: "As with the Unix case, it's easiest to use the shell (CMD.EXE) to handle redirection etc." The command is constructed at lines 557-561: cmd =3D psprintf("\"%s\" /C \"\"%s\" %s%s < \"%s\" >> \"%s\" 2>&1\"", comspec, exec_path, pgdata_opt, post_opts, DEVNULL, log_file); It is launched via CreateRestrictedProcess() at line 1846: r =3D CreateProcessAsUser(restrictedToken, NULL, cmd, NULL, NULL, TRUE, CREATE_SUSPENDED, // <-- no CREATE_NO_WINDOW NULL, NULL, &si, processInfo); Since cmd.exe is a CUI binary (subsystem 3), Windows allocates a new console for it on every CreateProcess call. The parent's own CREATE_NO_WINDOW flag does not propagate to grandchildren. ## Proposed fix Option A (minimal, one flag): Add CREATE_NO_WINDOW (0x08000000) to dwCreationFlags: r =3D CreateProcessAsUser(restrictedToken, NULL, cmd, NULL, NULL, TRUE, CREATE_SUSPENDED | CREATE_NO_WINDOW, NULL, NULL, &si, processInfo); Option B (eliminate cmd.exe dependency): Use native CreateProcess handle inheritance (hStdInput/hStdOutput/hStdError in STARTUPINFO) for I/O redirection, removing the need for cmd.exe /C entirely. This would also eliminate the dependency on COMSPEC being set. ## Impact Any application that launches PostgreSQL via pg_ctl from a headless or background context sees an unexpected console flash on every start. This affects embedded databases, CI/CD pipelines, IDE-integrated PostgreSQL instances, and tools using libraries like pg0, theseus-rs/postgresql-embedded, and zonkyio/embedded-postgres. ## System details - OS: Windows 11 (22H2+, ConPTY enabled) - PostgreSQL version tested: 18 (bundled via pg0 v0.14.2) - The code path in pg_ctl.c is substantially unchanged across versions We are happy to test a patch if one is drafted. Thank you for your work on this excellent project. Best regards, Yuebei Wang