Python 测试.postgresql 错误:initdb 需要程序“postgres”

问题描述 投票:0回答:2
我们有一些使用testing.posgresql的python单元测试,但是我无法让它们在我的机器(Windows 10)上为我工作。我收到上面关于 initdb 需要 postgresql 但无法在同一目录中找到它的错误。我可以确认它们都位于 PostgresSQL 安装的 bin 目录中,并且在该目录中尝试直接运行 initdb 时遇到相同的错误。此安装的 bin 和 lib 目录也在我的路径中,并且在运行

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
    
python database windows postgresql
2个回答
0
投票
我也遇到了同样的问题,对我来说,原因是 Windows 上安装了不同的 postgres

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")
    

-1
投票
我无法对您的帖子发表评论:但是,我一直在尝试在我的服务器上安装 PostgreSQL 14,该服务器已经在运行 PostgreSQL 12。我看到了与“radEA2DE.bat”相关的相同错误。 这是我的安装日志中的相关代码块:

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
我希望这有助于提供线索。

© www.soinside.com 2019 - 2024. All rights reserved.