which initdb
或
which postgres
时获得了正确的位置我已经尝试了一些方法,包括在具有类似问题的线程中提出的所有解决方案,但没有任何效果,它适用于 macOS 和我们的 github 工作流程。我安装了 PostgresSQL 14 并且正在使用 cygwin (尽管在 Windows cmd 中运行时出现完全相同的错误),感谢任何帮助。从 Postgres 安装的 bin 目录运行 initdb 时的输出:
$ ./initdb -D example
The system cannot find the path specified.
child process exited with exit code 1
initdb: error: The program "postgres" is needed by initdb but was not found in the
same directory as "C:/Program Files/PostgreSQL/14/bin/initdb.exe".
Check your installation.
但是一个简单的 ls 显示 postgres.exe 确实存在:
$ ls
clusterdb.exe icutu67.dll libiconv-2.dll libxslt.dll pg_dump.exe pg_restore.exe psql.exe wxmsw313u_core_vc_x64_custom.dll
createdb.exe icuuc67.dll libintl-9.dll oid2name.exe pg_dumpall.exe pg_rewind.exe reindexdb.exe wxmsw313ud_aui_vc_x64_custom.dll
createuser.exe initdb.exe liblz4.dll pg_amcheck.exe pg_isolation_regress.exe pg_test_fsync.exe stackbuilder.exe wxmsw313ud_html_vc_x64_custom.dll
dropdb.exe isolationtester.exe libpgtypes.dll pg_archivecleanup.exe pg_isready.exe pg_test_timing.exe vacuumdb.exe wxmsw313ud_xrc_vc_x64_custom.dll
dropuser.exe libcrypto-1_1-x64.dll libpq.dll pg_basebackup.exe pg_receivewal.exe pg_upgrade.exe vacuumlo.exe zic.exe
ecpg.exe libcurl.dll libpq_pipeline.exe pg_checksums.exe pg_recvlogical.exe pg_verifybackup.exe wxbase313u_vc_x64_custom.dll zlib1.dll
icudt67.dll libcurl.lib libssl-1_1-x64.dll pg_config.exe pg_regress.exe pg_waldump.exe wxbase313u_xml_vc_x64_custom.dll
icuin67.dll libecpg.dll libwinpthread-1.dll pg_controldata.exe pg_regress_ecpg.exe pgbench.exe wxbase313ud_net_vc_x64_custom.dll
icuio67.dll libecpg_compat.dll libxml2.dll pg_ctl.exe pg_resetwal.exe postgres.exe wxmsw313u_adv_vc_x64_custom.dll
PATH
。这使得 initdb 的路径由我所有 postgres 安装的所有 initdb.exe 的路径组成,并用
\r\n
分隔。由于使用哪种安装对我来说并不重要,因此以下几行解决了我的问题:
def find_path(name: str) -> str:
program_path = testing.postgresql.find_program(name, [])
return program_path.split("\r\n")[0]
initdb = find_path("initdb")
postgres = find_path("postgres")
Called IsVistaOrNewer()...
'winmgmts' object initialized...
Version:10.
MajorVersion:10
Granting full access to Administrators on (D:\pgData14)
Executing batch file 'radEA2DE.bat'...
processed file: D:\pgData14
Successfully processed 1 files; Failed processing 0 files
Executing batch file 'radEA2DE.bat'...
initdb: error: The program "postgres" was found by "C:/Program Files/PostgreSQL/14/bin/initdb.exe"
but was not the same version as initdb.
Check your installation.
Called Die(Failed to initialise the database cluster with initdb)...
Failed to initialise the database cluster with initdb
Script stderr:
Program ended with an error exit code
Error running C:\WINDOWS\System32\cscript //NoLogo "C:\Program Files\PostgreSQL\14/installer/server/initcluster.vbs" "NT AUTHORITY\NetworkService" "postgres" "****" "C:\Users\USER\AppData\Local\Temp/postgresql_installer_3f464cf94c" "C:\Program Files\PostgreSQL\14" "D:\pgData14" 5433 "DEFAULT" 0: Program ended with an error exit code
Problem running post-install step. Installation may not complete correctly
The database cluster initialisation failed.
Setting variable whoami from C:\WINDOWS\System32\whoami
Script exit code: 0
我希望这有助于提供线索。