IBM DB2,为具有模式和表的数据库创建别名

IBM DB2, create an alias to database with schemas and tables

我有一个数据库(列出数据库目录):

Database 4 entry:
Database alias                       = ABC
Database name                        = ABC
Local database directory             = /data
Database release level               = f.00
Comment                              =
Directory entry type                 = Indirect
Catalog database partition number    = 0
Alternate server hostname            =
Alternate server port number         =

我需要该数据库的别名,因为我的应用程序试图连接到数据库 DEF。

我可以使用

创建别名
catalog db ABC as DEF

然后(列表数据库目录)显示:

Database 4 entry:
Database alias                       = ABC
Database name                        = ABC
Local database directory             = /data
Database release level               = f.00
Comment                              =
Directory entry type                 = Indirect
Catalog database partition number    = 0
Alternate server hostname            =
Alternate server port number         =code here

Database 5 entry:
Database alias                       = DEF
Database name                        = ABC
Local database directory             = /data
Database release level               = f.00
Comment                              =
Directory entry type                 = Indirect
Catalog database partition number    = 0
Alternate server hostname            =
Alternate server port number         =

但是在我连接到别名数据库后使用:

db2 connect DEF

我无法访问原始数据库中的任何模式和表格。当然,当我使用 ABC 数据库名称连接时,一切都可见且就位。

我是不是误解了 DB2 中的别名?或者也许有像 "create an alias with data" 之类的选项?

您似乎误解了 db2 catalog database ABC as DEF 生成的数据库别名的用途。

对于 Linux/Unix/Windows 的 Db2,数据库 ALIAS 不是 SCHEMA。

您不能在 SELECT 或其他 SQL 语句中使用新别名。

您只能在 CONNECT 步骤中引用数据库别名。连接成功后,使用SQL就好像你只连接了数据库ABC。

数据库别名只是一个指向数据库的指针。

指向的数据库(在您的例子中是 ABC)不会改变,其中的模式也不会改变,您无法改变在这些模式中引用表和视图等对象的方式。

在您的 SELECT(或其他 SQL 语句)中,您必须引用物理数据库中存在的模式。所以确实没有称为 DEF 的模式,因为 DEF 是一个 别名 只有命令行处理器和 db2 数据库目录知道。如果您希望在数据库中创建新的同义词,您可以随意这样做,但这不是数据库别名的目的。

因为您似乎是 运行ning Db2 for Linux/Unix/Windows 与本地数据库(目录条目类型 = 间接),您应该连接到每个数据库 ABC 和 DEF 以及 运行 两者下面的查询,然后比较每个数据库的输出,并用输出更新你的问题。

select char(os_name,20) as os_name
, char(os_version,5) as os_version
, char(os_release,20) as os_release
, char(host_name,30) as host_name 
from sysibmadm.env_sys_info;


select char(inst_name,15) as inst_name
,char(release_num,20) as release_num
,char(service_level,20) as service_level
,char(bld_level,20) as bld_level
,char(ptf,20) as ptf
from sysibmadm.env_inst_info;

@mao - 你是对的! 我已经使用外部软件连接到一个节点,并使用 shell db2 连接到另一个节点。这就是我看不到数据库的原因。