當你遇到以下db2錯誤:
SQL1585N A system temporary table space with sufficient page size does not exist. SQLSTATE=54048
是因爲在view裏面加入了太多的列,超過了當前系統臨時表空間的page長度。
來看一下 SQL1585N的官方建議解決方案:
db2 => ? SQL1585N
SQL1585N A system temporary table space with sufficient page size does
not exist.
Explanation:
One of the following conditions could have occurred:
1. The row length of the system temporary table exceeded the limit that
can be accommodated in the largest system temporary table space in
the database.
2. The number of columns required in a system temporary table exceeded
the limit that can be accommodated in the largest system temporary
table space in the database.
3. A tablespace might be offline.
The system temporary table space limits depend on its page size. These
values are:
Max Max Page size of
Record Cols temporary
Length table space
----------- ---- ------------
4005 bytes 500 4K
8101 bytes 1012 8K
16293 bytes 1012 16K
32677 bytes 1012 32K
User response:
Create a system temporary table space of a larger page size supported,
if one does not already exist. If such a table space already exists,
eliminate one or more columns from the system temporary table. Create
separate tables or views, as required, to hold additional information
beyond the limit.
sqlcode: -1585
sqlstate: 54048
Related information:
ALTER TABLESPACE statement
官方建議 :
1建一個大一點的系統臨時表空間,
2刪除一些字段。
由於項目需要,一般只能選擇方案1. 但是沒有例子,只能自己寫。
系統的默認臨時表空間是USERSPACE1, 這是page 爲4k的表空間。 既然默認的表空間不夠,那就新建一個32k的吧。
先建立bufferpool:
db2 "create bufferpool temp_pool32k size 100 pagesize 32k"
然後檢查這個bufferpool:
db2 "select * from syscat.bufferpools"
有了bufferpool,這時候才能建立自己的臨時表空間:
CREATE TEMPORARY TABLESPACE "TEMP_TBS_32"
IN DATABASE PARTITION GROUP "IBMTEMPGROUP" --> 1
PAGESIZE 32K
MANAGED BY SYSTEM
USING
('/home/db2inst9/tablespaces16k/Temp_001' --->2
)
EXTENTSIZE 32
PREFETCHSIZE 16
BUFFERPOOL "TEMP_POOL32K" --->3
OVERHEAD 24.10
TRANSFERRATE 0.90
DROPPED TABLE RECOVERY OFF;
注意:
1是默認表空間的group,一定要這個值才能讓view找到。
2 是本地存儲文件路徑,根據自己的硬盤修改。
3 是bufferpool的名字,記得一定都要改成大寫字母。
4 文件/home/db2inst9/tablespaces16k/Temp_001是創建tablespaces之後纔有的,之前需要自己命名。
去掉註釋,創建完成後,檢查創建結果:
db2 get snapshot for tablespaces on netdb | grep -A 30 TEMP_TBS_32
有返回,就表明表空間創建成功了。
在訪問view,就有返回結果了。原因是db2會默認找到數據庫下面最大的表空間來使用。
最後,祝好運!