Cannot find a usable libpq.dll

[expired user #8358]'s profile image [expired user #8358] posted 9 years ago in Creating a connection Permalink

I saw from the forums that this was an issue a while ago, but I'm getting it again with the latest builds of HeidiSQL and a clean install of Windows 10.

The error dialog states "Cannot find a usable libpq.dll. Please launch heidisql.exe from a directory where you installed it.

  • I've verified that that libpq, libeasy 32, and ssleay32 .dlls are all present.
  • I am launching from the directory that I installed it.
  • I tried it from both the Program Files directory and installed in a non-protected directory.
  • It occurs whether I try to run as Administrator or not.
  • This is the 64 bit version of Windows 10.
  • I've seen this issue now from any clean install of Windows 10, whether through VirtualBox or natively on a new PC.

Any tips or ideas on how to work around this?

ansgar's profile image ansgar posted 9 years ago Permalink

Can you please - just for testing purposes - download and run the portable version of HeidiSQL? The portable version just contains the 32bit version of heidisql.exe and all .dll's. So we can probably track down the problem to 32/64bit.

[expired user #8358]'s profile image [expired user #8358] posted 9 years ago Permalink

Just tried, and I'm getting the same error, unfortunately.

ansgar's profile image ansgar posted 9 years ago Permalink

Heidi loads libpq.dll without a path, so that might be a problem when there is a different libpq.dll somewhere else in the %path%. I could try and let Heidi load libpq.dll from exactly the folder where the current heidisql.exe is running from.

Code modification/commit bdddc72 from ansgarbecker, 9 years ago, revision 9.3.0.5065
Load libpq.dll with full path, so the LoadLibrary does not accidentally take a different (probably wrong) one from somewhere else than the current directory. See http://www.heidisql.com/forum.php?t=21039
ansgar's profile image ansgar posted 9 years ago Permalink

Please try that in r5065.

[expired user #8358]'s profile image [expired user #8358] posted 9 years ago Permalink

I tried 5065 - still getting the same error.

I also tried adding the HeiSQL path to my PATH environment variables - still the same result.

Not sure why this is happening now - the version I run at home (which I installed a long while ago, but have used the update process to keep current) runs just fine there. When I moved that full install directory to the new machine, I get the same error. (But that doesn't cover any confounding variables, like other software or Postgres server installed at home.)

Code modification/commit cd35370 from ansgarbecker, 9 years ago, revision 9.3.0.5066
Attempt to add a helpful error message to the error dialog when libpq.dll was not loaded. http://www.heidisql.com/forum.php?t=21039
ansgar's profile image ansgar posted 9 years ago Permalink

Sorry for the mess. Got no more ideas currently, only I know you're not the only one having this issue: http://www.heidisql.com/forum.php?t=18580 http://www.heidisql.com/forum.php?t=20693

r5066 adds the last system error message to the "cannot find a usable libpq.dll" dialog. Probably this is helpful for finding some error here. Please update again.

[expired user #8358]'s profile image [expired user #8358] posted 9 years ago Permalink

I tried version 5066 on fresh install for Windows 10 Pro x64 (only other thing installed are VirtualBox extensions), but still got the same error, with the additional info that "The operation completed successfully".

I ran Sysinternal Process Monitor on my working machine and the new machine, and have attached screenshots of the results. If you'd like a stack trace of any particular call, I can also attach those.

2 attachment(s):
  • working_pgsql_proc_calls
  • broken_libpq_proc_calls
ansgar's profile image ansgar posted 9 years ago Permalink

Looks like the dll was loaded but the result of LoadLibrary() is 0 anyway, which normally means: dll could not be loaded. So, I could just check the existence of libpq.dll without checking the result of LoadLibrary. This evening...

Code modification/commit 4645c38 from ansgarbecker, 9 years ago, revision 9.3.0.5067
Load libpq.dll after just checking if it exists. Do not check what LoadLibrary returns. This is quite risky, but there seem to be cases where LoadLibrary returns 0 although libpq.dll was loaded. See http://www.heidisql.com/forum.php?t=21039
ansgar's profile image ansgar posted 9 years ago Permalink

r5067 now does only a FileExists() check on libpq.dll in the HeidiSQL directory. No check for what LoadLibrary() returns. This can cause crashes but it may also fix this issue.

[expired user #8358]'s profile image [expired user #8358] posted 9 years ago Permalink

Sorry, no luck on 5067 either. This is really confusing to me.

It now says, "Your libpq.dll is out-dated or somehow incompatible to HeidiSQL. Please use the one from the installer, or just reinstall HeidiSQL."

(Got this from both manually downloading and adding the 5067 x64 executable, and then uninstalling and doing a fresh install with the 5067 isntaller.)

ansgar's profile image ansgar posted 9 years ago Permalink

With the latest build, could you activate debug logging (in Tools > Preferences > Logging), then connect to some working (maybe MySQL or MSSL) session, then attempt to connect to your PostgreSQL server. The log should display now a number of such lines:

Assign procedure "PQconnectdb"

I guess it will just be one of these lines, but just to be sure it's not some special procedure which is not working.

[expired user #8358]'s profile image [expired user #8358] posted 9 years ago Permalink

Haven't tried iwth local MySQL yet, but will in a second. Getting this from Postgres:

/* 2016-04-06 12:13:15 [DB] */ /* Loading library file C:\Program Files\HeidiSQL\libpq.dll ... */
/* 2016-04-06 12:13:15 [DB] */ /* Assign procedure "PQconnectdb" */
/* 2016-04-06 12:13:15 [DB] */ /* Library error in libpq.dll: Could not find procedure address for "PQconnectdb" */
[expired user #8358]'s profile image [expired user #8358] posted 9 years ago Permalink

MySQL is working fine. Sometimes, my Postgres connection stop logging before it gets to the end of its output:

/* 2016-04-06 12:19:14 [] */ /* Writing to session log file now: Z:\heidisql.log\000003.log */
/* 2016-04-06 12:19:14 [] */ /* Setting up TSynMemo "SynMemoQuery" */
/* 2016-04-06 12:19:14 [] */ /* Setting up TSynMemo "SynMemoFilter" */
/* 2016-04-06 12:19:14 [] */ /* Setting up TSynMemo "SynMemoProcessView" */
/* 2016-04-06 12:19:14 [] */ /* Setting up TSynMemo "SynMemoSQLLog" */
/* 2016-04-06 12:20:23 [MySQL Test] */ /* Loading library file libmysql.dll ... */
/* 2016-04-06 12:20:23 [MySQL Test] */ /* Assign procedure "mysql_affected_rows" */
...
/* 2016-04-06 12:20:23 [MySQL Test] */ /* libmysql.dll v5.6.6-m9 loaded. */
/* 2016-04-06 12:20:23 [MySQL Test] */ /* Connecting to 172.16.26.87 via MySQL (TCP/IP), username root, using password: Yes ... */
...
/* 2016-04-06 12:20:47 [] */ /* DBtreeFocusChanged without node. */
/* 2016-04-06 12:20:52 [PGDB] */ /* Loading library file C:\Program Files\HeidiSQL\libpq.dll ... */
/* 2016-04-06 12:20:52 [AMG [dev vm]] */ /* Library error in libpq.dll: Could not find procedure address for "PQconnectdb" */
[tried to connect again]
/* 2016-04-06 12:23:00 [AMG [dev vm]] */ /* Loading library file C:\Program Files\HeidiSQL\libpq.dll ... */
/* 2016-04-06 12:23:00 [AMG [dev vm]] */ /* Assign procedure "PQconnectdb" */
/* 2016-04-06 12:23:00 [AMG [dev vm]] */ /* Library error in libpq.dll: Could not find
ansgar's profile image ansgar posted 9 years ago Permalink

Hm, well, that still means the dll cannot be loaded.

I should definitely check if I mixed up the 32/64bit libpq.dll's in the installer...

If you have the time you can try to copy libpq.dll from the Windows PostgreSQL server download. I will do the same this evening.

[expired user #8358]'s profile image [expired user #8358] posted 9 years ago Permalink

Tried replacing with the libpq version that ships with the latest pgAdmin III - still not luck.

I tried with the 64 & 32-bit (only) HeidiSQL installers, got the same error message about loading the .dll.

[expired user #8358]'s profile image [expired user #8358] posted 9 years ago Permalink

I just tried a bunch more combinations - and finally got it to work! But it requires replacing every one of the library .dlls with a more recent version. (Or versions that know about each other?)

Here's what I did:

  1. Tried copying the heidisql.exe (64-bit version) into my PostgreSQL\9.5\bin directory (I did a fresh 9.5.2 Windows server install); running Heidi from there worked!
  2. Tried copying the same .exe plus 4 .dlls from PostgreSQL\9.5\bin (libeay32, libintl-8, libpq, and ssleay32) to own, new directory - it didn't work. (got same error as always)
  3. Copied .dlls one by one from Posgres\9.5\bin to the new directory - it worked after I added libiconv-2.dll
  4. Tried copying only libiconv-2.dll to my original HeidiSQL location - that didn't work.
  5. Replaced, one by one, the other 4 .dlls - none of them helped, and I only once got another error about a dll not finding a symbol it expected. Once all original .dlls were replaced, and libiconv-2 was added (just like in #3), it finally worked from original install location.
ansgar's profile image ansgar posted 9 years ago Permalink

Oh man, thanks for your effort and consistent feedback :)

So, libiconv-2.dll is missing and all other dlls should be updated if I understand right. Will check that here as soon as I can.

[expired user #8358]'s profile image [expired user #8358] posted 9 years ago Permalink

You're welcome - I'm really glad for the tool you've made and continue to work on!

And your summary is correct, and a much more succinct way to summarize what I found. :)

Disclaimer: I only tested those results with the 64-bit version of Heidi and the 64-bit dlls from the Postgres install. But it worked again fine when I re-did the steps on my office machine.

Code modification/commit 91cefe7 from ansgarbecker, 9 years ago, revision 9.3.0.5068
Update all PostgreSQL libraries, add missing libiconv-2.dll, unify filename of 32bit version of libintl.dll (=> libintl-8.dll), and finally revert the previous 3 commits, which hopefully are not required with these updates. See http://www.heidisql.com/forum.php?t=21039
ansgar's profile image ansgar posted 9 years ago Permalink

So, all above mentioned changes done in r5068. Also, I reverted the previous 3 commits, as I think these changes did not help anyway and they are most likely not required any longer.

For me it (still) works, also with a fresh install of the 64bit installer.

[expired user #8358]'s profile image [expired user #8358] posted 9 years ago Permalink

Yep, 5068 just worked for me on a fresh install!

ansgar's profile image ansgar posted 9 years ago Permalink

Coool! :)

I'm gonna have 3 or 4 beers on that this evening.

ansgar's profile image ansgar posted 5 years ago Permalink

I just refreshed PostgreSQL libraries for the next installer. See issue #831. I removed the old v9.5 libpq.dll and added v10.0.11 and v12.0.1 .

If you want you can try these in the nightly built installer.

Please login to leave a reply, or register at first.