Schema

DB2 - 如何安全地吹走 Linux 上的數據庫?

  • December 1, 2015

我在 CentOS 6.5(肯定)上使用(我相信)10.1.2。

我遇到的根本問題是內部準備的數據庫升級包對我不起作用,至少從某種意義上說,數據庫架構沒有像預期的那樣發生變化。當然,沒有任何外部人員可以幫助我。

我想做的是盡可能完全地刪除現有數據庫(最好是刪除/歸檔可能有它的記錄的文件的級別),這樣升級包就無法讀取舊的模式數據。最安全的方法是什麼?

我嘗試drop database在 db2 命令行中作為 db2inst1 執行一次,但沒有成功:

db2 => connect to xydb 

  Database Connection Information

Database server        = DB2/LINUXX8664 10.1.2
SQL authorization ID   = DB2INST1
Local database alias   = XYDB

db2 => drop database
SQL0104N  An unexpected token "END-OF-STATEMENT" was found following 
"DATABASE".  Expected tokens may include:  "<identifier>".  SQLSTATE=42601
db2 => drop database xydb
SQL1035N  The operation failed because the specified database cannot be 
connected to in the mode requested.  SQLSTATE=57019
db2 => 

非常感謝任何幫助。

如果有人連接到數據庫,則不能刪除該數據庫。您需要首先強制所有人離開數據庫(為此,您需要實例的 SYSCTRL 權限,如果您沒有實例級別的權限,我會猜測數據庫級別的 DBADM)。

db2 connect to xydb
--the next command forces off the users asynchronously
db2 quiesce database immediate force connections
--but you need to unquiesce to drop
db2 unquiesce database
db2 connect reset
-- hope you don't have a connection in between
-- also make sure the database isn't activated....
db2 deactivate db xydb
-- do this as a safeguard cause there is no going back once you drop it.....
db2 backup db xydb to '<path you provide>' compress
db2 drop db xydb

或者,如果您想進入實例級別並鎖定實例…..

db2 quiesce instance <instance name> restricted access immediate force connections
-- make sure the db isn't activated
db2 deactivate db xydb
-- do this as a safeguard cause there is no going back once you drop it......
db2 backup db xydb to '<path you provide>' compress
db2 drop db xydb
-- wait a few seconds
db2 unquiesce instance <instance name>

然後不要忘記備份日誌和歸檔日誌,然後你也可以清理它們。

現在您可以嘗試創建一個新數據庫。但是,我猜您需要擔心遷移數據?您是否正在嘗試遷移到新的修訂包或 DB2 版本?您是否正在嘗試升級您的架構?您始終可以先在另一台伺服器上測試“升級”。我想我想要更多關於你的“升級”的資訊,我可以調整這個答案,希望能回應那部分,而不僅僅是給你關於如何刪除數據庫的提示。

是的,有了這個腳本,我就可以放棄了。轉到命令提示符,然後鍵入

db2cmd

然後

db2 -tvsf <script-name.txt>

腳本內容:

CONNECT TO XYZ;
UNQUIESCE DATABASE;
QUIESCE DATABASE IMMEDIATE FORCE CONNECTIONS;
UNQUIESCE DATABASE;
CONNECT RESET;
deactivate db XYZ;
DROP DATABASE XYZ;

引用自:https://dba.stackexchange.com/questions/76305