Configuring PostgreSQL ODBC connector
apt-get install unixodbc odbc-postgresql
Add the following line into /etc/odbcinst.ini
[Postgres] Description = Postgres Driver = /usr/lib/odbc/psqlodbc.so Driver64 = /usr/lib Setup = /usr/lib/odbc/libodbcpsqlS.so Setup64 = /usr/lib UsageCount = 1 CPTimeout = CPReuse =Add the following DSN into /etc/odbc.ini
[test] Description = test Driver = Postgres Trace = No TraceFile = Database = test Servername = localhost Username = Password = Port = 5432 Protocol = 6.4 ReadOnly = No RowVersioning = No ShowSystemTables = No ShowOidColumn = No FakeOidIndex = No ConnSettings =
NOTE that the hostname is called servername here! If you use a standard hostname, the driver will connect to a socket, not the inet and you get a “connection refused” message.
- The DNS-less connection string to PostgreSQL (don’t need step 3 then) would be:
"Driver=Postgres;Database=test;Servername=localhost;Port=5432;Username=test;Password=xxxx;"
NOTE: It’s error-prone and hell to debug.
- Driver should not be in curly braces {} (should be according to the spec).
- Absolutely no spaces anywhere (should be ok according to the spec).
- Error messages are not very informative as it fails silently and calls another connection methos producing “Data source name not found, and no default driver specified”
A useless pointer: DSN-less connection strings – discussed here.