標籤

4GL (1) 人才發展 (10) 人物 (3) 太陽能 (4) 心理 (3) 心靈 (10) 文學 (31) 生活常識 (14) 光學 (1) 名句 (10) 即時通訊軟體 (2) 奇狐 (2) 音樂 (2) 產業 (5) 郭語錄 (3) 無聊 (3) 統計 (4) 新聞 (1) 經濟學 (1) 經營管理 (42) 解析度 (1) 遊戲 (5) 電學 (1) 網管 (10) 廣告 (1) 數學 (1) 機率 (1) 雜趣 (1) 證券 (4) 證券期貨 (1) ABAP (15) AD (1) agentflow (4) AJAX (1) Android (1) AnyChart (1) Apache (14) BASIS (4) BDL (1) C# (1) Church (1) CIE (1) CO (38) Converter (1) cron (1) CSS (23) DMS (1) DVD (1) Eclipse (1) English (1) excel (5) Exchange (4) Failover (1) FI (57) File Transfer (1) Firefox (2) FM (2) fourjs (1) gladiatus (1) google (1) Google Maps API (2) grep (1) Grub (1) HR (2) html (23) HTS (8) IE (1) IE 8 (1) IIS (1) IMAP (3) Internet Explorer (1) java (3) JavaScript (22) jQuery (6) JSON (1) K3b (1) LED (3) Linux (112) Linux Mint (4) Load Balance (1) Microsoft (2) MIS (2) MM (51) MSSQL (1) MySQL (27) Network (1) NFS (1) Office (1) Oracle (125) Outlook (3) PDF (6) Perl (59) PHP (33) PL/SQL (1) PL/SQL Developer (1) PM (3) Postfix (2) postfwd (1) PostgreSQL (1) PP (50) python (1) QM (1) Red Hat (4) Reporting Service (28) ruby (11) SAP (234) scp (1) SD (16) sed (1) Selenium-WebDriver (5) shell (5) SQL (4) SQL server (8) SQuirreL SQL Client (1) SSH (2) SWOT (3) Symantec (2) T-SQL (7) Tera Term (2) tip (1) tiptop (22) Tomcat (6) Trouble Shooting (1) Tuning (5) Ubuntu (33) ufw (1) utf-8 (1) VIM (11) Virtual Machine (2) vnc (3) Web Service (2) wget (1) Windows (19) Windows (1) WM (6) youtube (1) yum (2)

2011年3月29日 星期二

HTS : [4000]系統交易 參考 加權指數

1. STS code 加上
Value1 = (Open  of data2)
Value2 = (High  of data2)
Value3 = (Low   of data2)
Value4 = (Close of data2)

2. [4000]系統交易 右上角,點選 "多筆個股"
3. 個股2 -> 類股 -> 上市 -> 加權指數
4. STS code 即可參考Value1 ~ Value 5 例如:
if Date = 1110315 then
  print (Value1[1])
end if
意即 如果日期=20110315,print 昨日開盤價

2011年3月28日 星期一

SAP : Transaction Codes

KSB1 : 經由會計科目看部門費用 (5* & 6* 會計科目)

nslookup

C:\Documents and Settings\tyruan>nslookup
Default Server:  xxx.yyyy.com.tw
Address:  10.56.34.1

> set type=MX

> lserver 168.95.1.1
Default Server:  dns.hinet.net
Address:  168.95.1.1

> foxconn.com
Server:  dns.hinet.net
Address:  168.95.1.1

Non-authoritative answer:
foxconn.com     MX preference = 10, mail exchanger = relay2.la.foxconn.com
foxconn.com     MX preference = 10, mail exchanger = relay6.foxconn.com.cn
foxconn.com     MX preference = 10, mail exchanger = relay7.tw.foxconn.com
foxconn.com     MX preference = 10, mail exchanger = vhost4.foxconn.com.cn
foxconn.com     MX preference = 20, mail exchanger = relay8.tw.foxconn.com
foxconn.com     MX preference = 10, mail exchanger = relay.la.foxconn.com

foxconn.com     nameserver = 3dnscn.foxconn.com
foxconn.com     nameserver = 3dnstw.foxconn.com
foxconn.com     nameserver = 3dnsus.foxconn.com
relay.la.foxconn.com    internet address = 63.67.248.249
relay2.la.foxconn.com   internet address = 63.97.134.144
relay2.la.foxconn.com   internet address = 204.2.221.144
relay6.foxconn.com.cn   internet address = 218.18.111.142
relay7.tw.foxconn.com   internet address = 218.210.124.167
vhost4.foxconn.com.cn   internet address = 61.144.234.146
relay8.tw.foxconn.com   internet address = 210.80.95.166
3dnscn.foxconn.com      internet address = 116.6.66.5
3dnstw.foxconn.com      internet address = 210.80.95.77
3dnsus.foxconn.com      internet address = 65.197.202.65

2011年3月27日 星期日

HTS : 自動下單注意事項

1. HTSFileTrader2.exe : 檔案位置 修改 C:\JihSun\cur_cmd.txt

2. Variables: FileStr(" 1 F TXF 201104 ")

3. 作多時,STS code
If Condition1 and Condition2 and Condition3 and Condition4 and MarketPosition < 1 then
  Buy ("L1") this bar at CriticalPrice or Higher
  Buy ("L2") this bar at CriticalPrice or Lower
  TradeNumber = TradeNumber + 1
  if LastBarOnChart and MOD(Q_Time, 2) <> 0 then
    FileDelete("C:\jihsun\cur_cmd.txt")
    FileAppend("C:\jihsun\cur_cmd.txt", cdate(date) + " " + ctime(time)+ FileStr+ NumToStr(CurrentContracts,0) + " N")
  end if

end if

4. 放空時,STS code:
If Condition6 and Condition7 and Condition8 and Condition9 and MarketPosition > -1 then
  Sell ("S1") this bar at CriticalPrice or Higher
  Sell ("S2") this bar at CriticalPrice or Lower
  TradeNumber = TradeNumber + 1
  if LastBarOnChart and MOD(Q_Time, 2) <> 0 then
    FileDelete("C:\jihsun\cur_cmd.txt")
    FileAppend("C:\jihsun\cur_cmd.txt", cdate(date) + " " + ctime(time)+ FileStr+ NumToStr(CurrentContracts,0) + " N")

  end if
end if

HTS : 常用函數

// 買賣的當根K棒
If BarsSinceEntry(0)=0 then
  ……
endif

// 手中有空單
If MarketPosition < 0
  ……
endif

// 手中有多單
If MarketPosition > 0
……
endif

EntryPrice 進場的價格
BarsSinceEntry 進場後過了幾根k棒
CurrentContracts 目前的部位
CurrentContracts=0 顯示目前無單
CurrentContracts=1 顯示目前有1口多單
CurrentContracts=-1 顯示目前有1口空單

Date格式 : 2011/03/27 => 1110327
Time格式 : 17:39:34 => 173934


程式語言的邏輯觀念都是相通的,但語法切入的角度或方向會有點差異
物件導向的Visual Basic程式語言,其語法切入的重點在於物件用途、物件與物件之間的連結
Power Language是以每根k棒的開盤、最高、最低、收盤與成交量為思考基礎換言之,程式會去判斷每一根k棒在發生何種狀況下,而去建立買入、賣出訊號
程式語言組成份子

數學運算符號 + ,-,*,/
比較運算符號<>,= ,>=,>,<
保留字與無義字
自設變數 value1—valuen…
邏輯條件結構 if —then
買賣訊號的組成
變數宣告區
進場買賣訊號區
出場平倉區
如何設定自設變數
自設變數的名稱不可是保留字,變數由英文字母與數字所構成,例如ange1
Ange1=(high-low)/(high[1]-low[1])
這個變數是由保留字變數所構成,他將隨著保留字變動而變動,所以他將無法最適化,我們稱為variables變數,在variables中宣告。
另外一種稱為parameters變數,此種變數可以進行變數最佳化的工作,此變數是獨立出來的,其值並不會受到其他變數所影響。
Ange1=(high-low)/(high[1]-low[1])*att
此att就是為parameters變數
Parameters:att(0);
Variables:ange1(0);
Ange1=(high-low)/(high[1]-low[1])*att
變數宣告區為程式中的前兩行,後面的() 為初始值的設定。
運算符號介紹
數學運算+ (加) - (減) * (乘) / (除)
實例
value1=(close+high-low)/high
value2=(high-low)*0.03
注意:先乘除 後加減
比較運算符號
> (大於)
>= (大於等於)
< (小於)
<= (小於等於)
= (等於)
<> (不等於)
實例
high>6000 ; low=5900 ; close<5900 ; (high-low)<>100
聯接運算式
And 所有必要條件
實例
條件1 and 條件2,條件1與條件2都要成立
high>high[1] and low>low[1]
(日線) 今日最高價大於昨日最高價與今日最低價大於昨日最低價
Or 任何一條件
實例
條件1 or 條件2
條件1與條件2任一成立
high>high[1] or low>low[1]
保留字介紹
保留字為系統內建的字,每一保留字有其特殊的意義,使用者無法變更其意義與用途。
例如close 表示k棒之收盤價,使用者若寫出close=value1+value2 此種程式語句,將出現錯誤訊號。
保留字
Open K線的開盤價
High K線的最高價
Low K線的最低價
Close K線的收盤價
Volume K線的成交量
Openint 期貨的未平倉量(日線資料才會有)
保留字
Date 這根K線的日期
日期格式 1988年10月11日 寫法881011
2000年後的日期
2000 11 12 寫法1001112
2005 12 13 寫法1051213
Time 這根K線的時間
時間格式 24小時制 9:15 寫法0915 , 13:30 寫法1330
保留字
Buy 買進訊號
Sell 賣出訊號
Exitlong 買進平倉訊號
Exitshort 賣出平倉訊號
實例 buy(“買進”) this bar on close
(“買進”)表示在k線圖上標示“買進“這 兩個字
保留字
Entryprice 進場的價格
通常用於停損或停利語法,實例
exitshort(“XS”) at entryprice+30 stop
出場訊號,當價格觸到(進場價格+30)則停損出場
保留字
Avgentryprice 平均進場價格
通常運用在多重進場,每一次進場都不同價格,將所有出場價格平均。
exitlong(“XL”) at avgentryprice+30 limit
停利單 當價格觸到 平均出場價格+30 則停利出場
保留字
barsSinceEntry 進場後過了幾根k棒
假如 barsSinceEntry =10 進場後過了10根k棒,日線資料,進場後過了10天,通常用於出場訊號,顯示出價格波動性不大,就平倉出場。
實例
if marketposition=1 and barsSinceEntry =10 then begin
exitlong(“XL”) next bar at market;
end;
保留字
Currentcontracts 目前的部位
currentcontracts=1 顯示目前有1口多單
currentcontracts=-1顯示目前有1口空單
currentcontracts=0顯示目前沒有部位
通常用於進、出場訊號。
實例
if currentcontracts=0 and close>value1 then
buy(“BBUY”) this bar on close;
end if;
保留字
Marketposition 顯示目前部位跟currentcontracts用法完全相同。
marketposition=1代表目前有一口多單
marketposition=-1代表目前有一口空單
marketposition=0代表目前沒有部位
條件判斷式
程式邏輯判斷if…….then……..end if
假如(if) 某件事發生的情況下 然後(then)就去執行一個動作 end if
思考的邏輯 完全跟日常生活一樣 例如 如果 累了 然後……休息………
STS 邏輯 如果 最高價創三天新高價 然後呢……買進或賣出…..
反向去思考 如果你不累……..接下來的動作 就不會去做了
STS程式邏輯也一樣 如果 最高價沒有創三天新高價 程式一樣不會去執行then 後面的動作
多條件邏輯判斷式
如果是兩個條件以上呢? 如果都要成立 用and 作連結
條件1 and 條件2 and 條件3……
如果選工作的條件是 1.事少 2.錢多 3.離家近 如果此人缺一不可
轉換為程式語法
if 如果此工作1.事少 and 2.錢多 and 3.離家近 then 去應徵此工作
反向思考 如果1—3有一不成立 …此人就不會去應徵
STS 程式邏輯
假如 最高價大於昨日最高 最低價大於昨日最低價 然後 買進……..
if high>high[1] and low>low[1] then buy…………….
多擇一邏輯架構
如果有一個工作符合 1.事少 2.錢多 3.離家近 的其中一條件 然後就去應徵用or 連結 if 1.事少 or 2.錢多 or 3.離家近 then……工作
STS程式邏輯 當 最高價大於昨日最高 或 最低價大於昨日最低價 然後 買進……
if high>high[1] or low>low[1] then buy……………
進階結構 and or 混合
if 1.事少 and ( 2.錢多 or 3.離家近 ) then………
此份工作’’事少’’ 是必備的 但是2.錢多與3.離家近 有一個條件成立就可 .
常用內建函數
Average 定義為平均值
用法 average(價格,長度)
value1=average(close,10)
定義value1這個變數的值為 以收盤價
計算10日的平均價
如果我們要計算我們自己設定變數的平均值也可以用這個函數。
實例
value1=high-low
value2=average(value1,9)
常用內建函數
Averagetruerange 真實區間的平均值
真實高價 max(此k最高價,昨日收盤價)
真實低價 min( 此k最低價,昨日收盤價)
真實區間=(真實高價-真實低價)
Averagetruerange(5)代表5日真實區間的平均值
常用內建函數
Highest 找出最高值highest(價格,長度)
實例 value1=highest(low,5)
近5根K棒最低價中最大值
value2=highest(close,10)
近10根K棒收盤價中最大值
常用內建函數
Lowest 找出最低值 lowest(price,5)
實例 value1=lowest(high,3)
近3根k棒的最高價中,最低那一個
value2=lowest(low,5)
近5根k棒的最低價中,最低那一個
常用內建函數
RSI 相對強弱指標 RSI(close,長度)
RSI(close,6) 代表6日的RSI值
RSI(close,13)代表12日的RSI值
常用內建函數
KD指標的函數寫法,KD指標中的K值與D值是由FastD這個函數所構成,先求出K值,之後在求出D值。
K-value = FastD( High, Low, Close,9)
D-value=MA(K-value,3)
常用內建函數
EMA函數 指數平滑移動平均數,MACD指標中的快速與慢速平均數是由此平均數求得。
MACD(price,fastMA,slowMA)
此函數可求得快速與慢速平均數的差離值,換句話說,例如30日平均數減去10日平均數。
寫法1
Value1=EMA(close,12)
Value2=EMA(close,26)
Value3=value1-value2 (市場稱為DIF值)
寫法2
Value3=macd(close,12,26) (市場稱為DIF值)
Value4=EMA(value3,9) (市場稱為MACD值)
突破與跌破
技術指標中跌破與突破代表市場將出現趨勢走向,通常是進場的好時機。
Cross over 代表突破 A cross over B (A突破B)
High cross over MA(close,30)
今日最高價突破30均線
Cross below 代表跌破 A cross below B(A跌破B)
Low cross over MA(close,30)
今日最低價跌破30均線
基本買賣訊號的構成
進場訊號 語法中要出現buy sell
一個情況發生下,以一種價格或下單模式進行買賣動作
If close cross over value1 then
buy(“long”) next bar at market
end if
模擬下單模式
市價單 buy(“long”) next bar at market
此根k出現買入訊號,進場價格為下一根k的市價,也就是開盤價。
停損單 buy(“long”) at 30 stop
以價格30為停損價位,換句話說,價格觸到30後 下單,價格可能高於30。
限價單 exitshort(“XS”) at 50 limit
以價格50為出場價位,價格一定會小於等於50
當根收盤價單 buy(“long”) this bar on close
基本出場訊號的組成
出場程式中,exitlong 多單出場 與 exitshort 空單出場一定要出現。
結構與進場訊號相似,但條件是中會出現marketposition
If marketposition=1 and barssinceentry=10 then
exitlong(“XL”) next bar at market
End if
指標語法介紹
指標最重要的函數就是畫線draw,簡單的指標最先還是變數宣告,與買賣訊號寫法相似,下方以真實區間為例說明:
Parameters:len(4);
variables:value1(0);
Value1=averagetruerange(len)
Draw1(value1, 『averagetruerange』)
長短均線交易策略
Parameters: FastLength(10), slowlength(30)
If MA(close,fastlength) cross above MA(close,slowlength) then
Buy (『買進』) next bar at market
End If
If MA(close,fastlength) cross below MA(close,slowLength) then
Sell (『賣出』) next bar at market
End If
均線交易策略
Parameters: slowlength(30)
If close cross above MA(close,slowlength) then
Buy (『買進』) next bar at market
End If
If close cross below MA(close,slowLength) then
Sell (『賣出』) next bar at market
End If
均線出場訊號
Parameters: fastlength(10),slowlength(30)
if close<ma(close,fastlength) and currentcontracts=1 then
exitlong(『買進平倉』) next Bars at market
end if
if close>ma(close,fastlength) and currentcontracts=-1 then
exitshort(『賣出平倉』) next Bars at market
end if
台指期波動性策略 進場訊號
Parameters: VtyPercentLE(1.2),VtyPercentSE(0.6),VtyPercentLX(2),VtyPercentSX(0.9)
If MarketPosition <> 1 Then
Buy (『買進』) Next Bar at Close + (VtyPercentLE * AverageTrueRange(5)) Stop
End If
If MarketPosition <> -1 Then
Sell (『賣出』) Next Bar at Close – (VtyPercentSE * AverageTrueRange(5)) Stop
End If
台指期波動性策略 出場訊號
ExitLong (『多出』) Next Bar at Close – (VtyPercentLX * AverageTrueRange(5)) Stop
ExitShort (『空補』) Next Bar at Close + (VtyPercentSX * AverageTrueRange(5)) Stop
台指期波動性策略主要是由平均真實區間作調整所形成的買賣訊號,每日的真實區間都可能變動,當收盤價觸及到真實區間後進行買進賣出的動作
KD指標的計算
Step1 計算RSV
RSV=(Ct-Ln)/(Hn-Ln)*100
Ct為收盤價 Ln為n日內的最低價
Hn為n日內的最高價
Step2 計算K與D
Kt=RSV*(1/3)+Kt-1*(2/3)
Dt=Kt*(1/3)+Dt-1 *(2/3)
KD指標語法說明
Parameters : HighLowTerm(14), kLength(3), dLength(3), OverSold(20), OverBought(80)
Value1 = FastD( High, Low, Close, HighLowTerm)
DrawBase1( OverBought, 『Over Bought』, DarkGray )
DrawBase2( OverSold, 『Over Sold』, DarkGray )
Draw2( Round(MA( Value1, dLength),2), 『Slow %D』, Blue)
Draw1( Round( Value1,2), 『Slow %K』, Red)
KD交易策略語法說明
Parameters : HighLowTerm(9), kLength(3), dLength(3), OverSold(20), OverBought(80)
variables:value(0),value2(0);
Value1 = FastD( High, Low, Close, HighLowTerm)
value2=MA( Value1, dLength)
if value1>OverBought and value2>OverBought and value1 cross over value2 then
buy(『long』) next bar at market
end if
if value1<OverSold and value2<OverSold and value1 cross below value2 then
sell(『short』) next bar at market
end if
RSI交易策略語法說明
parameters:len(9),overbought(80),oversought(20)
if rsi(close,len)>overbought then
sell(『賣出』) this bar on close
end if
if rsi(close,len)<oversought then
buy(『買進』) this bar on close
end if
MACD指標的計算方式
Step1:先計算兩條長短均線,例如12日均與26日均。
Step2: 12日均減去26日均 形成DIF值
Step3IF取9日平均 為MACD值
MACD 交易策略
Parameters: FastMA(10),SlowMA(20),MacdMA(9)
variables:value1(0)
value1=MACD(close,FastMA,SlowMA)
If value1 crosses over EMA(value1,MacdMA) then
buy(『買進』) next bar at market
End if
If value1 crosses below EMA(value1,MacdMA) then
sell(『賣出』) next bar at market
End if
MACD 進階策略
DIF與MACD 的差離值,此差離值>30則買進,<-20則賣出。
Parameters: FastMA(10),SlowMA(20),MacdMA(9)
variables:value1(0)
value1=MACD(close,FastMA,SlowMA)
value2= EMA(value1,MacdMA)
value3=value2-value1
If value3>30 then
buy(『買進』) next bar at market
End if
If value3<-20 then
sell(『賣出』) next bar at market
End if
週k線策略(利用週線資料)
If close-open>0 then
buy(“買進”) next bar at market
End if
If close-open<0 then
sell(“賣出”) next bar at market
End if
ROC交易策略
當ROC指標連續三日增加則買進,連續3日減少則賣出
variables:ROC(0)
ROC=close/close[9]
if ROC>ROC[1] and ROC[1]>ROC[2] and ROC[2]>ROC[3] then
buy(『買進』) next bar at market
end if。
if ROC<ROC[1] and ROC[1]<ROC[2] and ROC[2]<ROC[3] then
sell(“賣出』) next bar at market
end if。
停損訊號程式碼說明
Parameter: DollarRisk(10000)
Variables: StopLossAmount(0), OrderPrice(0)
If MarketPosition = 1 Then
StopLossAmount = DollarRisk + Commission_B
OrderPrice = Entryprice(0) – (StopLossAmount / PointValue)
ExitLong (『停損L』) this Bar at OrderPrice Stop
End if
If MarketPosition = -1 Then
StopLossAmount = DollarRisk + Commission_S
OrderPrice = EntryPrice(0) + (StopLossAmount/ PointValue)
ExitShort (『停損S』) this Bar at OrderPrice Stop
End if
If MarketPosition = 1 Then
StopLossAmount = DollarRisk + Commission_B
OrderPrice = Entryprice(0) – (StopLossAmount / PointValue)
ExitLong (『停損L』) this Bar at OrderPrice Stop
End if
StopLossAmount 代表總損失的金額
Commission_B 代表手續費
PointValue 每1點的價值 例如台指期1點200元
停利訊號程式碼
Parameter: profit(10000)
Variables: OrderPrice(0)
If MarketPosition = 1 Then
OrderPrice = Entryprice(0) + (profit / PointValue)
ExitLong (『停利L』) this Bar OrderPrice limit
End if
If MarketPosition = -1 Then
OrderPrice = EntryPrice(0) – (profit/ PointValue)
ExitShort (『停利S』) this Bar OrderPrice limit
End if
If MarketPosition = 1 Then
OrderPrice = Entryprice(0) + (profit / PointValue)
ExitLong (『停利L』) this Bar OrderPrice limit
End if
多單停利 profit 利潤設定為10000元,進場後必須賺到10000元以上才停利出場(profit / PointValue)顯示此10000元相當於幾點
以台指期為例,pointvalue=200,所以orderprice=50 ,利用限價單的原因是在於平倉的價格要比預定的還要好。

HTS : 在分線中抓取日線的價格

HTS程式碼如下:
Array:CoD1[84](-1),CoD2[84](-1),CoD3[84](-1)
//宣告3個陣列:CoD1,CoD2,Cod3//
vars:closeD1(0),closeD2(0),closeD3(0)
//宣告3個變數:closeOfD1,closeOfD2,closeOfD3//
closeD1 = CloseOfD(1, CoD1)
closeD2 = CloseOfD(2, CoD2)
closeD2 = CloseOfD(3, CoD3)
//利用CloseOfD這函數和宣告的陣列把三天的收盤放到變數裡//


這樣closeD1 closeD2 closeD3
就是1天前 2天前 3天前的收盤了
不用在建立其他函數 比較方便..

要抓開盤低點高點 都可以用這方法
開盤:openofd(X.Y)
高點:highofd(X.Y)
低點:lowofd(X.Y)
收盤:closeofd(X.Y)

X是要抓取的日數 一天前是1 兩天前是2...
0就是今日不過 這只能抓開盤
其他是抓不到的 抓到了也不準 因為還沒收盤 怎麼會知道高點低點收盤??

Y就是Array
而CoD1[84](-1)中的"CoD1"就是Array名...可隨便取
那"[84](-1)"是什麼意思?? //申明陣列長度84並賦值爲-1

大概是這樣...
自己可以研究...

HTS : 限定當天交易次數

if Barssinceentry(0)=0 and MarketPosition !=0 then
Value1 = Value1 + 1
end if

if 你自己的交易條件 and Value1<=2 then
buy...
sell...
end if

if time[1]=134500 then
Value1=0
end if

HTS : This bar at Close with Q_Time

if Condition XX= True and T=134500 and ( Q_Time >= 134440 or Q_Time = 0 ) then
   Buy / Sell / ExitLong / ExitShort ..... This bar at Market
end if

2011年3月26日 星期六

HTS 程式交易

轉貼來源: http://nickcatwang.blogspot.com/2009/06/hts.html

全自動HTS程式交易,僅需1+2+3即可,4、5是輔助使用,可有可無
以下分別詳細說明
1.日盛HTS:依照自行設計/購買/租用的程式,在日盛HTS的[4000]系統交易裡產生訊號,請去日盛開戶~或申請試用帳號,就可以使用了[ 註: 目前日盛有限制-->必須每月交易50口以上才可使用4000系統交易 ]

2.自動下單機:讀取HTS產生的訊號,送下單字串至步驟3的API Trade Manager。
下單機跟程式一樣,有自行設計/購買/租用的。
這玩意兒一開始整慘小喵了,用租的,吃利潤;用買的,貴傷傷。用試用版下單機,每個月又要重裝,設定設錯虧損可大了,所以花了點時間,自己寫給自己用。
需要的下單機的,請點→王小喵牌不負責任下單機←    [ 註: 日盛自動下單機--->請洽日盛 ]

3.API Trade Manager:這個只要安裝HTS就有了,在C:\JihSun\HTS2\APITradeMgr.exe。
這個程式的功能,就是將下單字串送給日盛期貨,然後就下單完成啦
API Trade Manager日盛說明文件

4.Macro Express3:這個是幫忙開機、開HTS、開API、開下單機…每天一樣的步驟,就靠Macro Express來完成的。
Macro Express試用版←(需要破解版的,請自行拜google大神)
Macro Express安裝設定

5.Team Viewer:超簡單遠端操作家裡電腦的軟體,換句話說,上班族可以偷老闆的時間,看看家裡電腦有沒有乖乖運作。
Team Viewer

2011年3月25日 星期五

SQL自動產生多個日期

select sysdate-lvl
  from dual a,
           (
             select level lvl from dual connect by level <= 3
           ) b;

--上月21號到今天有幾天
select sysdate-lvl
          from dual a,(select level lvl from dual connect by level <= trunc(sysdate)-(trunc(add_months(sysdate,-1),'mm')+20)) b

2011年3月23日 星期三

ERP系統借貸關係表

網路上無意中搜尋到的,由於我對FI/CO很不了解,趕緊先放到自己的Blog裡,才不會找不到。

ERP系統借貸關係表

成本核算會計信息歸納
按照事務處理的來源類型歸納。
一、 採購接收入庫和退貨:
1.接收: 借:材料採購   (訂單價格)
貸:應計負債   (訂單價格)
2.入庫: 借:原材料    (標準成本)
貸:材料採購   (訂單價格)
借或貸:材料成本差異_材料訂單價格
3.退貨至接收時產生與上面第2步相反的分錄,退貨至供貨商時產生與上面第1步相反的分錄。

二、 子庫存轉移:只有轉出子庫產生分錄
借:原材料(自制半成品、庫存商品)
貸:原材料(自制半成品、庫存商品)


三、 雜項事務處理:
1.庫存增加:借:原材料(自制半成品、庫存商品)
貸:賬戶別名(或自定義賬戶)
2.庫存減少:與上面相反的分錄

四、 採購發票匹配:借:應計負債      (訂單價格)
應交稅金_增值稅_進項稅
貸:應付帳款     (發票價格)
借或貸:材料成本差異_材料發票價格差異

五、 生產環節:
1. 標準工單:
① 標準工單領料:借:生產成本_直接生產成本_材料
貸:原材料(自制半成品、庫存商品)
② 標準工單退料:與上面相反的分錄
③ 標準工單資源事務處理(即人工):雖然我司沒有在WIP模塊進行實際的人工成本核算,但系統會自動核算一筆,基於在定義資源時的吸收賬戶為「生產成本_直接生產成本_直接人工」,系統產生以下分錄:
借:生產成本_直接生產成本_直接人工 (包含成本中心信息)
貸:生產成本_直接生產成本_直接人工
(值為零,且只有裝配件定義了資源、工藝路線的工單才會產生此分錄)
因此,在總帳模塊處理實際人工和製造費用時,建議:
借:生產成本_生產成本差異_人工   (實發工資)
貸:應付工資
借:生產成本_生產成本差異_費用    (實際發生的製造費用)
貸:製造費用
④ 標準工單完工入庫:借:原材料(自制半成品、庫存商品)
貸:生產成本_直接生產成本_直接材料
生產成本_直接生產成本_直接人工
生產成本_直接生產成本_直接費用
(僅庫存商品會有人工和費用科目)
⑤ 如果按照標準成本生產,即發生成本和沖減成本一致,則工單關閉時沒有差異;
⑥ 工單關閉時,如果材料的發生成本比沖減成本大,即多耗料:
借:生產成本_生產成本差異_材料
貸:生產成本_直接生產成本_直接材料
如果少耗料則產生相反分錄。
生產環節只產生量差,不產生價差。
⑦ 工單關閉時,對於人工和費用產生的分錄恆定為:
借:生產成本_直接生產成本_直接人工  (標準)
生產成本_直接生產成本_直接費用  (標準)
貸:生產成本_生產成本差異_人工
生產成本_生產成本差異_費用

2. 非標工單:(對一般性分錄不歸納,如領材料等)

① 有完工入庫的非拆卸工單
發出成品時:借:生產成本_直接生產成本_直接材料  (標準)
生產成本_直接生產成本_直接人工  (標準)
生產成本_直接生產成本_直接費用  (標準)
貸:產成品
完工入庫時:借:庫存商品
貸:生產成本_直接生產成本_直接材料  (標準)
生產成本_直接生產成本_直接人工  (標準)
生產成本_直接生產成本_直接費用  (標準)

關閉時:借:生產成本_直接生產成本_直接人工   (標準)
生產成本_直接生產成本_直接費用   (標準)
貸:生產成本_生產成本差異_人工
生產成本_生產成本差異_費用
借:生產成本_生產成本差異_材料
貸:生產成本_直接生產成本_直接人工  (標準)
生產成本_直接生產成本_直接費用  (標準)
② 拆卸工單:
發出成品,同上;
發放負組件:借:原材料(自制半成品)
貸:生產成本_直接生產成本_直接材料
返還負組件,產生與之相反分錄;
關閉時:借:生產成本_生產成本差異_材料
貸:生產成本_直接生產成本_直接材料  (標準)
生產成本_直接生產成本_直接人工  (標準)
生產成本_直接生產成本_直接費用  (標準)
3. 其它委外加工、外協加工、編碼拆分等類型類似工單處理(因為科目設置一樣)

六、 銷售環節:
1. 挑庫:借:分期收款發出商品
貸:庫存商品(自制半成品、原材料)
2. 發運:借:分期收款發出商品
貸:分期收款發出商品

七、 成本更新:
1. 對庫存的影響:
如果單位成本增加,則 借:原材料(自制半成品、庫存商品)
貸:材料成本差異_材料成本更新差異
如果單位成本降低,則產生相反分錄
2. 對在製品的影響,需要區分不同的工單狀態
① 工單已發放狀態,組件尚未發,裝配件未入庫,裝配件物料、人工和製造費用及組件的更新均不產生影響;
② 工單已發放狀態,組件已發,未有裝配件入庫,裝配件物料、人工和製造費用的更新不產生影響,某組件的成本更新會產生影響,
借(貸):生產成本_直接生產成本_直接材料
貸(借):生產成本_生產成本差異_在製品成本
③ 工單已發放狀態,組件已發,裝配件部分入庫,如果是裝配件某一組件更新引起裝配件成本更新,則組件和裝配件的更新都會產生影響:
(組件成本增加)組件產生的影響:
借:生產成本_直接生產成本_直接材料(已發料數量*更新值)
貸:生產成本_生產成本差異_在製品成本
裝配件產生的影響:
借:生產成本_生產成本差異_在製品成本
貸:生產成本_直接生產成本_直接材料(已入庫數量*更新值)
對於以後再入庫的按新裝配件成本沖減。
組件成本減少產生相反分錄。
④ 工單已發放狀態,組件已發,裝配件部分入庫,物料沒有更新,裝配件的資源或製造費用更新(人工定義非累計的更新)對已入庫部分產生影響:
成本增加:借:生產成本_生產成本差異_在製品成本
貸:生產成本_直接生產成本_直接人工(已入庫數量*更新值)
(或 貸:生產成本_直接生產成本_直接費用)
成本減少產生相反分錄。
⑤ 工單已完成狀態,組件已發,某個組件更新(但裝配件並沒更新),對組件的發料會產生影響:
成本增加:借:生產成本_直接生產成本_直接材料 (已發料數量*更新值)
貸:生產成本_生產成本差異_在製品成本
成本減少產生相反分錄。
⑥ 工單已完成狀態,組件已發,某個組件更新引起裝配件物料成本更新,對組件發放和裝配件入庫都會產生影響:
成本增加:借:生產成本_直接生產成本_直接材料 (已發料數量*更新值)
貸:生產成本_生產成本差異_在製品成本
借:生產成本_生產成本差異_在製品成本
貸:生產成本_直接生產成本_直接材料(入庫數量*更新值)
成本減少產生相反分錄。
⑦ 工單已完成狀態,組件已發,物料沒有更新,資源或製造費用更新(人工定義非累計):
成本增加:借:生產成本_生產成本差異_在製品成本
貸:生產成本_直接生產成本_直接人工(直接費用)
成本減少產生相反分錄。

八、 根據開票信息在總帳結轉銷售成本:
借:主營業務成本(其它業務支出_材料)
貸:分期收款發出商品

九、 彙總各個差異賬戶,按規則在總帳中分攤。

1.採購驗收作業,產生會計分錄如下:(
借):收貨科目 (Receiving Inventory) @ PO Price
(貸):存貨AP應計額 (Inventory AP Accrual) @ PO Price
2.入庫作業,有應付帳款立帳信息,則依循立帳信息,無立帳信息,則採用採購單信息,產生會計分錄如下 (假設有應付帳款立帳信息):
(借):原物料科目 (Material Account) @應付帳款立賬本幣金額
(貸):收貨科目 (Receiving Inventory) @ PO Price
(借 或 貸):商業發票價格差異(Invoice Price Variance, IPV)
採購單匯差收益/損失(Rate Variance Gain/Loss)
3.應付帳款立帳作業,產生會計分錄如下:
(借):存貨AP應計額 (Inventory AP Accrual) @ PO Price
(貸):應付帳款科目 @應付帳款立賬本幣金額
(借 或 貸):商業發票價格差異(Invoice Price Variance, IPV)
採購單匯差收益/損失(Rate Variance Gain/Loss)
4. 在週期性成本之下,若原物料採購的發票在立帳時有做Match Receipt的動作,則週期性成本會將此發票的商業發票價格差異(IPV)轉變成原物料成本,但若本期的發票Match前期的Receipt,則此發票 產生的IPV將不會被週期性成本納入本期的料件成本計算.

關與在製品會計分類(WIP Accounting Class)
1. 直接材料的發料
分錄的金額為「當期週期性成本」
(借):在製品計價科目 (WIP Valuation) @ 當期週期性成本
(貸):存貨科目 (MTL Account) @當期週期性成本

2. 直接人工的成本處理
分錄的金額為「當期維護的工資率」
(借):在製品計價科目 (WIP Valuation) @ 當期維護工資率
(貸):已分攤直接人工(Absorption) @當期維護工資率

3.製造費用 / 委外加工費用的成本處理
製造費用的成本反應會產生如下的分錄,分錄的金額為「當期維護的部門分攤率」
(借):在製品計價科目 (WIP Valuation) @ 當期維護分攤率
(貸):已分攤製造費用(Absorption) @當期維護分攤率

委外加工費用的成本反應會產生如下的分錄
分錄的金額為「當期維護的部門分攤率」
(借):在製品計價科目 (WIP Valuation) @ 當期維護分攤率
(貸):已分攤加工費用(Absorption) @當期維護分攤率

如果採用標準外包作業流程,則於驗收作業時產生如下之分錄:
(借):收貨科目 (Receiving Inventory) @ PO Price
(貸):存貨AP應計額 (Inventory AP Accrual) @ PO Price?

應付帳款立帳作業,產生會計分錄如下:
(借):存貨AP應計額 (Inventory AP Accrual) @ PO Price
(貸):應付帳款科目 @應付帳款立賬本幣金額
(借 or貸):商業發票價格差異(Invoice Price Variance, IPV)
採購單匯差收益/損失(Rate Variance Gain/Loss)

收回工單時,有應付帳款立帳信息,則依循立帳信息,無立帳信息,則採用採購單信息,產生會計分錄如下 (假設有應付帳款立帳信息):
(借):在製品-委外加工(WIP-Outside Process)@應付帳款立賬本幣金額
(貸):收貨科目 (Receiving Inventory) @ PO Price
(借 or貸):商業發票價格差異(Invoice Price Variance, IPV)
採購單匯差收益/損失(Rate Variance Gain/Loss)

工單完工入庫時會產生如下的分錄,其中借方科目依據完工入庫的成品/半成品料號所對應的分類(Category),讀取「週期性成本」的「週期性科目指定」貸方科目為「在製品會計分類」的「計價科目」。
(借):存貨科目 (MTL Valuation)
(貸):在製品計價科目 (WIP Valuation)

工單完工入庫數 = 工單開立數時,系統會將狀態切換為「完工(Complete)」。
生管於月底結帳前,需檢視所有未結工單是否仍會有交易會發生,針對可結案的工單,需將工單狀態切換為「完工 – 不允許費用再入帳(Complete-No Charge)」。
成會於月底結帳時,查詢所有狀態為「完工 – 不允許費用再入帳(Complete-No Charge)」的工單,執行工單成本結案動作。
工單結案時,如果工單上仍有剩餘在製品價值,會依成本元素分別結至「在製品會計分類」的對應「差異科目」,產生如下之分錄:
(借or 貸):在製品計價科目 (WIP Valuation)
(貸 or 借):在製品差異科目 (WIP Variance)

RMA 作業

有「銷退」、「退修」與「換貨」三種型態。
換貨作業採用訂單出貨與RMA收貨方式處理,並用「暫領待退料」來表達尚未歸還的部分,並需透過輔助報表協助表達已歸還部分是否有差異發生,如有差異,於總帳進行調整,調至「製造費用」科目。
上述差異的發生,一方面可能是領出與歸還的料號不同,這部分確實屬於差異,另一方面即使同一料號,因為領出與歸還的期間不同,亦會有差異的發生,照道理說,這部分的差異是不應該發生的。

假設 H 出原物料給 W,在途資產屬於接收方W,則H出貨時產生如下分錄(Transfer Credit 為轉撥利得):
(借) 在途存貨(Intransit, W) 應收帳款(Receivable, H)
(貸) 原物料(Material, H) 移轉銷退折讓(Transfer Credit, H)
應付帳款(Payable, W)?

W收貨時,產生如下的分錄:
(借) 原物料(Material, W)
(貸) 在途存貨(Intransit, W)

週期性成本,成品或半成品完工入庫時之成本計算
依據各站的單位成本貢獻加總而得,表達上有區分成本要素(Cost Elements)。
當站的單位貢獻成本 = (當站發生的成本 – 工單入庫, 當站已Relief 成本) / (當站移轉數 – 工單入庫數)。

S_ALR_87012284 : Balance Sheet / Profit and Loss Statement


銷售成本 觀念

  1. PGI : 借5xx銷貨成本(-),貸1xx庫存(-) ; Billing : 借1xxAR(+),貸4xx銷貨收入(+) ;
  2. 標改差減少 : 借1xx存貨價值(-) , 貸5xx標改差(-)
  3. 標改差在 B/S 左邊資產減少(貸-),故右邊 5* 也要跟著減少(借-)(就像借銷貨成本-;貸銷貨收入+)。其差異會跑到成本差異(也就是成本增加)。
    例如,上月存貨2,000萬,本月1,800萬;其200萬差異會跑到 "成本差異-當期"。
  4. 成本調整-分配 則是和 實際成本 的 價量差 相關,會影響實際成本
  5. 公報影響數->閒置產能成本 算法:原本400KK產能,本月只做到300KK,則1/4*折舊攤提 則為其 閒置產能成本
  6. 公報影響數->存貨評價提列 算法:呆滯提列
  7. 投入成本 會在月結時轉入存貨
  8. 成本調整-分配 會在 月結時按照週轉率,分配給存貨 及 成本(成本調整-分配-成本調整-其他)



2011年3月22日 星期二

ubuntu : 在本地的X-Window 看遠端的X-Window程式

本端機器:
   1. ~$ sudo vi /etc/X11/xinit/xserverrc:
      Remove the "-nolisten tcp"
   2. ~$ sudo vi /etc/gdm/gdm.schemas:
      Comment out the "DisallowTCP=true" so that it doesn't add the -nolisten back.
   3. Really restart X
      The easiest way is to probably kill gdm and then restart it from a text login:
      ~$ sudo service gdm stop
      At a text login:
      ~$ sudo service gdm start
   4. ~$ xhost +
   5. ~$ ifconfig 查詢目前IP address

遠端機器:
   1.  export DISPLAY=本端機器IP address:0.0
   2. ~$ xclock

2011年3月20日 星期日

Find process causing high iowait

1.
pidstat -d 2
pidstat -d | sort -nk 3
iotop -d 2
好用啊...

2.
Use top and look for processes in the 'D' state, or ps aux | grep " D "

stat 中的參數意義如下:
   
D 不可中斷 Uninterruptable(usually IO)
   
R 正在運行,或在隊列中的進程
   
S 處於休眠狀態
   
T 停止或被追踪
   
Z 殭屍進程
   
W 進入內存交換(從內核2.6開始無效)
   
X 死掉的進程


 3.
top - 09:34:12 up 2 days, 20:57,  2 users,  load average: 1.83, 1.99, 2.03
Tasks:  59 total,   2 running,  57 sleeping,   0 stopped,   0 zombie
Cpu(s):  0.3%us,  0.0%sy,  0.0%ni,  0.0%id, 99.7%wa,  0.0%hi,  0.0%si,  0.0%st

That 99.7% wa is iowait, it means the server is waiting for a process to complete an IO operation or in plain English, there is a delay in reading and/or writing data to the hard drive.
Here are some ways to get an idea of what is going on (in RPM based Distros this package is called "sysstat") and contains the very helpful binary called "iostat".  There's another package I like called "dstat" that does a great job too.
Run iostat -d 5 (it refreshes the data every 5 seconds):
Device:            tps   Blk_read/s   Blk_wrtn/s   Blk_read   Blk_wrtn
sda1              2.07         5.27        28.66    1309570    7120384
sda2              0.00         0.03         0.04       7496       8832

Device:            tps   Blk_read/s   Blk_wrtn/s   Blk_read   Blk_wrtn
sda1             27.15         0.00       357.68          0       1792
sda2              0.00         0.00         0.00          0          0

What we're seeing is that the iowait must be caused primarily by blocks being written to /dev/sda1 which is mounted as / (my root filesystem).  So now we know the main cause is by an application constantly writing to the root partition, but we still don't know what process is directly responsible for this.
If you have a newer kernel it's often possible to view processes by io usage, you can test for this by running: cat /proc/self/io
If the file is not found then you don't have io stats enabled in your kernel.  Then you can check a suspected process by running cat /proc/13/io (replace the 13 with the PID you want to check).

read_bytes: 0
write_bytes: 0
cancelled_write_bytes: 0


2011年3月19日 星期六

SQL overlaps function

1.
select 'X' dummy
  from dual
 where (sysdate,sysdate+1) overlaps (sysdate-2,sysdate+3)

2.
select case
       when (sysdate,sysdate+1) overlaps (sysdate-2,sysdate+3) then 1
       else 0
        end dummy
  from dual

3.
select case
       when (sysdate,sysdate+1) overlaps (sysdate-2,sysdate+3) then least(sysdate,sysdate-2)
       else null
        end valid_from,
       case
       when (sysdate,sysdate+1) overlaps (sysdate-2,sysdate+3) then greatest(sysdate+1,sysdate+3)
       else null
        end valid_to
  from dual

使用Report Viewer 載入 Reporting Service (外部網頁用/Role-based用)

1.
        目前於測試環境開始試著將週期性的資料擷取需求藉由Reporting Service彙整,以及設定排程,先於使用單位上班前產生快照集,並以mail寄出,以減少手動執行T-SQL的機會及時間,有效的運用系統所提供的服務。
        另外,有部份的例行性報表,亦也可以先使用SSRS開發,發行至Reporting Server後,再由web的程式使用ReportViewer來呼叫使用,而使用VS2005ReportViewer只要將其拖曳至設計畫面後,
點選『▼智慧標籤』即會出現如左圖的對話框,如果是要直接載入ReportServer上的報表檔,就以“Remore”的方式,設定下列參數:
‧選擇報表:<伺服器報表>
‧報表伺服器URLhttp://localhost/reportserver
‧報表路徑:/MyReport/Report1 
    可是,別以為這樣就可以了順利看到報表囉!因為Reporting Service預設是以Windows認證,所以需要再指定可以登入使用的帳號與密碼,但是問題來了,工具根本沒有提供可以設定帳號與密碼的屬性欄位!
    而要可以順利的看到報表,則需要藉用IReportServerCredentials來通過Reporting Service認證,以下的程式由微軟官網剪貼來的!

2.
using System;
using System.Data;
using System.Configuration;
using System.Net;
using System.Security.Principal;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Microsoft.Reporting.WebForms;
 
public partial class _Default : System.Web.UI.Page
{
    protected void Page_Init(object sender, EventArgs e)
    {
        // IsPostBack加上後,參數refresh就不會回到default value
        If (IsPostBack == false) {
        ReportViewer1.ServerReport.ReportServerCredentials = new MyReportServerCredentials();
        }
    }
}

3.
public sealed class MyReportServerCredentials:IReportServerCredentials
{
    public WindowsIdentity ImpersonationUser
    {
        get
        {
            // Use the default Windows user.  Credentials will be
            // provided by the NetworkCredentials property.
            return null;
        }
    }
    public ICredentials NetworkCredentials
    {
        get
        {
            // Read the user information from the Web.config file. 
            // By reading the information on demand instead of
            // storing it, the credentials will not be stored in
            // session, reducing the vulnerable surface area to the
            // Web.config file, which can be secured with an ACL.
 
            // User name
            string userName = ConfigurationManager.AppSettings["MyReportViewerUser"];
 
            if (string.IsNullOrEmpty(userName))
                throw new Exception("Missing user name from web.config file");
 
            // Password
            string password = ConfigurationManager.AppSettings["MyReportViewerPassword"];
 
            if (string.IsNullOrEmpty(password))
                throw new Exception("Missing password from web.config file");
 
            // Domain
            string domain = ConfigurationManager.AppSettings["MyReportViewerDomain"];
 
            if (string.IsNullOrEmpty(domain))
                throw new Exception("Missing domain from web.config file");
 
            return new NetworkCredential(userName, password, domain);
        }
    }
    public bool GetFormsCredentials(out Cookie authCookie,
                out string userName, out string password,
                out string authority)
    {
        authCookie = null;
        userName = null;
        password = null;
        authority = null;
 
        // Not using form credentials
        return false;
    }
}

4.
  而將上述的程式剪貼到程式後,還需要到Web.Config新增三個值,因為程式由appSettings取得帳號、密碼、網域值,設定如下:
     <appSettings>
           ……
           <add key="MyReportViewerUser" value="myuser"/>
           <add key="MyReportViewerPassword" value="mypasswd"/>
           <add key="MyReportViewerDomain" value="http://localhost"/>
     </appSettings>

5.
    Web.Config(黃色部份為手動新增)
<?xml version="1.0"?>
<!--
    注意: 除了手動編輯這個檔案以外,您也可以使用
    Web 管理工具設定您的應用程式設定值。請使用
    Visual Studio 中的 [網站] -> [ASP.NET 組態] 選項。
    如需完整的設定與註解清單,請參考
    machine.config.comments (通常位於
    \Windows\Microsoft.Net\Framework\v2.x\Config)
-->
<configuration>
     <appSettings>
           <add key="CrystalImageCleaner-AutoStart" value="true"/>
           <add key="CrystalImageCleaner-Sleep" value="60000"/>
           <add key="CrystalImageCleaner-Age" value="120000"/>
           <add key="MyReportViewerUser" value="myuser"/>
           <add key="MyReportViewerPassword" value="mypasswd"/>
           <add key="MyReportViewerDomain" value="http://localhost"/>
     </appSettings>
     <connectionStrings/>
     <system.web>
           <!--
            設定 compilation debug="true" 會將偵錯
            符號插入編譯過的頁面。因為這樣會
            影響效能,所以只有在開發期間才能將
            這個值設定為 true。
        -->
           <compilation debug="true">
                <assemblies>
                     <add assembly="CrystalDecisions.Web, Version=10.2.3600.0, Culture=neutral, PublicKeyToken=692FBEA5521E1304"/>
                     <add assembly="CrystalDecisions.Shared, Version=10.2.3600.0, Culture=neutral, PublicKeyToken=692FBEA5521E1304"/>
                     <add assembly="CrystalDecisions.ReportSource, Version=10.2.3600.0, Culture=neutral, PublicKeyToken=692FBEA5521E1304"/>
                     <add assembly="CrystalDecisions.Enterprise.Framework, Version=10.2.3600.0, Culture=neutral, PublicKeyToken=692FBEA5521E1304"/>
                     <add assembly="CrystalDecisions.Enterprise.Desktop.Report, Version=10.2.3600.0, Culture=neutral, PublicKeyToken=692FBEA5521E1304"/>
                     <add assembly="CrystalDecisions.CrystalReports.Engine, Version=10.2.3600.0, Culture=neutral, PublicKeyToken=692FBEA5521E1304"/>
                     <add assembly="CrystalDecisions.Enterprise.InfoStore, Version=10.2.3600.0, Culture=neutral, PublicKeyToken=692FBEA5521E1304"/>
                     <add assembly="CrystalDecisions.ReportAppServer.ClientDoc, Version=10.2.3600.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"/>
                     <add assembly="CrystalDecisions.Windows.Forms, Version=10.2.3600.0, Culture=neutral, PublicKeyToken=692FBEA5521E1304"/></assemblies>
                <buildProviders>
                     <add extension=".rdlc" type="Microsoft.Reporting.RdlBuildProvider, Microsoft.ReportViewer.Common, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
                </buildProviders>
           </compilation>
           <!--
            <authentication> 區段可以用來設定 ASP.NET
            使用的安全性驗證模式,以識別連入的
            使用者。
        -->
           <authentication mode="Windows"/>
           <httpHandlers>
                <add path="CrystalImageHandler.aspx" verb="GET" type="CrystalDecisions.Web.CrystalImageHandler, CrystalDecisions.Web, Version=10.2.3600.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"/>
                <add path="Reserved.ReportViewerWebControl.axd" verb="*" type="Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" validate="false"/>
           </httpHandlers></system.web>
</configuration>

6.
綜合上述,簡單整理一下步驟:
一、當然是要在Reporting Server上先有可執行的報表檔及帳號密碼。
二、拖曳ReportViewer至設計版面,點選智慧標籤後設定三個參數。
三、ReportServerCredentials(微軟官網提供的認證程式)剪貼到程式適當的位置。
四、打開Web.Config,在<appSettings>標籤中加入三個參數值。

完成上述步驟後,可以直接在瀏覽器中檢視asp.net的程式囉!




2011年3月16日 星期三

我為何而戰

為了那些愛我和我愛的人,為了人的尊嚴和自由權利,為了少女唇上的輕笑和兒童無邪的容顏,為了春天盛開的花朵,為了守護那些我珍惜和熱愛的美好事物不受踐踏——對不起,我語言笨拙無法把意思表達出來,但我堅信,人世間有些事物,值得我用生命捍衛。

紫川:第十五卷西南的統領第六章皇朝舊事

2011年3月15日 星期二

Oracle Listener Slow Response

11g Listener 看來會reference /etc/resolve.conf 的name server。
11g Listener也不會reference /etc/hosts資料
11g Listener也不會reference /etc/network/interfaces 其dns server設定資料

將其有問題/etc/resolve.conf entry mark以後,速度恢復。

search xxx.com.tw yyy.xxx.com.tw
#nameserver 10.56.34.1 這台很奇怪,會造成listener connect 很慢(原來那段時間crash了)
nameserver 10.56.34.2

2011年3月11日 星期五

Why does lsnrctl status display 3 services

1. status UNKOWN : listener.ora 中 SID_LIST_LISTENER 定義的
2. 下面兩個services則是spfile/pfile 定義
3. 如果刪掉listener.ora 中 SID_LIST_LISTENER 定義後,重啟listener,則status UNKOWN會不見
4. PMON每隔一分鐘會重新向listener重新註冊 下面兩個services

5. client端連線方式 如上圖SID or 服務名稱。必須和其parameter 定義的一樣。
6. 如果用listener.ora就要和 SID_LIST_LISTENER 定義的一樣。

lsnrctl - why status unknown

An 'UNKNOWN' status means that the instance is registered statically (with a SID_LIST) in the listener.ora file, rather than dynamically with service registration.

Ubuntu 和網路設定相關的檔案

1./etc/hosts :這個是最早的 hostname 對應 IP 的檔案;
2./etc/network/interfaces : 網卡設定

3./etc/nsswitch.conf : Name Service Switch Functionality;這個檔案則是在『決定』先要使用 /etc/hosts 還是 /etc/resolv.conf 的設定!
一般而言, Linux 的預設主機名稱與 IP 的對應搜尋都以 /etc/hosts 為優先,為什麼呢?你可以查看一下 /etc/nsswitch.conf ,並找到 hosts 的項目:
[root@www ~]# vim /etc/nsswitch.conf
hosts:      files dns 

上面那個 files 就是使用 /etc/hosts,而最後的 dns 則是使用 /etc/resolv.conf 的 DNS 伺服器來進行搜尋啦!因此,你可以先以 /etc/hosts 來設定 IP 對應!當然啦,你也可以將他調換過來,不過,總是 /etc/hosts 比較簡單,所以將他擺在前面比較好啦!
4./etc/resolv.conf : DNS 解析该文件是DNS域名解析的配置文件,它的格式很简单,每行以一个关键字开头,后接配置参数。resolv.conf的关键字主要有四个,分别是:
nameserver   #定义DNS服务器的IP地址
domain       #定义本地域名
search       #定义域名的搜索列表
sortlist     #对返回的域名进行排序 
/etc/resolv.conf的一个示例:
domain ringkee.com
search www.ringkee.com ringkee.com
nameserver 202.96.128.86
nameserver 202.96.128.166 
最主要是nameserver关键字,如果没指定nameserver就找不到DNS服务器,其它关键字是可选的。
DNS 伺服器的 IP 可以設定多個,為什麼要設定多個呢?因為當第一部 (照設定的順序) DNS 掛點時,我們用戶端可以使用第二部 (上述是 139.175.10.20) 來進行查詢,這多少有點像 DNS 備援功能。 通常建議至少填寫兩部 DNS 伺服器的 IP,不過在網路正常使用的情況下,永遠只有第一部 DNS 伺服器會被使用來查詢,其他的設定值只是在第一部出問題時才會被使用。
盡量不要設定超過 3 部以上的 DNS IP 在 /etc/resolv.conf 中,因為如果是你的區網出問題,導致無法連線到 DNS 伺服器,那麼你的主機還是會向每部 DNS 伺服器發出連線要求,每次連線都有 timeout 時間的等待,會導致浪費非常多的時間喔!
http://linux.die.net/man/5/resolver此文章討論resolv.conf其他option的設定,例如timeout設定如下:
options timeout:1

DNS設置引起的登錄延遲

一 套Linux上的11.1.0.7系统,操作系统管理人员最近对该服务器上的网络配置文件/etc/nsswitch.conf进行了调整,调整前其主机 名解析选项为”hosts:files dns” ,调整后被修改成了”hosts:files [NOTFOUND=continue] dns”;此后应用人员尝试在该主机上使用
“sqlplus username/password@connect_string”远程登录数据库都会出现多达五分钟的延迟,使用lsnrctl status命令查看监听器状态,发现LISTENER一切正常;初步可以判断是dns解析导致了长时间的延迟。

针对以上问题,首先想到的是设置client端Oracle network trace以了解造成延迟的具体原因,在$ORACLE_HOME/network/admin/sqlnet.ora配置文件中加入以下记录:
1
2
3
4
5
TRACE_LEVEL_CLIENT = 16
TRACE_FILE_CLIENT = client
TRACE_DIRECTORY_CLIENT = [any valid directory path]
TRACE_TIMESTAMP_CLIENT = ON
DIAG_ADR_ENABLED=off
之后再次尝试登录就会触发Oracle Network Trace文件在$TRACE_DIRECTORY_CLIENT指定的目录下产生(如果DIAG_ADR_ENABLED未设置为false,那么 11g下TRACE_DIRECTORY_CLIENT并不生效,而会产生在11g特有的diag目录下)。
登录测试产生的trace文件记录:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
[02-SEP-2010 07:36:57:719] nsc2addr: (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=m218279apss2012-vip)(PORT=1521))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=MOTOIDP.MOT.COM)(INSTANCE_NAME=MOTOIDP1)(CID=(PROGRAM=sqlplus)(HOST=m218279apss2012.mot.com)(USER=oraoid))))
[02-SEP-2010 07:36:57:719] nttbnd2addr: entry
[02-SEP-2010 07:36:57:719] snlinGetAddrInfo: entry
[02-SEP-2010 07:36:57:719] snlinGetAddrInfo: getaddrinfo() failed with error -2
[02-SEP-2010 07:36:57:719] snlinGetAddrInfo: exit
[02-SEP-2010 07:36:57:719] nttbnd2addr: looking up IP addr for host: m218279apss2012-vip
[02-SEP-2010 07:36:57:719] snlinGetAddrInfo: entry
[02-SEP-2010 07:36:57:719] snlinGetAddrInfo: exit
[02-SEP-2010 07:36:57:719] snlinFreeAddrInfo: entry
[02-SEP-2010 07:36:57:719] snlinFreeAddrInfo: exit
[02-SEP-2010 07:36:57:719] nttbnd2addr: exit
..................
[02-SEP-2010 07:36:57:722] nspsend: packet dump
[02-SEP-2010 07:36:57:722] nspsend: 01 1E 00 00 01 00 00 00  |........|
[02-SEP-2010 07:36:57:722] nspsend: 01 3A 01 2C 0C 41 20 00  |.:.,.A..|
[02-SEP-2010 07:36:57:722] nspsend: 7F FF 7F 08 00 00 01 00  |........|
[02-SEP-2010 07:36:57:722] nspsend: 00 E4 00 3A 00 00 02 00  |...:....|
[02-SEP-2010 07:36:57:722] nspsend: 41 41 00 00 00 00 00 00  |AA......|
[02-SEP-2010 07:36:57:722] nspsend: 00 00 00 00 00 00 00 00  |........|
[02-SEP-2010 07:36:57:722] nspsend: 00 00 00 00 00 00 00 00  |........|
[02-SEP-2010 07:36:57:722] nspsend: 00 00 28 44 45 53 43 52  |..(DESCR|
[02-SEP-2010 07:36:57:722] nspsend: 49 50 54 49 4F 4E 3D 28  |IPTION=(|
[02-SEP-2010 07:36:57:722] nspsend: 41 44 44 52 45 53 53 3D  |ADDRESS=|
[02-SEP-2010 07:36:57:722] nspsend: 28 50 52 4F 54 4F 43 4F  |(PROTOCO|
[02-SEP-2010 07:36:57:722] nspsend: 4C 3D 54 43 50 29 28 48  |L=TCP)(H|
[02-SEP-2010 07:36:57:722] nspsend: 4F 53 54 3D 6D 32 31 38  |OST=m218|
[02-SEP-2010 07:36:57:722] nspsend: 32 37 39 61 70 73 73 32  |279apss2|
[02-SEP-2010 07:36:57:722] nspsend: 30 31 32 2D 76 69 70 29  |012-vip)|
[02-SEP-2010 07:36:57:722] nspsend: 28 50 4F 52 54 3D 31 35  |(PORT=15|
[02-SEP-2010 07:36:57:722] nspsend: 32 31 29 29 28 43 4F 4E  |21))(CON|
[02-SEP-2010 07:36:57:722] nspsend: 4E 45 43 54 5F 44 41 54  |NECT_DAT|
[02-SEP-2010 07:36:57:722] nspsend: 41 3D 28 53 45 52 56 45  |A=(SERVE|
[02-SEP-2010 07:36:57:722] nspsend: 52 3D 44 45 44 49 43 41  |R=DEDICA|
[02-SEP-2010 07:36:57:722] nspsend: 54 45 44 29 28 53 45 52  |TED)(SER|
[02-SEP-2010 07:36:57:722] nspsend: 56 49 43 45 5F 4E 41 4D  |VICE_NAM|
[02-SEP-2010 07:36:57:722] nspsend: 45 3D 4D 4F 54 4F 49 44  |E=MOTOID|
[02-SEP-2010 07:36:57:722] nspsend: 50 2E 4D 4F 54 2E 43 4F  |P.MOT.CO|
[02-SEP-2010 07:36:57:722] nspsend: 4D 29 28 49 4E 53 54 41  |M)(INSTA|
[02-SEP-2010 07:36:57:722] nspsend: 4E 43 45 5F 4E 41 4D 45  |NCE_NAME|
[02-SEP-2010 07:36:57:722] nspsend: 3D 4D 4F 54 4F 49 44 50  |=MOTOIDP|
[02-SEP-2010 07:36:57:722] nspsend: 31 29 28 43 49 44 3D 28  |1)(CID=(|
[02-SEP-2010 07:36:57:722] nspsend: 50 52 4F 47 52 41 4D 3D  |PROGRAM=|
[02-SEP-2010 07:36:57:722] nspsend: 73 71 6C 70 6C 75 73 29  |sqlplus)|
[02-SEP-2010 07:36:57:722] nspsend: 28 48 4F 53 54 3D 6D 32  |(HOST=m2|
[02-SEP-2010 07:36:57:722] nspsend: 31 38 32 37 39 61 70 73  |18279aps|
[02-SEP-2010 07:36:57:722] nspsend: 73 32 30 31 32 2E 6D 6F  |s2012.mo|
[02-SEP-2010 07:36:57:722] nspsend: 74 2E 63 6F 6D 29 28 55  |t.com)(U|
[02-SEP-2010 07:36:57:722] nspsend: 53 45 52 3D 6F 72 61 6F  |SER=orao|
[02-SEP-2010 07:36:57:722] nspsend: 69 64 29 29 29 29        |id))))  |
[02-SEP-2010 07:36:57:722] nspsend: 286 bytes to transport
[02-SEP-2010 07:36:57:722] nspsend: normal exit
[02-SEP-2010 07:36:57:722] nscon: exit (0)
[02-SEP-2010 07:36:57:722] nsdo: nsctxrnk=0
[02-SEP-2010 07:36:57:722] nsdo: normal exit
[02-SEP-2010 07:36:57:722] nsdo: entry
[02-SEP-2010 07:36:57:722] nsdo: cid=0, opcode=68, *bl=512, *what=9, uflgs=0x0, cflgs=0x3
[02-SEP-2010 07:36:57:722] nsdo: rank=64, nsctxrnk=0
[02-SEP-2010 07:36:57:722] nsdo: nsctx: state=2, flg=0x4005, mvd=0
[02-SEP-2010 07:36:57:722] nsdo: gtn=10, gtc=10, ptn=10, ptc=8155
[02-SEP-2010 07:36:57:722] nscon: entry
[02-SEP-2010 07:36:57:722] nscon: recving a packet
[02-SEP-2010 07:36:57:722] nsprecv: entry
[02-SEP-2010 07:36:57:722] nsprecv: reading from transport...
[02-SEP-2010 07:36:57:722] nttrd: entry
[02-SEP-2010 07:41:57:741] nttrd: socket 9 had bytes read=8
[02-SEP-2010 07:41:57:741] nttrd: exit
[02-SEP-2010 07:41:57:741] nsprecv: 8 bytes from transport
[02-SEP-2010 07:41:57:741] nsprecv: tlen=8, plen=8, type=11
[02-SEP-2010 07:41:57:741] nsprecv: packet dump
[02-SEP-2010 07:41:57:741] nsprecv: 00 08 00 00 0B 00 00 00  |........|
[02-SEP-2010 07:41:57:741] nsprecv: normal exit
可以看到以上出现了”snlinGetAddrInfo: getaddrinfo() failed with error -2″的记录,通过关键词”snlinGetAddrInfo”在MOS上搜索可以找到以下Note:
Remote Connections Take Very Long to Establish

Applies to:

Oracle Net Services – Version: 11.1.0.6 to 11.1.0.7 – Release: 11.1 to 11.1
Information in this document applies to any platform.

Symptoms

When you connect remotely, it takes very long until the connection is established. Once connected, everything works fine.
Local bequeath connections work in a timely manner.
Resolution of hostnames is done via a centralized DNS server.

Cause

Listener traces show the listener is wasting time while calling the “snlinGetAddrInfo” function :
2009-07-08 13:58:35.135311 : nttcnp:exit
2009-07-08 13:58:35.135327 : snlinGetAddrInfo:entry
2009-07-08 13:58:55.135643 : snlinGetAddrInfo:getaddrinfo() failed with error -5
2009-07-08 13:58:55.135703 : snlinGetAddrInfo:exit

Solution

We need to make sure that the DNS server(s) configured are reachable.
The “snlinGetAddrInfo” function is a TCP layer function which Oracle uses (since version 11g) for hostname-to-IP mappings.
When the DNS server is unreachable, the listener will wait for some time until it will time out and fail over to the next method configured for resolution of hostnames (usually the local “hosts” file).
Note : On UNIX systems, the order of methods used for resolution of hostnames can be specified via the /etc/nsswitch.conf and /etc/host.conf files :
  • on Linux systems, you can specify the order by setting “hosts” to “files” and / or “dns”
Example for /etc/nsswitch.conf :
hosts: files [NOTFOUND=continue] dns
  • on HP-UX and Solaris systems, you need to specify the order using the “ipnodes” keyword
    Example for /etc/nsswitch.conf :
    ipnodes: files [NOTFOUND=continue] dns
Note : Since 11.2, this behaviour has changed and naming lookup is no longer performed at this stage (the changes was addressed through unpublished Bug 9593134).
这个文档指出snlinGetAddrInfo函数用以主机名到ip地址的映射,并建议使用在/etc/nsswitch.conf网络配置文件中 设置过程为”hosts: files [NOTFOUND=continue] dns”,而我们恰恰正是这样做的!另一个文档[ID 803838.1]指出在其他UNIX平台上,可以使用”ipnodes: files [NOTFOUND=continue] dns”方式避免延迟问题,但Linux平台上并没有ipnodes方式。
11g中对hosts的解析实在变得有些西斯底里,这个case通过在移除nsswitch.conf中hosts的dns选项最后解决了,对于Oracle使用最简单的文件解析方式似乎仍是最稳妥的办法,不管版本有多新。
© 2010, www.oracledatabase12g.com. 版权所有.

3 comments to DNS设置引起的登录延迟

  • admin
    11g Network Layer Does Not Use /etc/hosts on UNIX

    Applies to:

    Oracle Net Services – Version: 11.1.0.6 to 11.1.0.7
    Generic UNIX

    Symptoms

    After upgrading to 11g Oracle functionality bypasses the /etc/hosts file when resolving hostnames to IPs and instead query the DNS server. This can introduce some delay in establishing a connection to a remote host compared with 10g.
    SQL*Plus and tnsping show this behavior but this delay can appear also when opening a dblink or anytime tcpip connections are established by the Oracle Network layer.
    This happens even if  Name Server Switch configuration (nsswitch) specifies the hosts file prior to dns lookups:
    /etc/nsswitch.conf
    hosts: files [NOTFOUND=continue] dns

    or only:
    hosts: files
    If we obtain truss/tusc trace for a SQL*Plus connection we find the following sequence of OS system calls:
    On 10g after reading the nsswitch.conf file, library “libnss_files.so” is loaded then /etc/hosts is read and the socket is opened:
    open(“/etc/nsswitch.conf”, O_RDONLY|0×800, 0666) = 5
    ioctl(5, TCGETA, 0x9fffffffffffaca0) ERR#25 ENOTTY
    read(5, “# \n# / e t c / n s s w i t c “.., 8192) = 92
    read(5, 0x60000000001e6078, 8192) = 0
    close(5) = 0
    open(“/usr/lib/hpux64/libnss_files.so.1″, O_RDONLY|0×800, 0) = 5
    fstat(5, 0x9fffffffffffa720) = 0
    pread(5, “7fE L F 0202010101\0\0\0\0\0\0\0″.., 1024, 0) = 1024
    stat(“/usr/lib/hpux64/dpd”, 0x9fffffffffff9cd0) = 0
    open(“/usr/lib/hpux64/dpd/libnss_files.so.1.bpd”, O_RDONLY|0×800, 0) ERR#2 ENOENT
    getuid() = 305 (305)
    getgid() = 303 (303)
    mmap(NULL, 85872, PROT_READ|PROT_EXEC, MAP_SHARED|MAP_SHLIB, 5, 0) = 0xc0000000008d8000
    mmap(NULL, 3159, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_SHLIB, 5, 131072) = 0x9fffffffbf63d000
    close(5) = 0
    getuid() = 305 (305)
    getgid() = 303 (303)
    open(“/etc/hosts”, O_RDONLY|0×800, 0666) = 5
    ioctl(5, TCGETA, 0x9fffffffffffac30) ERR#25 ENOTTY
    read(5, “# / e t c / h o s t s \n# \n# “.., 8192) = 8192
    lseek(5, 18446744073709549410, SEEK_CUR) = 5986
    close(5) = 0
    socket(AF_INET, SOCK_STREAM, 0) = 5
    connect(5, 0x60000000001f0680, 16) = 0
    getsockname(5, 0x9fffffffffffb750, 0x9fffffffffffb740) = 0
    getsockopt(5, SOL_SOCKET, SO_SNDBUF, 0x9fffffffffffb890, 0x9fffffffffffb894) = 0
    getsockopt(5, SOL_SOCKET, SO_RCVBUF, 0x9fffffffffffb890, 0x9fffffffffffb894) = 0
    setsockopt(5, 0×6, TCP_NODELAY, 0x9fffffffffffb89c, 4) = 0

    But on 11g after reading the nsswitch.conf  library “libnss_dns.so” is loaded then /etc/resolv.conf (which specifies available domain name servers) is read and much later a socket for TCP/IP (SOCK_STREAM) is opened. :
    open(“/etc/nsswitch.conf”, O_RDONLY|0×800, 0666) = 5
    ioctl(5, TCGETA, 0x9fffffffffffa360) ERR#25 ENOTTY
    read(5, “# \n# / e t c / n s s w i t c “.., 8192) = 92
    read(5, 0x60000000001c9058, 8192) = 0
    close(5) = 0
    open(“/usr/lib/hpux64/libnss_dns.so.1″, O_RDONLY|0×800, 0) = 5
    fstat(5, 0x9fffffffffff9de0) = 0
    pread(5, “7fE L F 0202010101\0\0\0\0\0\0\0″.., 1024, 0) = 1024
    stat(“/usr/lib/hpux64/dpd”, 0x9fffffffffff9390) = 0
    open(“/usr/lib/hpux64/dpd/libnss_dns.so.1.bpd”, O_RDONLY|0×800, 0) ERR#2 ENOENT
    getuid() = 305 (305)
    getgid() = 303 (303)
    mmap(NULL, 49440, PROT_READ|PROT_EXEC, MAP_SHARED|MAP_SHLIB, 5, 0) = 0xc00000000b054000
    mmap(NULL, 800, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_SHLIB, 5, 65536) = 0x9fffffffbf68d000
    close(5) = 0
    getuid() = 305 (305)
    getgid() = 303 (303)
    getuid() = 305 (305)
    getgid() = 303 (303)
    open(“/test/local/oracle/11.1.0.7/lib/libdl.so.1″, O_RDONLY|0×800, 0) ERR#2 ENOENT
    open(“/test/local/oracle/11.1.0.7/lib32/libdl.so.1″, O_RDONLY|0×800, 0) ERR#2 ENOENT
    getuid() = 305 (305)
    getgid() = 303 (303)
    open(“/usr/lib/hpux64/libdl.so.1″, O_RDONLY|0×800, 0) = 5
    fstat(5, 0x9fffffffffff9cf0) = 0
    read(5, “7fE L F 0202010101\0\0\0\0\0\0\0″.., 64) = 64
    close(5) = 0
    socket(AF_INET, SOCK_DGRAM, 0) = 5
    ioctl(5, SIOCGIFNUM, 0x9fffffffffff9680) = 0
    ioctl(5, SIOCGIFCONF, 0x9fffffffffff9690) = 0
    socket(AF_INET6, SOCK_DGRAM, 0) = 6
    ioctl(6, SIOCGLIFNUM, 0x9fffffffffff9684) = 0
    ioctl(6, SIOCGLIFCONF, 0x9fffffffffff96a0) = 0
    ioctl(5, SIOCGIFFLAGS, 0x9fffffffffff96b0) = 0
    close(5) = 0
    close(6) = 0
    gettimeofday(0x9fffffffffff7dd0, NULL) = 0
    getpid() = 22968 (22967)
    open(“/etc/resolv.conf”, O_RDONLY|0×800, 0666) = 5
    ioctl(5, TCGETA, 0x9fffffffffff7da0) ERR#25 ENOTTY
    read(5, “d o m a i n t e s t . c o m \n”.., 8192) = 453
    read(5, 0x60000000001dddf8, 8192) = 0
    close(5) = 0
    …………….
    ………….
    socket(AF_INET, SOCK_STREAM, 0) = 5
    connect(5, 0x60000000001eba50, 16) = 0
    getsockname(5, 0x9fffffffffff9da0, 0x9fffffffffff94c0) = 0
    getsockopt(5, SOL_SOCKET, SO_SNDBUF, 0x9fffffffffffa000, 0x9fffffffffffa004) = 0
    getsockopt(5, SOL_SOCKET, SO_RCVBUF, 0x9fffffffffffa000, 0x9fffffffffffa004) = 0
    setsockopt(5, 0×6, TCP_NODELAY, 0x9fffffffffffa00c, 4) = 0
     

    Changes

    Nothing was changed in the configuration of the OS, only the upgrade from Oracle 10g to 11g was done.

    Cause

    What was changed between the two is the way Oracle resolves hostnames to IPs, more specifically the system call used to do that.
    Oracle 11g use now getaddrinfo() while 10g used gethostbyname().
    These system functions requires different configuration in /etc/nsswitch.conf.
    gethostbyname() require the use of keyword “hosts” while getaddrinfo() the use the keyword “ipnodes”

    Notes:
    Even though this has only been observed on HP-UX and Solaris, this may be UNIX generic.
    With Solaris, ipnodes has a different meaning (specify a file for IPV6 addresses resolution, gethostbyname and getaddrinfo both use hosts or ipnodes file).
    Linux on the other hand does not use ipnodes in nsswitch.conf

    Solution

    Add a line in the /etc/nsswitch.conf file similar to the following:

    ipnodes: files [NOTFOUND=continue] dns
    The line starting with keyword “hosts” must not be deleted.
    This way calls made by getaddrinfo() will search first in /etc/hosts then, if the name is not found, will contact the dns server.
    Thus there will be no connection delay for any lookup of host names existing in the local /etc/hosts file.

  • admin
    Sqlnet connection via TCP Hangs for about 10seconds Before Connection is Established

    Applies to:

    Oracle Server – Enterprise Edition – Version: 10.1.0.2 to 11.2.0.1.0 – Release: 10.1 to 11.2
    Information in this document applies to any platform.

    Symptoms

    10 nodes RAC cluster, sqlnet connection via TCP consistently takes 10 seconds before the connection with the server is finally established.
    $date;sqlplus apps/xxx@dwnodea @time.sql
    Tue Feb  2 17:00:39 CST 2010 SQL*Plus: Release 11.1.0.7.0 – Production on Tue Feb  2 17:00:39 2010
    Copyright (c) 1982, 2008, Oracle. All rights reserved.
    Connected to:
    Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 – 64bit Production
    With the Partitioning, Real Application Clusters, OLAP and Real Application Testing options
    TO_CHAR(SYSDATE,’YYYY-MM-DDHH24:MI:SS’)
    ————————————————————————————————————————
    2010-02-02 17:00:49
    Sqlnet tracing (both server and client) against sqlplus connection with level 16 shows:
    Server side trace:
    2010-02-02 17:00:39.432277 : nttcnp:exit
    2010-02-02 17:00:39.432308 : snlinGetAddrInfo:entry *** 2010-02-02 17:00:49.440
    2010-02-02 17:00:49.440655 : snlinGetAddrInfo:getaddrinfo() failed with error -2
    2010-02-02 17:00:49.440736 : snlinGetAddrInfo:exit
    2010-02-02 17:00:49.440751 : nttcon:exit
    2010-02-02 17:00:49.440767 : nsopen:transport is open
    2010-02-02 17:00:49.440785 : nsoptions:entry
    2010-02-02 17:00:49.440802 : nsoptions:lcl[0]=0×0, lcl[1]=0×0, gbl[0]=0×0, gbl[1]=0×0, cha=0×0
    Client side trace:
    2010-02-02 17:00:39.418598 : nscon:recving a packet
    2010-02-02 17:00:39.418714 : nsprecv:entry
    2010-02-02 17:00:39.418833 : nsprecv:reading from transport…
    2010-02-02 17:00:39.418949 : nttrd:entry
    2010-02-02 17:00:49.444643 : nttrd:socket 12 had bytes read=8

    2010-02-02 17:00:49.444832 : nttrd:exit

    Changes

    This is a new installation.

    Cause

    This issue is caused by invalid nameserver entry in /etc/resolv.conf.
    Examine system configuration files show:
    resolv.conf
    ——–
    nameserver 192.168.1.20
    nameserver 192.168.4.12 nsswitch.conf
    ———-
    #hosts: db files ldap nis dns
    hosts: files dns
    These are incorrect nameserver per customer configuration, they do not exist. Once they are removed, there is no longer any delay in sqlnet connection.

    Solution

    1. Remove incorrect setting for nameserver in /etc/resolv.conf if DNS is not in use.
    or
    2. Consult with the network administrator to provide correct nameserver IP address if DNS is in use.
  • admin
    =========================================================================
    Interim Patch for Base Bug: 9593134
    =========================================================================
    Date: Tue Aug 10 18:18:48 2010
    ————————————————————————-
    Platform Patch for : Linux-x86
    Product Patched : SQLNET
    Product Version # : 11.1.0.7.0
    RAC Rolling Installable : YES
    Bugs Fixed by this patch:
    ————————-
    9593134: DNS OR NIS MIS-CONFIGURATION CAN CAUSE SLOW DATABASE CONNECTS
    Hdr: 8307164 11.1.0.7 NET 11.1.0.7 PRODID-115 PORTID-197
    Abstract: TNSPING 11G USING DNS AND NOT HOSTS FILE
    *** 03/04/09 05:24 am ***
    TAR:
    —-
    Problem:
    ——–
    Customer has 2 oracle homes on the same HP-UX server,
    one 10g and one 11.1.0.7.
    He execute tnsping in both versions, and truss them truss -o out
    tnsping
    In 10g truss shows that the hostname from the connect descriptor is resolved
    using /etc/hosts file but in 11g the same hostname is resolved using dns.
    The same behavior is observed for sqlplus.
    Because of this connections to the database ar slow because of the slow
    hostname resolution using the dns.
    Versions:
    ———
    Diagnostic Analysis:
    ——————–
    nsswitch.conf
    ==============
    hosts: files [NOTFOUND=continue] dns
    Reproducibility:
    —————-
    on customer site, also I observered same behavior on
    internal HP-UX server with 11g database
    Test Case:
    ———-
    Workaround:
    ———–
    none