I am trying to set up unixODBC to access a Postgres server from multiple (Intel) Mac computers.
The first two machines have unixodbc
and psqlodbc
installed using Homebrew. I have tested it using this command:
iusql ";Driver=PostgreSQL;Server=172.16.66.30;Port=5432;UID=moshe;Database=appdb;" -v
One is working perfectly, and the other is showing the following error:
[unixODBC][Driver Manager]Data source name not found and no default driver specified
[ISQL]ERROR: Could not SQLDriverConnect
I have compared the Homebrew-installed files on both machines, and they are identical. I have run odbcinst -j
and confirmed that both machines are looking at the same files. The only relevant config file for this test (since I'm not using a named connection) is the drivers file at /usr/local/etc/odbcinst.ini
which has the following contents on both machines:
[PostgreSQL]
Description = PostgreSQL ODBC driver (Unicode 13)
Driver = /usr/local/lib/psqlodbcw.so
CommLog = 1
UsageCount = 1
Running odbcinst -q -d -n PostgreSQL
on both machines confirms that the above information is set correctly.
Why am I getting this error on one machine?
This error seems to be a bug in unixODBC. If the /usr/local/etc/odbc.ini
and $HOME/.odbc.ini
files are both empty, this error occurs. If one of those files has a datasource defined (even a non-functional placeholder), the iusql
command works properly. This is true even though the man page says:
A string DSN:
A string DSN may be provided in its entirety, with no file DSN reference at all:
$ iusql ";Driver=PostgreSQL Unicode;UID=MyID;PASSWORD=secret" -v
which should mean that no DSN is required in the config files either.
Here is the simplest code to put in $HOME/.odbc.ini
to get rid of the error:
[placeholder]
Driver = PostgreSQL