【问题标题】:How to enable wirecompression on Firebird 3.0如何在 Firebird 3.0 上启用线压缩
【发布时间】:2018-12-27 00:27:37
【问题描述】:

我使用 Firebird 和 Delphi,我想通过有线压缩实现通过 Internet 的访问; 但我无法激活它。

我已按照本文档中的步骤获取新参数(我能找到的为数不多的参数之一) How to enable WireCompression on Firebird 3.0 using FireDAC

在我使用的测试中 视窗服务器 2012 R2 火鸟:火鸟-3.0.4.33054_0_Win32(32位) 也复制到可执行文件夹。 fbclient.dll zlib1.dll(同上服务器和客户端) 使用wirecompression = true 创建了firebird.conf。 我在应用程序的 Firedac 中给出了wirecompression=true。

为什么我无法激活 P15:CZ 压缩?

Sending connection info for the example:
================================
Connection definition parameters
================================
DriverID=FB
Database=miservidor001:C:\sysdat\C100\gestdat03.fdb
User_Name=SYSDBA
PassWord=*****
WireCompression=true
================================
FireDAC info
================================
Tool = RAD Studio 10.2
FireDAC = 16.0.0 (Build 88974)
Platform = Windows 32 bit
Defines = FireDAC_NOLOCALE_META;FireDAC_MONITOR
================================
Client info
================================
Loading driver FB ...
Brand = Firebird
Client version = 300049900
Client DLL name = C:\APPS\WC01\fbclient.dll
================================
Session info
================================
Current catalog = 
Current schema = 
Server version = WI-V3.0.4.33054 Firebird 3.0
WI-V3.0.4.33054 Firebird 3.0/tcp (WIN-2012LAGO003)/P15:C
WI-V3.0.4.33054 Firebird 3.0/tcp (nucleo)/P15:C'

【问题讨论】:

  • 究竟如何将WireCompression=true 传递给客户端?对stackoverflow.com/a/40886443/466862 的评论说“将wirecompression=true 添加到连接参数什么都不做,只会将它添加到firebird.conf 生效”(fbclient.dll 读取的firebird.conf 就是! )
  • “使用wirecompression=true 创建firebird.conf”是什么意思?您不应该创建 Firebird 配置!您应该找到唯一现有的配置文件并对其进行编辑(然后重新启动 Firebird)。如果你在服务器上创建了它,那么它很可能位于 Firebird Server 永远不会看到的某个杂散的地方。
  • 使用 SysInternals Process Monitor 确保您的应用程序访问了哪些文件:它是否加载了您希望它加载的 fbclient.dll、zlib1.dll 和 firebird.conf 或其他文件所有这些?
  • firebird.conf 文件中的WireCompression=true 是仅限客户端的设置。如果您在服务器的firebird.conf 中更改它,它只会影响服务器(其中服务器充当客户端)建立的on external datasource 连接。在服务器上更改此设置不会以任何方式影响连接到服务器的客户端(除非它们读取相同的配置文件)。

标签: delphi firebird firedac firebird-3.0 anydac


【解决方案1】:

注意:我不知道 Delphi 或 FireDAC,这个答案基于 Firebird 的一般行为和我维护其 JDBC 驱动程序 (Jaybird) 的经验。因此,可能有专门针对 FireDAC/Delphi 的更好答案。

启用或禁用线路压缩完全由客户端决定,而不是由服务器决定。这意味着服务器的配置不是必需的,也没有任何影响,除非服务器本身充当客户端,例如execute statement ... on external datasource

要能够使用线压缩,您需要三件事:

  1. fbclient.dll
  2. zlib1.dll(与fbclient.dll在同一位置,或在搜索路径上)
  3. 为客户端启用线路压缩的配置

第 3 点可能是您的问题:我不确定 FireDAC 是否有一个连接属性 WireCompression 可以实际启用线路压缩。

我知道为客户端启用线路压缩的两种方法:

  1. 在与您的应用程序使用的fbclient.dll 相同的目录中创建一个firebird.conf。在此配置文件中,放入请求的配置选项(每行一个):

    WireCompression = true
    # maybe other config lines (eg AuthClient, WireCrypt, etc)
    
  2. 不要创建firebird.conf 文件,而是在isc_dpb_config (int 87) 数据库参数项中传递配置(用换行符分隔配置选项)。

    该值与上一个选项中firebird.conf文件的内容相同。如果客户端使用旧的数据库参数缓冲区格式(其中字符串最大 255 字节)并且您想要传递(很多)更多配置选项,这可能会遇到大小问题。

选项 1 可能是最简单的,适用于所有框架。选项 2 取决于框架或驱动程序是否公开数据库参数缓冲区,或者它是否具有映射到 isc_dpb_config 的连接属性。

例如在使用 Jaybird 的 Java 中,您可以使用以下方法启用压缩(仅在使用本机连接时):

Properties props = new Properties();
props.setProperty("user", "sysdba");
props.setProperty("password", "masterkey");
props.setProperty("config", "WireCompression=true");

try (var connection = DriverManager.getConnection(
        "jdbc:firebirdsql:native:localhost:D:/data/db/fb3/fb3testdatabase.fdb", props)) {

    FirebirdConnection fbCon = connection.unwrap(FirebirdConnection.class);
    FbDatabase fbDatabase = fbCon.getFbDatabase();
    System.out.println(fbDatabase.getServerVersion());

} catch (SQLException e) {
    e.printStackTrace();
}

这会打印出WI-V3.0.4.33054 Firebird 3.0,WI-V3.0.4.33054 Firebird 3.0/tcp (host)/P15:CZ,WI-V3.0.4.33054 Firebird 3.0/tcp (host)/P15:CZ(注意这是<server version>,<server protocol info>,<client protocol info>)。 P15:CZ中的Z表示连接是zlib压缩的(C表示连接是加密的)。

这里,config 属性是 isc_dpb_config 的别名。

【讨论】:

    【解决方案2】:

    Mark's answer 是整个互联网上有关此问题的最佳(并且可能是唯一)信息来源。祝你在 Delphi、FireDAC 或 Firebird 文档中找到关于他所说的任何内容。

    根据他的回答,以下是您需要将 Firebird 线压缩与 FireDAC 一起使用:

    • 您需要 Delphi Rio 10.3.1(更新 1)或更高版本。 Only in this version config 低级参数(见下文)已添加到 FireDAC。

    • 您必须将WireCompression=true 传递给低级别 config 连接参数。这不是TFDConnection.Params(高级)。

      • 要完成此操作,您需要将TFDPhysFBConnectionDefParamsIBAdvanced 属性设置为config=WireCompression=true(是的!算了!)

      • 代码:

        FDConnection1.DriverName := '​FB';
        with FDConnection1.Params as TFDPhysFBConnectionDefParams do   
        begin
          Server := '...';
          Database := '...';
          UserName := '...';
          Password := '...';
          IBAdvanced := 'config=WireCompression=true';
        end;
        FDConnection1.Connected := True;
        
      • 使用connection definition file:

        [FB_Demo]
        DriverID=FB
        Server=...
        Database=...
        User_Name=...
        Password=...
        IBAdvanced=config=WireCompression=true
        
    • 您需要zlib1.dll 与您的fbclient.dll 位于同一路径中。这里的问题是 Firebird 发行版在其 C:\Program Files\Firebird\Firebird_3_0\WOW64 文件夹中没有 zlib1.dll 的 32 位版本。所以:

      • 如果您的应用程序是 64 位,您可能没问题。只需使用 C:\Program Files\Firebird\Firebird_3_0 文件夹中的 fbclient.dllzlib1.dll

      • 如果您的应用程序是 32 位,您有来自 32 位 Firebird 发行版的 to download 的 32 位版本 zlib1.dll。将它与您在 C:\Program Files\Firebird\Firebird_3_0\WOW64(包含 32 位库)中找到的 fbclient.dll 一起使用。

    In Firebird 3.0.4 or later 您可以使用WIRE_COMPRESSED 上下文变量来检查连接是否按预期建立:

    SELECT
      RDB$GET_CONTEXT('SYSTEM', 'WIRE_COMPRESSED') wire_compressed
    FROM
      rdb$database
    

    如果当前连接被压缩,这将返回 TRUE。

    【讨论】:

      猜你喜欢
      • 2018-08-20
      • 2017-06-17
      • 2021-10-03
      • 1970-01-01
      • 1970-01-01
      • 2017-12-15
      • 2014-10-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多