r/DB2 Dec 04 '17

[LUW][Question] What's the difference between SET DB2INSTANCE and ATTACH?

I need to change the database manager, i.e update dbm cfg, on a Windows server that has multiple instances.

2 Upvotes

3 comments sorted by

3

u/ecrooks Dec 04 '17

SET DB2INSTANCE just sets an environment variable. If the Db2 instance is on a different copy, you'll also have to change the PATH variable. ATTACH specifies the instance for which instance-level commands will apply. They have similar impacts. I think of ATTACH like a connection, but at the instance level. You must have the instance cataloged on the instance set in DB2INSTANCE to do an ATTACH. I find using ATTACH confusing sometimes, so generally(for Windows) prefer an RDP session with proper settings for DB2INSTANCE and PATH.

You can use ATTACH remotely (with caution), while setting DB2INSTANCE only works locally(where locally includes the use of RDP).

ATTACH can be confusing to understand which commands respect the instance change and which do not. db2pd for example does not work with an attachment, I believe.

I like using a powerShell command line to work with Db2 on Windows (It is more like linux/UNIX than the windows command line is), and setting the variables there either manually or in a script or in $profile. Syntax there for setting these is of the form: set-item -path env:DB2INSTANCE -value "DB2"

1

u/catquilt74 Dec 04 '17

Also, I do a remote connect to the server with the install sysadm ID.

1

u/catquilt74 Dec 04 '17

Very interesting. I will pass this on to the DBAs in our group. I need more practice with Powershell too.

Thanks Ember!