tds-fdw / tds_fdw

A PostgreSQL foreign data wrapper to connect to TDS databases (Sybase and Microsoft SQL Server)
Other
377 stars 101 forks source link

Specify Schema name during connection (SQL Anywhere Error -83: Specified Database not found) #359

Open cmrwy opened 3 months ago

cmrwy commented 3 months ago

Issue report

The following information is very important in order to help us to help you. Omission of the following details cause delays or could receive no attention at all.

Operating system

On recent GNU/Linux distributions, you can provide the content of the file /etc/os-release

Ubuntu 20.04 LTS in Docker Container (Supabase Postgres as base image)

Version of tds_fdw

From a psql session, paste the outputs of running \dx

If you built the package from Git sources, also paste the output of running git log --source -n 1 on your git clone from a console

postgres=# \dx
                                                 List of installed extensions
        Name        | Version |   Schema   |                                    Description                                    
--------------------+---------+------------+-----------------------------------------------------------------------------------
 pg_graphql         | 1.5.4   | graphql    | pg_graphql: GraphQL support
 pg_stat_statements | 1.10    | extensions | track planning and execution statistics of all SQL statements executed
 pgcrypto           | 1.3     | extensions | cryptographic functions
 pgjwt              | 0.2.0   | extensions | JSON Web Token API for Postgresql
 pgsodium           | 3.1.8   | pgsodium   | Pgsodium is a modern cryptography library for Postgres.
 plpgsql            | 1.0     | pg_catalog | PL/pgSQL procedural language
 supabase_vault     | 0.2.8   | vault      | Supabase Vault Extension
 tds_fdw            | 2.0.3   | public     | Foreign data wrapper for querying a TDS database (Sybase or Microsoft SQL Server)
 uuid-ossp          | 1.1     | extensions | generate universally unique identifiers (UUIDs)
(9 rows)

Version of PostgreSQL

From a psql session, paste the output of running SELECT version();

postgres=# select version();
                                                              version                                                              
-----------------------------------------------------------------------------------------------------------------------------------
 PostgreSQL 15.1 (Ubuntu 15.1-1.pgdg20.04+1) on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0, 64-bit
(1 row)

Version of FreeTDS

How to get it will depend on your Operating System and how you installes FreeTDS

From a console:

ii  freetds-common                     1.1.6-1.1                         all          configuration files for FreeTDS SQL client libraries
ii  freetds-dev                        1.1.6-1.1                         amd64        MS SQL and Sybase client library (static libs and headers)

Logs

Please capture the logs when the error you are reporting is happening, as well as commands with their outputs if you are reporting a problem build or installing

_For problems using tdsfdw on PostgreSQL how to do it will depend on your system, but if your PostgreSQL is installed on GNU/Linux, you will want to use tail -f with the log of the PostgreSQL cluster

For MSSQL you will need to use the SQL Server Audit Log

postgres=# select * from myfdwtable;
NOTICE:  DB-Library notice: Msg #: 911, Msg state: 0, Msg: SQL Anywhere-Fehler -83: Angegebene Datenbank nicht gefunden, Server: [x.x.x.x:2638], Process: , Line: 0, Level: 16
ERROR:  DB-Library error: DB #: 20002, DB Msg: Adaptive Server connection failed (x.x.x.x:2638), OS #: 0, OS Msg: Success, Level: 9

Sentences, data structures, data

This will depend on the exact problem you are having and data privacy restrictions

However the more data you provide, the more likely we will be able to help

As a bare minimum, you should provide

create extension tds_fdw;
create server remotedb foreign data wrapper tds_fdw options (servername 'x.x.x.x', database 'MYDB', msg_handler 'notice');
create user mapping for supabase_admin server remotedb options (username 'myuser', password 'mypass');
create foreign table myfdwtable (ID integer, Col1 varchar, Col2 varchar) server remotedb options (table_name 'tMySybaseTable');
select * from myfdwtable; -- Fails with error above in logs section

I also tried connecting with DBeaver using the jTDS driver, which fails with the same error, but using the jConnect Driver succeeds.

I spun up a SQL Anywhere 17 Dev Server and jTDS works there, but only shows the DBA schema, while jConnect shows another level (Catalog with all schemas inside). I feel like this default value is the issue or at least contributes to it.

Is there a way to specify a schema name in the tds_fdw options (or the catalog)?

jTDS: Bildschirmfoto 2024-06-17 um 11 24 26

jConnect: Bildschirmfoto 2024-06-17 um 11 24 50 Bildschirmfoto 2024-06-17 um 11 25 30

Bildschirmfoto 2024-06-17 um 11 26 58