<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>SQL Server on Mimus</title><link>https://mimus.pgsty.com/docs/mssql/</link><description>Recent content in SQL Server on Mimus</description><generator>Hugo</generator><language>en-US</language><atom:link href="https://mimus.pgsty.com/docs/mssql/index.xml" rel="self" type="application/rss+xml"/><item><title>Known limits and troubleshooting</title><link>https://mimus.pgsty.com/docs/mssql/status/</link><guid>https://mimus.pgsty.com/docs/mssql/status/</guid><description>&lt;h2 id="login"&gt;The PG port works, but the TDS client cannot log in&#10;&lt;/h2&gt;&#10;&lt;div class="td-table-scroll td-table-scroll--static"&gt;&#10;&lt;table&gt;&#10; &lt;thead&gt;&#10; &lt;tr&gt;&#10; &lt;th scope="col"&gt;Symptom&lt;/th&gt;&#10; &lt;th scope="col"&gt;What to check&lt;/th&gt;&#10; &lt;th scope="col"&gt;Action&lt;/th&gt;&#10; &lt;/tr&gt;&#10; &lt;/thead&gt;&#10; &lt;tbody&gt;&#10; &lt;tr&gt;&#10; &lt;td&gt;Connection refused, or the client sees a protocol error immediately&lt;/td&gt;&#10; &lt;td&gt;&lt;code&gt;psql&lt;/code&gt; speaks PG. &lt;code&gt;tsql&lt;/code&gt; speaks TDS. The sockets use different ports.&lt;/td&gt;&#10; &lt;td&gt;In native &lt;code&gt;psql&lt;/code&gt; as the DBA, inspect &lt;code&gt;SHOW shared_preload_libraries&lt;/code&gt;, &lt;code&gt;SHOW listen_addresses&lt;/code&gt; and &lt;code&gt;SHOW babelfishpg_tds.port&lt;/code&gt;. Check the startup log for a bind failure. After changing the listener, restart and connect to the TDS port explicitly.&lt;/td&gt;&#10; &lt;/tr&gt;&#10; &lt;tr&gt;&#10; &lt;td&gt;&lt;code&gt;unsupported TDS authentication&lt;/code&gt;&lt;/td&gt;&#10; &lt;td&gt;A broader HBA entry may select &lt;code&gt;scram-sha-256&lt;/code&gt;. &lt;code&gt;localhost&lt;/code&gt; can resolve to &lt;code&gt;::1&lt;/code&gt; and miss an IPv4-only rule.&lt;/td&gt;&#10; &lt;td&gt;Inspect the server-reported database, role and source address. Match the &lt;strong&gt;physical&lt;/strong&gt; database and the correct subnet with a supported HBA method. Put that rule first, reload and reconnect.&lt;/td&gt;&#10; &lt;/tr&gt;&#10; &lt;tr&gt;&#10; &lt;td&gt;Login succeeds only with certificate validation disabled&lt;/td&gt;&#10; &lt;td&gt;The CA may be missing, or the client may use a name absent from the certificate. A stricter driver may also request an unsupported protocol version.&lt;/td&gt;&#10; &lt;td&gt;Install the issuing CA on the client, use the certificate hostname and verify the negotiated TLS version on the same session. &lt;a href="https://mimus.pgsty.com/docs/mssql/connect/#tls"&gt;Tested TLS settings&lt;/a&gt;&lt;/td&gt;&#10; &lt;/tr&gt;&#10; &lt;tr&gt;&#10; &lt;td&gt;Initialization reports a reserved role or says the supplied login is not the owner&lt;/td&gt;&#10; &lt;td&gt;Initialization creates cluster roles and checks the physical database owner. The same cluster may already host an initialized Babelfish database.&lt;/td&gt;&#10; &lt;td&gt;Inspect the owner and existing roles in PG. Connect to the intended physical database. Use the existing mapping or start a fresh cluster when an independent mapping is needed. Preserve roles already in use.&lt;/td&gt;&#10; &lt;/tr&gt;&#10; &lt;tr&gt;&#10; &lt;td&gt;The application connects but cannot find a table&lt;/td&gt;&#10; &lt;td&gt;The driver may have selected &lt;code&gt;master&lt;/code&gt;, or a native query may be using a logical schema name.&lt;/td&gt;&#10; &lt;td&gt;Check &lt;code&gt;DB_NAME()&lt;/code&gt; on TDS and &lt;code&gt;current_database()&lt;/code&gt; on PG. Look up the catalog mapping and check the database user’s grants. &lt;a href="https://mimus.pgsty.com/docs/mssql/mapping/#lookup"&gt;Name lookup&lt;/a&gt;&lt;/td&gt;&#10; &lt;/tr&gt;&#10; &lt;/tbody&gt;&#10;&lt;/table&gt;&#10;&lt;/div&gt;&#10;&#10;&lt;h2 id="temporary"&gt;Permanent tables work, temporary objects fail&#10;&lt;/h2&gt;&#10;&lt;p&gt;With an effective default of &lt;code&gt;tde_heap&lt;/code&gt;, all three T-SQL temporary objects fail at creation. The 2601 in &lt;code&gt;Unexpected catalog OID 2601 referenced in ENR&lt;/code&gt; identifies &lt;code&gt;pg_am&lt;/code&gt;. On the actual TDS connection, check both &lt;code&gt;default_table_access_method&lt;/code&gt; and &lt;code&gt;pg_tde.enforce_encryption&lt;/code&gt;. Use &lt;code&gt;heap/off&lt;/code&gt; for a runtime login that needs temporary objects and recycle its physical pool connections. All three objects then work, and their data can reach disk in plaintext. &lt;a href="https://mimus.pgsty.com/docs/mssql/temporary-storage/#settings"&gt;Runtime settings and rollback results&lt;/a&gt;&lt;/p&gt;</description></item><item><title>Migration and operations</title><link>https://mimus.pgsty.com/docs/mssql/operations/</link><guid>https://mimus.pgsty.com/docs/mssql/operations/</guid><description>&lt;h2 id="migration"&gt;Move a SQL Server application&#10;&lt;/h2&gt;&#10;&lt;ol&gt;&#10;&lt;li&gt;For a source supplied as a SQL Server .bak file, restore it in SQL Server first. Export the application DDL, including procedures, triggers, logins, users and grants. Inventory SQL generated by the driver as well. Babelfish Compass can flag constructs for review. Validate the flagged paths and the application’s own queries on the matching Mimus build. &lt;a href="https://babelfishpg.org/docs/usage/migration/"&gt;Babelfish migration guide&lt;/a&gt;&lt;/li&gt;&#10;&lt;li&gt;Choose the mapping mode and collation for the target. Create the user database and its principals through TDS. Replay the DDL in dependency order. For a procedure, check the result sets, types and return status the caller consumes. Review ignored or rewritten clauses individually before accepting a successful import.&lt;/li&gt;&#10;&lt;li&gt;Copy a representative batch with the intended driver. Compare counts by primary-key range, NULL counts, totals and values that can round or truncate. Check identity/sequence state for the next insert. Compare rows through TDS and native PG using the &lt;a href="https://mimus.pgsty.com/docs/mssql/mapping/#lookup"&gt;physical schema mapping&lt;/a&gt;.&lt;/li&gt;&#10;&lt;li&gt;Rehearse cutover at a consistent point. Stop source writes or capture and apply outstanding changes. Run the application under its normal login, check transactions and reconcile both sides before redirecting writers. Retain the source and record how to reconcile any writes accepted after cutover.&lt;/li&gt;&#10;&lt;/ol&gt;&#10;&lt;h2 id="coexistence"&gt;Choose the instance boundary&#10;&lt;/h2&gt;&#10;&lt;p&gt;Run TDS alongside native PostgreSQL. Give MySQL a separate instance and data directory, including when the two applications use different logical databases. Each instance shares preloads, roles and startup requirements across its databases. &lt;a href="https://mimus.pgsty.com/docs/intro/architecture/#connections"&gt;Connection architecture&lt;/a&gt;&lt;/p&gt;</description></item><item><title>Temporary tables, table variables and plaintext on disk</title><link>https://mimus.pgsty.com/docs/mssql/temporary-storage/</link><guid>https://mimus.pgsty.com/docs/mssql/temporary-storage/</guid><description>&lt;p&gt;&lt;strong&gt;A runtime login with &lt;code&gt;heap&lt;/code&gt; and enforcement off can read and write encrypted permanent tables and use table variables, &lt;code&gt;#&lt;/code&gt; tables and &lt;code&gt;SELECT INTO #&lt;/code&gt; on the same TDS connection.&lt;/strong&gt; The Mimus 19.0.1 candidate with the four accepted changes allows these temporary objects to reach disk in plaintext. Copying a row from an encrypted permanent table to a temporary table can put a plaintext copy in a file. &lt;a href="https://mimus.pgsty.com/docs/mssql/encrypted-tables/"&gt;Deploy encrypted permanent tables&lt;/a&gt;&lt;/p&gt;</description></item><item><title>Create encrypted permanent tables over TDS</title><link>https://mimus.pgsty.com/docs/mssql/encrypted-tables/</link><guid>https://mimus.pgsty.com/docs/mssql/encrypted-tables/</guid><description>&lt;p&gt;A SQL Server client can create an encrypted permanent table on Mimus with an ordinary &lt;code&gt;CREATE TABLE&lt;/code&gt;. The DBA supplies the key and the creation default. Applications then use their usual &lt;code&gt;INSERT&lt;/code&gt;, &lt;code&gt;UPDATE&lt;/code&gt; and &lt;code&gt;SELECT&lt;/code&gt;. A migration can also select encryption for a single transaction. This guide covers the 19.0.1 candidate with the four accepted changes, tested over TDS 7.4 on Debian 13 x86-64 image &lt;code&gt;a3b80a5a99a1&lt;/code&gt;. &lt;a href="https://mimus.pgsty.com/docs/patches/mssql/#tde-increments"&gt;Identify the build and patches&lt;/a&gt;&lt;/p&gt;</description></item><item><title>T-SQL and client compatibility</title><link>https://mimus.pgsty.com/docs/mssql/compatibility/</link><guid>https://mimus.pgsty.com/docs/mssql/compatibility/</guid><description>&lt;h2 id="clients"&gt;Which client operation was tested?&#10;&lt;/h2&gt;&#10;&lt;div class="td-table-scroll td-table-scroll--static"&gt;&#10;&lt;table&gt;&#10; &lt;thead&gt;&#10; &lt;tr&gt;&#10; &lt;th scope="col"&gt;Client or API&lt;/th&gt;&#10; &lt;th scope="col"&gt;Observed result&lt;/th&gt;&#10; &lt;th scope="col"&gt;What to check for an application&lt;/th&gt;&#10; &lt;/tr&gt;&#10; &lt;/thead&gt;&#10; &lt;tbody&gt;&#10; &lt;tr&gt;&#10; &lt;td&gt;FreeTDS 1.5.18 &lt;code&gt;tsql&lt;/code&gt;, TDS 7.4&lt;/td&gt;&#10; &lt;td&gt;On the matching Rocky x86-64 build, password login, logical database selection, table DDL, two-row DML, a procedure call and TLS 1.2 worked.&lt;/td&gt;&#10; &lt;td&gt;Run the actual result sets and parameter types through the driver used in production.&lt;/td&gt;&#10; &lt;/tr&gt;&#10; &lt;tr&gt;&#10; &lt;td&gt;Microsoft JDBC 8.2.2.jre8 &lt;code&gt;SQLServerBulkCopy&lt;/code&gt;&lt;/td&gt;&#10; &lt;td&gt;On a preceding integrated PG19 build with the same Babelfish extension tree, two integers reached an encrypted table. PG read 2 and 40. The bulk test used &lt;code&gt;databaseName=master;encrypt=false&lt;/code&gt; on loopback.&lt;/td&gt;&#10; &lt;td&gt;Check server-side row counts and values. Re-test with the deployed JDBC version, TLS settings and real column types.&lt;/td&gt;&#10; &lt;/tr&gt;&#10; &lt;tr&gt;&#10; &lt;td&gt;FreeTDS 1.3.17 &lt;code&gt;freebcp&lt;/code&gt;&lt;/td&gt;&#10; &lt;td&gt;On the standalone PG19 port and upstream beta, the utility reported two rows copied. The server rejected the bulk packet and stored zero.&lt;/td&gt;&#10; &lt;td&gt;Reconcile counts on the target. Use the exercised JDBC bulk path or parameterized inserts after testing them with the application.&lt;/td&gt;&#10; &lt;/tr&gt;&#10; &lt;tr&gt;&#10; &lt;td&gt;&lt;code&gt;sqlcmd&lt;/code&gt;, SSMS, .NET SqlClient, ODBC and Python drivers&lt;/td&gt;&#10; &lt;td&gt;Upstream documents SQL Server clients. There is no complete application or driver-suite result for these tools on this Mimus build.&lt;/td&gt;&#10; &lt;td&gt;Check prepared RPCs, output parameters, result-set metadata, connection pooling and reset, cancellation and reconnect with the exact client version.&lt;/td&gt;&#10; &lt;/tr&gt;&#10; &lt;/tbody&gt;&#10;&lt;/table&gt;&#10;&lt;/div&gt;&#10;&#10;&lt;h2 id="procedures"&gt;Procedures and batches&#10;&lt;/h2&gt;&#10;&lt;p&gt;In FreeTDS &lt;code&gt;tsql&lt;/code&gt; as &lt;code&gt;bbf_admin&lt;/code&gt; in &lt;code&gt;master&lt;/code&gt;, after the &lt;a href="https://mimus.pgsty.com/docs/mssql/connect/#first-login"&gt;two-row example&lt;/a&gt;, submit the definition and invocation as separate batches. The integer parameter &lt;code&gt;1&lt;/code&gt; returned &lt;code&gt;amount = 40&lt;/code&gt; and return status 0. This exercises a T-SQL call sent as a SQL batch. Driver RPC calls, output parameters and multiple results take additional client paths.&lt;/p&gt;</description></item><item><title>Databases, schemas and roles</title><link>https://mimus.pgsty.com/docs/mssql/mapping/</link><guid>https://mimus.pgsty.com/docs/mssql/mapping/</guid><description>&lt;h2 id="modes"&gt;Choose the mapping before initialization&#10;&lt;/h2&gt;&#10;&lt;p&gt;One PostgreSQL cluster hosts one initialized Babelfish physical database, selected by &lt;code&gt;babelfishpg_tsql.database_name&lt;/code&gt;. All TDS connections enter that database. The login packet and T-SQL &lt;code&gt;USE&lt;/code&gt; select a logical database inside it. Thus the HBA entry and &lt;code&gt;psql -d&lt;/code&gt; name &lt;code&gt;wire&lt;/code&gt;, while the driver names &lt;code&gt;master&lt;/code&gt; or a user database such as &lt;code&gt;sales&lt;/code&gt;.&lt;/p&gt;&#10;&lt;div class="td-table-scroll td-table-scroll--static"&gt;&#10;&lt;table&gt;&#10; &lt;thead&gt;&#10; &lt;tr&gt;&#10; &lt;th scope="col"&gt;At the TDS endpoint&lt;/th&gt;&#10; &lt;th scope="col"&gt;Native PG schema in &lt;code&gt;single-db&lt;/code&gt;&lt;/th&gt;&#10; &lt;th scope="col"&gt;Native PG schema in &lt;code&gt;multi-db&lt;/code&gt;&lt;/th&gt;&#10; &lt;/tr&gt;&#10; &lt;/thead&gt;&#10; &lt;tbody&gt;&#10; &lt;tr&gt;&#10; &lt;td&gt;&lt;code&gt;master.dbo&lt;/code&gt;&lt;/td&gt;&#10; &lt;td&gt;&lt;code&gt;master_dbo&lt;/code&gt;&lt;/td&gt;&#10; &lt;td&gt;&lt;code&gt;master_dbo&lt;/code&gt;&lt;/td&gt;&#10; &lt;/tr&gt;&#10; &lt;tr&gt;&#10; &lt;td&gt;&lt;code&gt;tempdb.dbo&lt;/code&gt; / &lt;code&gt;msdb.dbo&lt;/code&gt;&lt;/td&gt;&#10; &lt;td&gt;&lt;code&gt;tempdb_dbo&lt;/code&gt; / &lt;code&gt;msdb_dbo&lt;/code&gt;&lt;/td&gt;&#10; &lt;td&gt;&lt;code&gt;tempdb_dbo&lt;/code&gt; / &lt;code&gt;msdb_dbo&lt;/code&gt;&lt;/td&gt;&#10; &lt;/tr&gt;&#10; &lt;tr&gt;&#10; &lt;td&gt;&lt;code&gt;sales.dbo&lt;/code&gt;&lt;/td&gt;&#10; &lt;td&gt;&lt;code&gt;dbo&lt;/code&gt;&lt;/td&gt;&#10; &lt;td&gt;&lt;code&gt;sales_dbo&lt;/code&gt;&lt;/td&gt;&#10; &lt;/tr&gt;&#10; &lt;tr&gt;&#10; &lt;td&gt;&lt;code&gt;sales.billing&lt;/code&gt;&lt;/td&gt;&#10; &lt;td&gt;&lt;code&gt;billing&lt;/code&gt;&lt;/td&gt;&#10; &lt;td&gt;&lt;code&gt;sales_billing&lt;/code&gt;&lt;/td&gt;&#10; &lt;/tr&gt;&#10; &lt;/tbody&gt;&#10;&lt;/table&gt;&#10;&lt;/div&gt;&#10;&#10;&lt;p&gt;&lt;code&gt;single-db&lt;/code&gt; admits one user database in addition to the built-ins. Choose &lt;code&gt;multi-db&lt;/code&gt; when several user databases need separate namespaces in one physical database. Each mode above was initialized in a fresh instance. FreeTDS created &lt;code&gt;sales.dbo.orders&lt;/code&gt; and read one row in both. Changing the parameter after initialization would leave existing names and metadata in the old layout. To change layouts, provision a fresh target and migrate the application objects and data.&lt;/p&gt;</description></item><item><title>First TDS connection</title><link>https://mimus.pgsty.com/docs/mssql/connect/</link><guid>https://mimus.pgsty.com/docs/mssql/connect/</guid><description>&lt;h2 id="first-login"&gt;Log in and write two rows&#10;&lt;/h2&gt;&#10;&lt;p&gt;After &lt;a href="https://mimus.pgsty.com/docs/mssql/install/#initialize"&gt;initialization&lt;/a&gt;, run this in the local client shell. FreeTDS &lt;code&gt;tsql&lt;/code&gt; prompts for &lt;code&gt;bbf_admin&lt;/code&gt;’s password. &lt;code&gt;-H&lt;/code&gt; and &lt;code&gt;-p&lt;/code&gt; select the TCP endpoint. &lt;code&gt;-D master&lt;/code&gt; selects a &lt;strong&gt;logical&lt;/strong&gt; database at login. The &lt;code&gt;1&amp;gt;&lt;/code&gt; prompt means the client accepts a new batch.&lt;/p&gt;&#10;&lt;div class="td-code td-code--untitled" id="td-code-1fa98b39-fence-0" data-td-code data-td-code-auto-id&#10; data-td-language="sh" data-td-line-count="1"&gt;&#10; &lt;div class="td-code__viewport" id="td-code-1fa98b39-fence-0-viewport" data-td-code-viewport&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-sh" data-lang="sh"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nv"&gt;TDSVER&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;7.4 tsql -H 127.0.0.1 -p &lt;span class="m"&gt;1433&lt;/span&gt; -U bbf_admin -D master&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&#10;&lt;/div&gt;&#10;&lt;p&gt;Enter the following at the &lt;code&gt;tsql&lt;/code&gt; prompt in the fresh example database. &lt;code&gt;GO&lt;/code&gt; on its own line sends the batch. &lt;code&gt;exit&lt;/code&gt; returns to the shell. Expect &lt;code&gt;master&lt;/code&gt;, followed by &lt;code&gt;n = 2&lt;/code&gt; and &lt;code&gt;total = 42&lt;/code&gt;. Use an application database for real tables. Here &lt;code&gt;master&lt;/code&gt; makes the example reproducible immediately after initialization.&lt;/p&gt;</description></item><item><title>Install and initialize</title><link>https://mimus.pgsty.com/docs/mssql/install/</link><guid>https://mimus.pgsty.com/docs/mssql/install/</guid><description>&lt;h2 id="components"&gt;Check the installation&#10;&lt;/h2&gt;&#10;&lt;p&gt;Use a Linux installation of the &lt;a href="https://mimus.pgsty.com/docs/mssql/#version"&gt;matching Mimus kernel and extensions&lt;/a&gt;. The PostgreSQL 19 version string alone cannot identify the patched ABI. If building from source, compile the complete kernel with ICU, OpenSSL, libxml2 and libuuid support, install its &lt;code&gt;contrib/uuid-ossp&lt;/code&gt;, then build the four Babelfish modules against &lt;strong&gt;that installation’s&lt;/strong&gt; &lt;code&gt;pg_config&lt;/code&gt; and its matching &lt;code&gt;PG_SRC&lt;/code&gt;. The T-SQL parser uses Java, CMake and the ANTLR 4.13.2 C++ runtime. The isolated upstream port and the Mimus build use different TDS interfaces. &lt;a href="https://github.com/babelfish-for-postgresql/babelfish_extensions/blob/a6e79da1b28c72e4801abbc9b58f946c10fcb6f9/contrib/README.md"&gt;Upstream build dependencies&lt;/a&gt;&lt;/p&gt;</description></item></channel></rss>