

 Amazon Redshift 將不再支援從修補程式 198 開始建立新的 Python UDFs。現有 Python UDF 將繼續正常運作至 2026 年 6 月 30 日。如需詳細資訊，請參閱[部落格文章](https://aws.amazon.com/blogs/big-data/amazon-redshift-python-user-defined-functions-will-reach-end-of-support-after-june-30-2026/)。

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 用於記錄日誌的 STL 檢視
<a name="c_intro_STL_tables"></a>

STL 系統檢視是從 Amazon Redshift 日誌檔產生，以提供系統歷史記錄。

這些檔案位於資料倉儲叢集中的每一個節點上。STL 檢視會從日誌中取得資訊，並將它們格式化為可供系統管理員使用的檢視。

**日誌保留** - STL 系統檢視會保留 7 天的日誌歷史記錄。所有叢集大小和節點類型都保證日誌保留，並且不受叢集工作負載變化的影響。日誌保留也不受叢集狀態的影響，例如叢集暫停時。只有在叢集是新的情況下，您才會有少於 7 天的日誌歷史記錄。您不需要採取任何動作來保留日誌，但必須定期將日誌資料複製到其他資料表，或將其卸載至 Amazon S3，才能保存超過 7 天的日誌資料。

**Topics**
+ [STL\$1AGGR](r_STL_AGGR.md)
+ [STL\$1ALERT\$1EVENT\$1LOG](r_STL_ALERT_EVENT_LOG.md)
+ [STL\$1ANALYZE](r_STL_ANALYZE.md)
+ [STL\$1ANALYZE\$1COMPRESSION](r_STL_ANALYZE_COMPRESSION.md)
+ [STL\$1BCAST](r_STL_BCAST.md)
+ [STL\$1COMMIT\$1STATS](r_STL_COMMIT_STATS.md)
+ [STL\$1CONNECTION\$1LOG](r_STL_CONNECTION_LOG.md)
+ [STL\$1DDLTEXT](r_STL_DDLTEXT.md)
+ [STL\$1DELETE](r_STL_DELETE.md)
+ [STL\$1DISK\$1FULL\$1DIAG](r_STL_DISK_FULL_DIAG.md)
+ [STL\$1DIST](r_STL_DIST.md)
+ [STL\$1ERROR](r_STL_ERROR.md)
+ [STL\$1EXPLAIN](r_STL_EXPLAIN.md)
+ [STL\$1FILE\$1SCAN](r_STL_FILE_SCAN.md)
+ [STL\$1HASH](r_STL_HASH.md)
+ [STL\$1HASHJOIN](r_STL_HASHJOIN.md)
+ [STL\$1INSERT](r_STL_INSERT.md)
+ [STL\$1LIMIT](r_STL_LIMIT.md)
+ [STL\$1LOAD\$1COMMITS](r_STL_LOAD_COMMITS.md)
+ [STL\$1LOAD\$1ERRORS](r_STL_LOAD_ERRORS.md)
+ [STL\$1LOADERROR\$1DETAIL](r_STL_LOADERROR_DETAIL.md)
+ [STL\$1MERGE](r_STL_MERGE.md)
+ [STL\$1MERGEJOIN](r_STL_MERGEJOIN.md)
+ [STL\$1MV\$1STATE](r_STL_MV_STATE.md)
+ [STL\$1NESTLOOP](r_STL_NESTLOOP.md)
+ [STL\$1PARSE](r_STL_PARSE.md)
+ [STL\$1PLAN\$1INFO](r_STL_PLAN_INFO.md)
+ [STL\$1PROJECT](r_STL_PROJECT.md)
+ [STL\$1QUERY](r_STL_QUERY.md)
+ [STL\$1QUERY\$1METRICS](r_STL_QUERY_METRICS.md)
+ [STL\$1QUERYTEXT](r_STL_QUERYTEXT.md)
+ [STL\$1REPLACEMENTS](r_STL_REPLACEMENTS.md)
+ [STL\$1RESTARTED\$1SESSIONS](r_STL_RESTARTED_SESSIONS.md)
+ [STL\$1RETURN](r_STL_RETURN.md)
+ [STL\$1S3CLIENT](r_STL_S3CLIENT.md)
+ [STL\$1S3CLIENT\$1ERROR](r_STL_S3CLIENT_ERROR.md)
+ [STL\$1SAVE](r_STL_SAVE.md)
+ [STL\$1SCAN](r_STL_SCAN.md)
+ [STL\$1SCHEMA\$1QUOTA\$1VIOLATIONS](r_STL_SCHEMA_QUOTA_VIOLATIONS.md)
+ [STL\$1SESSIONS](r_STL_SESSIONS.md)
+ [STL\$1SORT](r_STL_SORT.md)
+ [STL\$1SSHCLIENT\$1ERROR](r_STL_SSHCLIENT_ERROR.md)
+ [STL\$1STREAM\$1SEGS](r_STL_STREAM_SEGS.md)
+ [STL\$1TR\$1CONFLICT](r_STL_TR_CONFLICT.md)
+ [STL\$1UNDONE](r_STL_UNDONE.md)
+ [STL\$1UNIQUE](r_STL_UNIQUE.md)
+ [STL\$1UNLOAD\$1LOG](r_STL_UNLOAD_LOG.md)
+ [STL\$1USAGE\$1CONTROL](r_STL_USAGE_CONTROL.md)
+ [STL\$1USERLOG](r_STL_USERLOG.md)
+ [STL\$1UTILITYTEXT](r_STL_UTILITYTEXT.md)
+ [STL\$1VACUUM](r_STL_VACUUM.md)
+ [STL\$1WINDOW](r_STL_WINDOW.md)
+ [STL\$1WLM\$1ERROR](r_STL_WLM_ERROR.md)
+ [STL\$1WLM\$1RULE\$1ACTION](r_STL_WLM_RULE_ACTION.md)
+ [STL\$1WLM\$1QUERY](r_STL_WLM_QUERY.md)

# STL\$1AGGR
<a name="r_STL_AGGR"></a>

分析查詢的彙總執行步驟。在執行彙總函數和 GROUP BY 子句期間，即會進行這些步驟。

所有使用者都可看見 STL\$1AGGR。超級使用者可以看見所有資料列；一般使用者只能看見自己的資料。如需詳細資訊，請參閱[系統資料表和檢視中資料的可見性](cm_chap_system-tables.md#c_visibility-of-data)。

**注意**  
STL\$1AGGR 僅包含在主佈建叢集上執行的查詢。但不包含在並行擴縮叢集上或無伺服器命名空間上執行的查詢。若要存取在主要叢集、並行擴縮叢集和無伺服器命名空間上執行的查詢說明計畫，建議您使用 SYS 監控檢視 [SYS\$1QUERY\$1DETAIL](SYS_QUERY_DETAIL.md)。SYS 監視檢視中的資料會格式化為更易於使用和理解。

## 資料表欄
<a name="r_STL_AGGR-table-columns2"></a>

[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/redshift/latest/dg/r_STL_AGGR.html)

## 範例查詢
<a name="r_STL_AGGR-sample-queries2"></a>

傳回 SLICE 1 和 TBL 239 之彙總執行步驟的相關資訊。

```
select query, segment, bytes, slots, occupied, maxlength, is_diskbased, workmem, type
from stl_aggr where slice=1 and tbl=239
order by rows
limit 10;
```

```
 query | segment | bytes |  slots  | occupied | maxlength | is_diskbased |  workmem  |  type
-------+---------+-------+---------+----------+-----------+--------------+-----------+--------
   562 |       1 |     0 | 4194304 |        0 |         0 | f            | 383385600 | HASHED
   616 |       1 |     0 | 4194304 |        0 |         0 | f            | 383385600 | HASHED
   546 |       1 |     0 | 4194304 |        0 |         0 | f            | 383385600 | HASHED
   547 |       0 |     8 |       0 |        0 |         0 | f            |         0 | PLAIN
   685 |       1 |    32 | 4194304 |        1 |         0 | f            | 383385600 | HASHED
   652 |       0 |     8 |       0 |        0 |         0 | f            |         0 | PLAIN
   680 |       0 |     8 |       0 |        0 |         0 | f            |         0 | PLAIN
   658 |       0 |     8 |       0 |        0 |         0 | f            |         0 | PLAIN
   686 |       0 |     8 |       0 |        0 |         0 | f            |         0 | PLAIN
   695 |       1 |    32 | 4194304 |        1 |         0 | f            | 383385600 | HASHED
(10 rows)
```

# STL\$1ALERT\$1EVENT\$1LOG
<a name="r_STL_ALERT_EVENT_LOG"></a>

當查詢最佳化器識別可能表示效能問題的狀況時，請記錄一個提醒。使用 STL\$1ALERT\$1EVENT\$1LOG 檢視來識別提升查詢效能的機會。

查詢包含多個區段，每個區段包含一或多個步驟。如需詳細資訊，請參閱[查詢處理](c-query-processing.md)。

所有使用者都可看見 STL\$1ALERT\$1EVENT\$1LOG。超級使用者可以看見所有資料列；一般使用者只能看見自己的資料。如需詳細資訊，請參閱[系統資料表和檢視中資料的可見性](cm_chap_system-tables.md#c_visibility-of-data)。

**注意**  
STL\$1ALERT\$1EVENT\$1LOG 僅包含在主叢集上執行的查詢。但不包含在並行擴縮叢集上或無伺服器命名空間上執行的查詢。若要存取在主要叢集、並行擴縮叢集和無伺服器命名空間上執行的查詢說明計畫，建議您使用 SYS 監控檢視 [SYS\$1QUERY\$1DETAIL](SYS_QUERY_DETAIL.md)。SYS 監視檢視中的資料會格式化為更易於使用和理解。

## 資料表欄
<a name="r_STL_ALERT_EVENT_LOG-column2"></a>

[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/redshift/latest/dg/r_STL_ALERT_EVENT_LOG.html)

## 使用須知
<a name="r_STL_ALERT_EVENT_LOG-usage-notes"></a>

您可以使用 STL\$1ALERT\$1EVENT\$1LOG，識別查詢中的潛在問題，然後遵循[調校查詢效能](c-optimizing-query-performance.md)中的實務，來最佳化資料庫設計並重新撰寫查詢。STL\$1ALERT\$1EVENT\$1LOG 會記錄下列提醒：
+ **找不到統計資訊** 

  找不到統計資訊。在進行資料載入或重要更新之後執行 ANALYZE，並使用 STATUPDATE 與 COPY 操作搭配。如需詳細資訊，請參閱[設計查詢的 Amazon Redshift 最佳實務](c_designing-queries-best-practices.md)。
+ **巢狀迴圈**

  巢狀迴路通常是 Cartesian 產品。評估您的查詢，以確保所有參與資料表均已有效聯結。
+ **選擇性相當高的篩選條件**

  傳回的資料列與已掃描資料列的比率低於 0.05。已掃描列是 `rows_pre_user_filter` 的值，而傳回的列則是 [STL\$1SCAN](r_STL_SCAN.md) 系統檢視中的列值。表示查詢正在掃描例外狀況大量的資料列來決定結果集。這可能是由於找不到排序索引鍵或其不正確所致。如需詳細資訊，請參閱[排序索引鍵](t_Sorting_data.md)。
+ **過多的幽靈資料列**

  掃描已略過相當多標示為已刪除但未清空的資料列，或已插入但未遞交的資料列。如需詳細資訊，請參閱[清空資料表](t_Reclaiming_storage_space202.md)。
+ **大型分佈**

  已重新配送超過 1,000,000 個資料列，進行雜湊聯結或彙整。如需詳細資訊，請參閱[分配資料以實現查詢最佳化](t_Distributing_data.md)。
+ **大型廣播**

  已播送超過 1,000,000 個資料列，進行雜湊聯結。如需詳細資訊，請參閱[分配資料以實現查詢最佳化](t_Distributing_data.md)。
+ **序列執行**

   已在查詢計劃中指出 DS\$1DIST\$1ALL\$1INNER 重新配送樣式，其會強制序列執行，因為整個內部資料表已重新配送至單一節點。如需詳細資訊，請參閱[分配資料以實現查詢最佳化](t_Distributing_data.md)。

## 範例查詢
<a name="r_STL_ALERT_EVENT_LOG-sample-queries"></a>

下列查詢顯示四個查詢的提醒事件。

```
SELECT query, substring(event,0,25) as event, 
substring(solution,0,25) as solution, 
trim(event_time) as event_time from stl_alert_event_log order by query;

 query |             event             |          solution            |     event_time      
-------+-------------------------------+------------------------------+---------------------
  6567 | Missing query planner statist | Run the ANALYZE command      | 2014-01-03 18:20:58
  7450 | Scanned a large number of del | Run the VACUUM command to rec| 2014-01-03 21:19:31
  8406 | Nested Loop Join in the query | Review the join predicates to| 2014-01-04 00:34:22
 29512 | Very selective query filter:r | Review the choice of sort key| 2014-01-06 22:00:00

(4 rows)
```

# STL\$1ANALYZE
<a name="r_STL_ANALYZE"></a>

記錄 [ANALYZE](r_ANALYZE.md) 操作的詳細資訊。

只有超級使用者才能看到 STL\$1ANALYZE。如需詳細資訊，請參閱[系統資料表和檢視中資料的可見性](cm_chap_system-tables.md#c_visibility-of-data)。

此資料表中的部份或所有資料也會在 SYS 監控檢視 [SYS\$1ANALYZE\$1HISTORY](SYS_ANALYZE_HISTORY.md) 中找到。SYS 監視檢視中的資料會格式化為更易於使用和理解。我們建議您使用 SYS 監控檢視進行查詢。

## 資料表欄
<a name="r_STL_ANALYZE-table-columns2"></a>

[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/redshift/latest/dg/r_STL_ANALYZE.html)

## 範例查詢
<a name="r_STL_ANALYZE-sample-queries2"></a>

下列範例聯結 STV\$1TBL\$1PERM，以顯示資料表名稱和執行結果。

```
select distinct a.xid, trim(t.name) as name, a.status, a.rows, a.modified_rows, a.starttime, a.endtime
from stl_analyze a 
join stv_tbl_perm t  on t.id=a.table_id
where name = 'users'
order by starttime;

xid    | name  | status          | rows  | modified_rows | starttime           | endtime            
-------+-------+-----------------+-------+---------------+---------------------+--------------------
  1582 | users | Full            | 49990 |         49990 | 2016-09-22 22:02:23 | 2016-09-22 22:02:28
244287 | users | Full            | 24992 |         74988 | 2016-10-04 22:50:58 | 2016-10-04 22:51:01
244712 | users | Full            | 49984 |         24992 | 2016-10-04 22:56:07 | 2016-10-04 22:56:07
245071 | users | Skipped         | 49984 |             0 | 2016-10-04 22:58:17 | 2016-10-04 22:58:17
245439 | users | Skipped         | 49984 |          1982 | 2016-10-04 23:00:13 | 2016-10-04 23:00:13
(5 rows)
```

# STL\$1ANALYZE\$1COMPRESSION
<a name="r_STL_ANALYZE_COMPRESSION"></a>

記錄在 COPY 或 ANALYZE COMPRESSION 命令期間的壓縮分析操作詳細資訊。

所有使用者都可看見 STL\$1ANALYZE\$1COMPRESSION。超級使用者可以看見所有資料列；一般使用者只能看見自己的資料。如需詳細資訊，請參閱[系統資料表和檢視中資料的可見性](cm_chap_system-tables.md#c_visibility-of-data)。

此資料表中的部份或所有資料也會在 SYS 監控檢視 [SYS\$1ANALYZE\$1COMPRESSION\$1HISTORY](r_SYS_ANALYZE_COMPRESSION_HISTORY.md) 中找到。SYS 監視檢視中的資料會格式化為更易於使用和理解。我們建議您使用 SYS 監控檢視進行查詢。

## 資料表欄
<a name="r_STL_ANALYZE_COMPRESSION-table-columns2"></a>

[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/redshift/latest/dg/r_STL_ANALYZE_COMPRESSION.html)

## 範例查詢
<a name="r_STL_ANALYZE_COMPRESSION-sample-queries2"></a>

下列範例由在相同工作階段中執行的最後一項 COPY 命令檢查 `lineitem` 資料表上的壓縮分析詳細資料。

```
select xid, tbl, btrim(tablename) as tablename, col, old_encoding, new_encoding, best_compression_encoding, mode 
from stl_analyze_compression 
where xid = (select xid from stl_query where query = pg_last_copy_id()) order by col;

 xid  |  tbl   | tablename | col |  old_encoding   |  new_encoding   | best_compression_encoding |      mode      
------+--------+-----------+-----+-----------------+-----------------+---------------------------+----------------
 5308 | 158961 | $lineitem |   0 | mostly32        | az64            | delta                     | ON            
 5308 | 158961 | $lineitem |   1 | mostly32        | az64            | az64                      | ON            
 5308 | 158961 | $lineitem |   2 | lzo             | az64            | az64                      | ON            
 5308 | 158961 | $lineitem |   3 | delta           | az64            | az64                      | ON            
 5308 | 158961 | $lineitem |   4 | bytedict        | az64            | bytedict                  | ON            
 5308 | 158961 | $lineitem |   5 | mostly32        | az64            | az64                      | ON            
 5308 | 158961 | $lineitem |   6 | delta           | az64            | az64                      | ON            
 5308 | 158961 | $lineitem |   7 | delta           | az64            | az64                      | ON            
 5308 | 158961 | $lineitem |   8 | lzo             | lzo             | lzo                       | ON            
 5308 | 158961 | $lineitem |   9 | runlength       | runlength       | runlength                 | ON            
 5308 | 158961 | $lineitem |  10 | delta           | az64            | az64                      | ON            
 5308 | 158961 | $lineitem |  11 | delta           | az64            | az64                      | ON            
 5308 | 158961 | $lineitem |  12 | delta           | az64            | az64                      | ON            
 5308 | 158961 | $lineitem |  13 | bytedict        | bytedict        | bytedict                  | ON            
 5308 | 158961 | $lineitem |  14 | bytedict        | bytedict        | bytedict                  | ON            
 5308 | 158961 | $lineitem |  15 | text255         | text255         | text255                   | ON   
(16 rows)
```

# STL\$1BCAST
<a name="r_STL_BCAST"></a>

記錄在執行播送資料的查詢步驟期間網路活動的相關資訊。網路流量是藉由資料列數、位元組數和封包數所擷取的，而這些資料列、位元組和封包是在特定配量上的特定步驟期間透過網路傳送的。步驟的持續時間是記錄的開始時間與結束時間之間的差異。

若要識別查詢中的播送步驟，請尋找 SVL\$1QUERY\$1SUMMARY 檢視中的 bcast 標籤，或執行 EXPLAIN 命令，然後尋找包含 bcast 的步驟屬性。

所有使用者都可看見 STL\$1BCAST。超級使用者可以看見所有資料列；一般使用者只能看見自己的資料。如需詳細資訊，請參閱[系統資料表和檢視中資料的可見性](cm_chap_system-tables.md#c_visibility-of-data)。

**注意**  
STL\$1BCAST 僅包含在主佈建叢集上執行的查詢。但不包含在並行擴縮叢集上或無伺服器命名空間上執行的查詢。若要存取在主要叢集、並行擴縮叢集和無伺服器命名空間上執行的查詢說明計畫，建議您使用 SYS 監控檢視 [SYS\$1QUERY\$1DETAIL](SYS_QUERY_DETAIL.md)。SYS 監視檢視中的資料會格式化為更易於使用和理解。

## 資料表欄
<a name="r_STL_BCAST-table-columns2"></a>

[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/redshift/latest/dg/r_STL_BCAST.html)

### 範例查詢
<a name="r_STL_BCAST-sample-queries2"></a>

下列範例傳回查詢的播送資訊，其中具有一個或多個封包，而且查詢的開始與結束之間的差異為一秒或以上。

```
select query, slice, step, rows, bytes, packets, datediff(seconds, starttime, endtime)
from stl_bcast
where packets>0 and datediff(seconds, starttime, endtime)>0;
```

```
 query | slice | step | rows | bytes | packets | date_diff
-------+-------+------+------+-------+---------+-----------
   453 |     2 |    5 |    1 |   264 |       1 |         1
   798 |     2 |    5 |    1 |   264 |       1 |         1
  1408 |     2 |    5 |    1 |   264 |       1 |         1
  2993 |     0 |    5 |    1 |   264 |       1 |         1
  5045 |     3 |    5 |    1 |   264 |       1 |         1
  8073 |     3 |    5 |    1 |   264 |       1 |         1
  8163 |     3 |    5 |    1 |   264 |       1 |         1
  9212 |     1 |    5 |    1 |   264 |       1 |         1
  9873 |     1 |    5 |    1 |   264 |       1 |         1
(9 rows)
```

# STL\$1COMMIT\$1STATS
<a name="r_STL_COMMIT_STATS"></a>

提供與遞交效能相關的指標，包括各種遞交階段的計時，以及遞交的區塊數。查詢 STL\$1COMMIT\$1STATS，以判斷交易的哪個部分花費在遞交上，以及發生多少佇列。

只有超級使用者才能看到 STL\$1COMMIT\$1STATS。如需詳細資訊，請參閱[系統資料表和檢視中資料的可見性](cm_chap_system-tables.md#c_visibility-of-data)。

此資料表中的部份或所有資料也會在 SYS 監控檢視 [SYS\$1TRANSACTION\$1HISTORY](SYS_TRANSACTION_HISTORY.md) 中找到。SYS 監視檢視中的資料會格式化為更易於使用和理解。我們建議您使用 SYS 監控檢視進行查詢。

## 資料表欄
<a name="r_STL_COMMIT_STATS-table-columns"></a>

[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/redshift/latest/dg/r_STL_COMMIT_STATS.html)

## 範例查詢
<a name="r_STL_COMMIT_STATS-sample-queries"></a>

```
select node, datediff(ms,startqueue,startwork) as queue_time, 
datediff(ms, startwork, endtime) as commit_time, queuelen
from stl_commit_stats
where xid = 2574
order by node;

node | queue_time   | commit_time | queuelen
-----+--------------+-------------+---------
  -1 |            0 |         617 |        0
   0 | 444950725641 |         616 |        0
   1 | 444950725636 |         616 |        0
```

# STL\$1CONNECTION\$1LOG
<a name="r_STL_CONNECTION_LOG"></a>

記錄身分驗證嘗試以及連線和中斷連線。

只有超級使用者才能看到 STL\$1CONNECTION\$1LOG。如需詳細資訊，請參閱[系統資料表和檢視中資料的可見性](cm_chap_system-tables.md#c_visibility-of-data)。

此資料表中的部份或所有資料也會在 SYS 監控檢視 [SYS\$1CONNECTION\$1LOG](SYS_CONNECTION_LOG.md) 中找到。SYS 監視檢視中的資料會格式化為更易於使用和理解。我們建議您使用 SYS 監控檢視進行查詢。

## 資料表欄
<a name="r_STL_CONNECTION_LOG-table-columns2"></a>

[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/redshift/latest/dg/r_STL_CONNECTION_LOG.html)

## 範例查詢
<a name="r_STL_CONNECTION_LOG-sample-queries2"></a>

若要檢視已開啟之連線的詳細資訊，請執行下列查詢。

```
select recordtime, username, dbname, remotehost, remoteport
from stl_connection_log
where event = 'initiating session'
and pid not in 
(select pid from stl_connection_log
where event = 'disconnecting session')
order by 1 desc;

recordtime          | username    | dbname     | remotehost    | remoteport                      
--------------------+-------------+------------+---------------+------------
2014-11-06 20:30:06 | rdsdb       | dev        | [local]       |                            
2014-11-06 20:29:37 | test001     | test       | 10.49.42.138  | 11111                           
2014-11-05 20:30:29 | rdsdb       | dev        | 10.49.42.138  | 33333                                                 
2014-11-05 20:28:35 | rdsdb       | dev        | [local]       |  
(4 rows)
```

下列範例反映失敗的身分驗證嘗試，以及成功的連線和中斷連線。

```
select event, recordtime, remotehost, username
from stl_connection_log order by recordtime;            

            event      |         recordtime        |  remotehost  | username                      
-----------------------+---------------------------+--------------+---------
authentication failure | 2012-10-25 14:41:56.96391 | 10.49.42.138 | john                                              
authenticated          | 2012-10-25 14:42:10.87613 | 10.49.42.138 | john                                              
initiating session     | 2012-10-25 14:42:10.87638 | 10.49.42.138 | john                                              
disconnecting session  | 2012-10-25 14:42:19.95992 | 10.49.42.138 | john                                              
(4 rows)
```

下列範例顯示 ODBC 驅動程式的版本、用戶端機器上的作業系統，以及用來連線到 Amazon Redshift 叢集的外掛程式。在此範例中，使用的外掛程式用於使用登入名稱和密碼進行標準 ODBC 驅動程式驗證。

```
select driver_version, os_version, plugin_name from stl_connection_log;
                
driver_version                          |  os_version                       | plugin_name
----------------------------------------+-----------------------------------+--------------------
Amazon Redshift ODBC Driver 1.4.15.0001 | Darwin 18.7.0 x86_64              | none
Amazon Redshift ODBC Driver 1.4.15.0001 | Linux 4.15.0-101-generic x86_64   | none
```

下列範例顯示用戶端電腦上的作業系統版本、驅動程式版本和通訊協定版本。

```
select os_version, driver_version, protocol_version from stl_connection_log;
                
os_version                      |  driver_version              | protocol_version
--------------------------------+------------------------------+--------------------
Linux 4.15.0-101-generic x86_64 | Redshift JDBC Driver 2.0.0.0 | 2
Linux 4.15.0-101-generic x86_64 | Redshift JDBC Driver 2.0.0.0 | 2 
Linux 4.15.0-101-generic x86_64 | Redshift JDBC Driver 2.0.0.0 | 2
```

# STL\$1DDLTEXT
<a name="r_STL_DDLTEXT"></a>

擷取已在系統上執行的下列 DDL 陳述式。

這些 DDL 陳述式包括下列查詢和物件：
+ CREATE SCHEMA、TABLE、VIEW
+ DROP SCHEMA、TABLE、VIEW
+ ALTER SCHEMA、TABLE

另請參閱 [STL\$1QUERYTEXT](r_STL_QUERYTEXT.md)、[STL\$1UTILITYTEXT](r_STL_UTILITYTEXT.md) 和 [SVL\$1STATEMENTTEXT](r_SVL_STATEMENTTEXT.md)。這些檢視提供在系統上執行之 SQL 命令的時間軸；此歷史記錄有助於進行故障診斷，以及建立所有系統活動的稽核記錄。

使用 STARTTIME 和 ENDTIME 資料欄，來了解已在特定時段記錄哪些陳述式。SQL 文字的長區塊會分成數行，一行 200 個字元；SEQUENCE 欄會識別屬於單一陳述式的文字片段。

所有使用者都可看見 STL\$1DDLTEXT。超級使用者可以看見所有資料列；一般使用者只能看見自己的資料。如需詳細資訊，請參閱[系統資料表和檢視中資料的可見性](cm_chap_system-tables.md#c_visibility-of-data)。

此資料表中的部份或所有資料也會在 SYS 監控檢視 [SYS\$1QUERY\$1HISTORY](SYS_QUERY_HISTORY.md) 中找到。SYS 監視檢視中的資料會格式化為更易於使用和理解。我們建議您使用 SYS 監控檢視進行查詢。

## 資料表欄
<a name="r_STL_DDLTEXT-table-columns2"></a>

[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/redshift/latest/dg/r_STL_DDLTEXT.html)

## 範例查詢
<a name="r_STL_DDLTEXT-sample-queries2"></a>

下列查詢會傳回包含先前執行之 DDL 陳述式的記錄。

```
select xid, starttime, sequence, substring(text,1,40) as text
from stl_ddltext order by xid desc, sequence;
```

以下是顯示四個 CREATE TABLE 陳述式的範例輸出。DDL 陳述式會出現在 `text` 欄中，為了方便閱讀而被截斷。

```
 xid  |         starttime          | sequence |                   text
------+----------------------------+----------+------------------------------------------
 1806 | 2013-10-23 00:11:14.709851 |        0 | CREATE TABLE supplier ( s_suppkey int4 N
 1806 | 2013-10-23 00:11:14.709851 |        1 |  s_comment varchar(101) NOT NULL )
 1805 | 2013-10-23 00:11:14.496153 |        0 | CREATE TABLE region ( r_regionkey int4 N
 1804 | 2013-10-23 00:11:14.285986 |        0 | CREATE TABLE partsupp ( ps_partkey int8
 1803 | 2013-10-23 00:11:14.056901 |        0 | CREATE TABLE part ( p_partkey int8 NOT N
 1803 | 2013-10-23 00:11:14.056901 |        1 | ner char(10) NOT NULL , p_retailprice nu
(6 rows)
```

### 重建儲存的 SQL
<a name="r_STL_DDLTEXT-reconstruct-sql"></a>

下列 SQL 會列出儲存在 STL\$1DDLTEXT 之 `text` 欄中的列。列依 `xid` 與 `sequence` 排序。如果原始 SQL 的多個列長度超過 200 個字元，則 STL\$1DDLTEXT 可以依 `sequence` 包含多個列。

```
SELECT xid, sequence, LISTAGG(CASE WHEN LEN(RTRIM(text)) = 0 THEN text ELSE RTRIM(text) END, '') WITHIN GROUP (ORDER BY sequence) as query_statement 
FROM stl_ddltext GROUP BY xid, sequence ORDER BY xid, sequence;
```

```
xid     |  sequence | query_statement
--------+-----------+-----------------
7886671    0          create external schema schema_spectrum_uddh\nfrom data catalog\ndatabase 'spectrum_db_uddh'\niam_role ''\ncreate external database if not exists;	
7886752    0          CREATE EXTERNAL TABLE schema_spectrum_uddh.soccer_league\n(\n  league_rank smallint,\n  prev_rank   smallint,\n  club_name   varchar(15),\n  league_name varchar(20),\n  league_off  decimal(6,2),\n  le	
7886752    1          ague_def  decimal(6,2),\n  league_spi  decimal(6,2),\n  league_nspi smallint\n)\nROW FORMAT DELIMITED \n    FIELDS TERMINATED BY ',' \n    LINES TERMINATED BY '\\n\\l'\nstored as textfile\nLOCATION 's	
7886752    2          3://mybucket-spectrum-uddh/'\ntable properties ('skip.header.line.count'='1');
...
```

若要重建儲存在 STL\$1DDLTEXT 中 `text` 欄的 SQL，請執行下列 SQL 陳述式。它會將 `text` 欄中一或多個區段的 DDL 陳述式放在一起。請先在 SQL 用戶端中以新的一行取代任意 (`\n`) 特殊字元，再執行重建的 SQL。下列 SELECT 陳述式的結果會依序將三個列放在一起，以便在 `query_statement` 欄位中重建 SQL。

```
SELECT LISTAGG(CASE WHEN LEN(RTRIM(text)) = 0 THEN text ELSE RTRIM(text) END) WITHIN GROUP (ORDER BY sequence) as query_statement
FROM stl_ddltext GROUP BY xid, endtime order by xid, endtime;
```

```
query_statement
--------------
create external schema schema_spectrum_uddh\nfrom data catalog\ndatabase 'spectrum_db_uddh'\niam_role ''\ncreate external database if not exists;	
CREATE EXTERNAL TABLE schema_spectrum_uddh.soccer_league\n(\n  league_rank smallint,\n  prev_rank   smallint,\n  club_name   varchar(15),\n  league_name varchar(20),\n  league_off  decimal(6,2),\n  league_def  decimal(6,2),\n  league_spi  decimal(6,2),\n  league_nspi smallint\n)\nROW FORMAT DELIMITED \n    FIELDS TERMINATED BY ',' \n    LINES TERMINATED BY '\\n\\l'\nstored as textfile\nLOCATION 's3://mybucket-spectrum-uddh/'\ntable properties ('skip.header.line.count'='1');
```

# STL\$1DELETE
<a name="r_STL_DELETE"></a>

分析查詢的刪除執行步驟。

所有使用者都可看見 STL\$1DELETE。超級使用者可以看見所有資料列；一般使用者只能看見自己的資料。如需詳細資訊，請參閱[系統資料表和檢視中資料的可見性](cm_chap_system-tables.md#c_visibility-of-data)。

**注意**  
STL\$1DELETE 僅包含在主佈建叢集上執行的查詢。但不包含在並行擴縮叢集上或無伺服器命名空間上執行的查詢。若要存取在主要叢集、並行擴縮叢集和無伺服器命名空間上執行的查詢說明計畫，建議您使用 SYS 監控檢視 [SYS\$1QUERY\$1DETAIL](SYS_QUERY_DETAIL.md)。SYS 監視檢視中的資料會格式化為更易於使用和理解。

## 資料表欄
<a name="r_STL_DELETE-table-columns"></a>

[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/redshift/latest/dg/r_STL_DELETE.html)

## 範例查詢
<a name="r_STL_DELETE-sample-queries"></a>

為了要在 STL\$1DELETE 中建立一個資料列，下列範例會將一個資料列插入至 EVENT 資料表，然後刪除它。

首先，將一個資料列插入至 EVENT 資料表，然後驗證是否已插入它。

```
insert into event(eventid,venueid,catid,dateid,eventname)
values ((select max(eventid)+1 from event),95,9,1857,'Lollapalooza');
```

```
select * from event
where eventname='Lollapalooza'
order by eventid;
```

```
 eventid | venueid | catid | dateid |  eventname   |      starttime
---------+---------+-------+--------+--------------+---------------------
    4274 |     102 |     9 |   1965 | Lollapalooza | 2008-05-01 19:00:00
    4684 |     114 |     9 |   2105 | Lollapalooza | 2008-10-06 14:00:00
    5673 |     128 |     9 |   1973 | Lollapalooza | 2008-05-01 15:00:00
    5740 |      51 |     9 |   1933 | Lollapalooza | 2008-04-17 15:00:00
    5856 |     119 |     9 |   1831 | Lollapalooza | 2008-01-05 14:00:00
    6040 |     126 |     9 |   2145 | Lollapalooza | 2008-11-15 15:00:00
    7972 |      92 |     9 |   2026 | Lollapalooza | 2008-07-19 19:30:00
    8046 |      65 |     9 |   1840 | Lollapalooza | 2008-01-14 15:00:00
    8518 |      48 |     9 |   1904 | Lollapalooza | 2008-03-19 15:00:00
    8799 |      95 |     9 |   1857 | Lollapalooza |
(10 rows)
```

現在，刪除您已新增至 EVENT 資料表的資料列，然後驗證是否已刪除它。

```
delete from event 
where eventname='Lollapalooza' and eventid=(select max(eventid) from event);
```

```
select * from event
where eventname='Lollapalooza'
order by eventid;
```

```
 eventid | venueid | catid | dateid |  eventname   |      starttime
---------+---------+-------+--------+--------------+---------------------
    4274 |     102 |     9 |   1965 | Lollapalooza | 2008-05-01 19:00:00
    4684 |     114 |     9 |   2105 | Lollapalooza | 2008-10-06 14:00:00
    5673 |     128 |     9 |   1973 | Lollapalooza | 2008-05-01 15:00:00
    5740 |      51 |     9 |   1933 | Lollapalooza | 2008-04-17 15:00:00
    5856 |     119 |     9 |   1831 | Lollapalooza | 2008-01-05 14:00:00
    6040 |     126 |     9 |   2145 | Lollapalooza | 2008-11-15 15:00:00
    7972 |      92 |     9 |   2026 | Lollapalooza | 2008-07-19 19:30:00
    8046 |      65 |     9 |   1840 | Lollapalooza | 2008-01-14 15:00:00
    8518 |      48 |     9 |   1904 | Lollapalooza | 2008-03-19 15:00:00
(9 rows)
```

 然後，查詢 stl\$1delete 以查看刪除的執行步驟。在此範例中，查詢已傳回超過 300 個的資料列，因此以下輸出會縮短以便於顯示。

```
select query, slice, segment, step, tasknum, rows, tbl from stl_delete order by query;
```

```
 query | slice | segment | step | tasknum | rows |  tbl
-------+-------+---------+------+---------+------+--------
     7 |     0 |       0 |    1 |       0 |    0 | 100000
     7 |     1 |       0 |    1 |       0 |    0 | 100000
     8 |     0 |       0 |    1 |       2 |    0 | 100001
     8 |     1 |       0 |    1 |       2 |    0 | 100001
     9 |     0 |       0 |    1 |       4 |    0 | 100002
     9 |     1 |       0 |    1 |       4 |    0 | 100002
    10 |     0 |       0 |    1 |       6 |    0 | 100003
    10 |     1 |       0 |    1 |       6 |    0 | 100003
    11 |     0 |       0 |    1 |       8 |    0 | 100253
    11 |     1 |       0 |    1 |       8 |    0 | 100253
    12 |     0 |       0 |    1 |       0 |    0 | 100255
    12 |     1 |       0 |    1 |       0 |    0 | 100255
    13 |     0 |       0 |    1 |       2 |    0 | 100257
    13 |     1 |       0 |    1 |       2 |    0 | 100257
    14 |     0 |       0 |    1 |       4 |    0 | 100259
    14 |     1 |       0 |    1 |       4 |    0 | 100259
    ...
```

# STL\$1DISK\$1FULL\$1DIAG
<a name="r_STL_DISK_FULL_DIAG"></a>

磁碟已滿時記錄有關錯誤的日誌資訊。

只有超級使用者才能看到 STL\$1DISK\$1FULL\$1DIAG。如需詳細資訊，請參閱[系統資料表和檢視中資料的可見性](cm_chap_system-tables.md#c_visibility-of-data)。

## 資料表欄
<a name="r_STL_DISK_FULL_DIAG-table-columns"></a>

[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/redshift/latest/dg/r_STL_DISK_FULL_DIAG.html)

## 範例查詢
<a name="r_STL_DISK_FULL_DIAG-sample-queries"></a>

下列範例會在發生磁碟已滿錯誤時，傳回所儲存資料的詳細資訊。

```
select * from stl_disk_full_diag
```

下列範例會將 `currenttime` 轉換為時間戳記。

```
select '2000-01-01'::timestamp + (currenttime/1000000.0)* interval '1 second' as currenttime,node_num,query_id,temp_blocks from pg_catalog.stl_disk_full_diag;
```

```
        currenttime         | node_num | query_id | temp_blocks 
----------------------------+----------+----------+-------------
 2019-05-18 19:19:18.609338 |        0 |   569399 |       70982
 2019-05-18 19:37:44.755548 |        0 |   569580 |       70982
 2019-05-20 13:37:20.566916 |        0 |   597424 |       70869
```

# STL\$1DIST
<a name="r_STL_DIST"></a>

記錄在執行遞送資料的查詢步驟期間網路活動的相關資訊。網路流量是藉由資料列數、位元組數和封包數所擷取的，而這些資料列、位元組和封包是在特定配量上的特定步驟期間透過網路傳送的。步驟的持續時間是記錄的開始時間與結束時間之間的差異。

若要識別查詢中的配送步驟，請尋找 QUERY\$1SUMMARY 檢視中的 dist 標籤，或執行 EXPLAIN 命令，然後尋找包含 dist 的步驟屬性。

所有使用者都可看見 STL\$1DIST。超級使用者可以看見所有資料列；一般使用者只能看見自己的資料。如需詳細資訊，請參閱[系統資料表和檢視中資料的可見性](cm_chap_system-tables.md#c_visibility-of-data)。

**注意**  
STL\$1DIST 僅包含在主佈建叢集上執行的查詢。但不包含在並行擴縮叢集上或無伺服器命名空間上執行的查詢。若要存取在主要叢集、並行擴縮叢集和無伺服器命名空間上執行的查詢說明計畫，建議您使用 SYS 監控檢視 [SYS\$1QUERY\$1DETAIL](SYS_QUERY_DETAIL.md)。SYS 監視檢視中的資料會格式化為更易於使用和理解。

## 資料表欄
<a name="r_STL_DIST-table-columns"></a>

[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/redshift/latest/dg/r_STL_DIST.html)

## 範例查詢
<a name="r_STL_DIST-sample-queries"></a>

下列範例傳回查詢的配送資訊，其中具有一個或多個封包，且持續時間大於零。

```
select query, slice, step, rows, bytes, packets, 
datediff(seconds, starttime, endtime) as duration
from stl_dist
where packets>0 and datediff(seconds, starttime, endtime)>0
order by query
limit 10;
```

```
 query  | slice | step |  rows  |  bytes  | packets | duration
--------+-------+------+--------+---------+---------+-----------
    567 |     1 |    4 |  49990 | 6249564 |     707 |         1
    630 |     0 |    5 |   8798 |  408404 |      46 |         2
    645 |     1 |    4 |   8798 |  408404 |      46 |         1
    651 |     1 |    5 | 192497 | 9226320 |    1039 |         6
    669 |     1 |    4 | 192497 | 9226320 |    1039 |         4
    675 |     1 |    5 |   3766 |  194656 |      22 |         1
    696 |     0 |    4 |   3766 |  194656 |      22 |         1
    705 |     0 |    4 |    930 |   44400 |       5 |         1
 111525 |     0 |    3 |     68 |   17408 |       2 |         1
(9 rows)
```

# STL\$1ERROR
<a name="r_STL_ERROR"></a>

記錄 Amazon Redshift 資料庫引擎所產生的內部處理錯誤。STL\$1ERROR 不會記錄 SQL 錯誤或訊息。STL\$1ERROR 中的資訊有助於對特定錯誤進行故障診斷。 AWS 支援工程師可能會要求您在疑難排解程序中提供此資訊。

所有使用者都可看見 STL\$1ERROR。超級使用者可以看見所有資料列；一般使用者只能看見自己的資料。如需詳細資訊，請參閱[系統資料表和檢視中資料的可見性](cm_chap_system-tables.md#c_visibility-of-data)。

此資料表中的部份或所有資料也會在 SYS 監控檢視 [SYS\$1QUERY\$1HISTORY](SYS_QUERY_HISTORY.md) 中找到。SYS 監視檢視中的資料會格式化為更易於使用和理解。我們建議您使用 SYS 監控檢視進行查詢。

如需使用 Copy 命令載入資料時可能產生之錯誤代碼的清單，請參閱[載入錯誤參考](r_Load_Error_Reference.md)。

## 資料表欄
<a name="r_STL_ERROR-table-columns"></a>

[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/redshift/latest/dg/r_STL_ERROR.html)

## 範例查詢
<a name="r_STL_ERROR-sample-queries"></a>

下列範例從 STL\$1ERROR 擷取錯誤資訊。

```
select process, errcode, linenum as line,
trim(error) as err
from stl_error;

   process    | errcode | line |                               err
--------------+---------+------+------------------------------------------------------------------
 padbmaster   |    8001 |  194 | Path prefix: s3://redshift-downloads/testnulls/venue.txt*
 padbmaster   |    8001 |  529 | Listing bucket=redshift-downloads prefix=tests/category-csv-quotes
 padbmaster   |       2 |  190 | database "template0" is not currently accepting connections
 padbmaster   |      32 | 1956 | pq_flush: could not send data to client: Broken pipe
(4 rows)
```

# STL\$1EXPLAIN
<a name="r_STL_EXPLAIN"></a>

顯示已提交供執行之用的查詢的 EXPLAIN 計劃。

所有使用者都可看見 STL\$1EXPLAIN。超級使用者可以看見所有資料列；一般使用者只能看見自己的資料。如需詳細資訊，請參閱[系統資料表和檢視中資料的可見性](cm_chap_system-tables.md#c_visibility-of-data)。

**注意**  
STL\$1EXPLAIN 僅包含在主佈建叢集上執行的查詢。但不包含在並行擴縮叢集上或無伺服器命名空間上執行的查詢。若要存取在主要叢集、並行擴縮叢集和無伺服器命名空間上執行的查詢說明計畫，建議您使用 SYS 監控檢視 [SYS\$1QUERY\$1EXPLAIN](SYS_QUERY_EXPLAIN.md)。SYS 監視檢視中的資料會格式化為更易於使用和理解。

## 資料表欄
<a name="r_STL_EXPLAIN-table-columns"></a>

[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/redshift/latest/dg/r_STL_EXPLAIN.html)

## 範例查詢
<a name="r_STL_EXPLAIN-sample-queries"></a>

考慮彙總聯結查詢的下列 EXPLAIN 輸出：

```
explain select avg(datediff(day, listtime, saletime)) as avgwait
from sales, listing where sales.listid = listing.listid;
                                  QUERY PLAN
                                  
------------------------------------------------------------------------------
 XN Aggregate  (cost=6350.30..6350.31 rows=1 width=16)
  ->  XN Hash Join DS_DIST_NONE  (cost=47.08..6340.89 rows=3766 width=16)
        Hash Cond: ("outer".listid = "inner".listid)
        -> XN Seq Scan on listing  (cost=0.00..1924.97 rows=192497 width=12)
        -> XN Hash  (cost=37.66..37.66 rows=3766 width=12)
              -> XN Seq Scan on sales  (cost=0.00..37.66 rows=3766 width=12)
(6 rows)
```

如果執行此查詢且其查詢 ID 為 10，則您可以使用 STL\$1EXPLAIN 資料表，來查看 EXPLAIN 命令所傳回相同類型的資訊：

```
select query,nodeid,parentid,substring(plannode from 1 for 30),
substring(info from 1 for 20) from stl_explain
where query=10 order by 1,2;

query| nodeid |parentid|           substring            |    substring
-----+--------+--------+--------------------------------+-------------------
10   |      1 |      0 |XN Aggregate  (cost=6717.61..6  |
10   |      2 |      1 |  -> XN Merge Join DS_DIST_NO   | Merge Cond:("outer"
10   |      3 |      2 |       -> XN Seq Scan on lis    |
10   |      4 |      2 |       -> XN Seq Scan on sal    |
(4 rows)
```

請考處下列查詢：

```
select event.eventid, sum(pricepaid)
from event, sales
where event.eventid=sales.eventid
group by event.eventid order by 2 desc;

eventid |   sum
--------+----------
    289 | 51846.00
   7895 | 51049.00
   1602 | 50301.00
    851 | 49956.00
   7315 | 49823.00
...
```

 如果此查詢的 ID 為 15，則下列系統檢視查詢會傳回已完成的計劃節點。在此情況下，會保留節點的順序，以顯示執行的實際順序：

```
select query,nodeid,parentid,substring(plannode from 1 for 56)
from stl_explain where query=15 order by 1, 2 desc;

query|nodeid|parentid|                          substring
-----+------+--------+--------------------------------------------------------
15   |    8 |      7 |                                -> XN Seq Scan on eve
15   |    7 |      5 |                          -> XN Hash(cost=87.98..87.9
15   |    6 |      5 |                          -> XN Seq Scan on sales(cos
15   |    5 |      4 |                    -> XN Hash Join DS_DIST_OUTER(cos
15   |    4 |      3 |              -> XN HashAggregate(cost=862286577.07..
15   |    3 |      2 |        -> XN Sort(cost=1000862287175.47..10008622871
15   |    2 |      1 |  -> XN Network(cost=1000862287175.47..1000862287197.
15   |    1 |      0 |XN Merge(cost=1000862287175.47..1000862287197.46 rows=87
(8 rows)
```

下列查詢會擷取包含視窗函數之任何查詢計劃的查詢 ID：

```
select query, trim(plannode) from stl_explain
where plannode like '%Window%';

query|                                     btrim
-----+------------------------------------------------------------------------
26   | -> XN Window(cost=1000985348268.57..1000985351256.98 rows=170 width=33)
27   | -> XN Window(cost=1000985348268.57..1000985351256.98 rows=170 width=33)
(2 rows)
```

# STL\$1FILE\$1SCAN
<a name="r_STL_FILE_SCAN"></a>

傳回 Amazon Redshift 在使用 COPY 命令載入資料時讀取的檔案。

查詢此檢視有助於對資料載入錯誤進行故障診斷。STL\$1FILE\$1SCAN 特別有助於指出平行資料載入中的問題，因為平行資料載入通常會利用單一 COPY 命令載入多個檔案。

所有使用者都可看見 STL\$1FILE\$1SCAN。超級使用者可以看見所有資料列；一般使用者只能看見自己的資料。如需詳細資訊，請參閱[系統資料表和檢視中資料的可見性](cm_chap_system-tables.md#c_visibility-of-data)。

**注意**  
STL\$1FILE\$1SCAN 僅包含在主佈建叢集上執行的查詢。但不包含在並行擴縮叢集上或無伺服器命名空間上執行的查詢。若要存取在主要叢集、並行擴縮叢集和無伺服器命名空間上執行的查詢說明計畫，建議您使用 SYS 監控檢視 [SYS\$1LOAD\$1DETAIL](SYS_LOAD_DETAIL.md)。SYS 監視檢視中的資料會格式化為更易於使用和理解。

## 資料表欄
<a name="r_STL_FILE_SCAN-table-columns2"></a>

[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/redshift/latest/dg/r_STL_FILE_SCAN.html)

## 範例查詢
<a name="r_STL_FILE_SCAN-sample-queries2"></a>

下列查詢擷取 Amazon Redshift 需要超過 1,000,000 微秒來讀取之任何檔案的名稱和載入時間。

```
select trim(name)as name, loadtime from stl_file_scan
where loadtime > 1000000;
```

此查詢傳回下列範例輸出。

```
           name            | loadtime
---------------------------+----------
 listings_pipe.txt         |  9458354
 allusers_pipe.txt         |  2963761
 allevents_pipe.txt        |  1409135
 tickit/listings_pipe.txt  |  7071087
 tickit/allevents_pipe.txt |  1237364
 tickit/allusers_pipe.txt  |  2535138
 listings_pipe.txt         |  6706370
 allusers_pipe.txt         |  3579461
 allevents_pipe.txt        |  1313195
 tickit/allusers_pipe.txt  |  3236060
 tickit/listings_pipe.txt  |  4980108
(11 rows)
```

# STL\$1HASH
<a name="r_STL_HASH"></a>

分析查詢的雜湊執行步驟。

所有使用者都可看見 STL\$1HASH。超級使用者可以看見所有資料列；一般使用者只能看見自己的資料。如需詳細資訊，請參閱[系統資料表和檢視中資料的可見性](cm_chap_system-tables.md#c_visibility-of-data)。

**注意**  
STL\$1HASH 僅包含在主佈建叢集上執行的查詢。但不包含在並行擴縮叢集上或無伺服器命名空間上執行的查詢。若要存取在主要叢集、並行擴縮叢集和無伺服器命名空間上執行的查詢說明計畫，建議您使用 SYS 監控檢視 [SYS\$1QUERY\$1DETAIL](SYS_QUERY_DETAIL.md)。SYS 監視檢視中的資料會格式化為更易於使用和理解。

## 資料表欄
<a name="r_STL_HASH-table-columns"></a>

[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/redshift/latest/dg/r_STL_HASH.html)

## 範例查詢
<a name="r_STL_HASH-sample-queries"></a>

下列範例會傳回雜湊中針對查詢 720 所使用之分割區數目的相關資訊，並指出已沒有步驟在磁碟上執行。

```
select slice, rows, bytes, occupied, workmem, num_parts, est_rows, num_blocks_permitted, is_diskbased
from stl_hash
where query=720 and segment=5
order by slice;
```

```
 slice | rows | bytes  | occupied | workmem  | num_parts | est_rows | num_blocks_permitted | is_diskbased
-------+------+--------+----------+----------+-----------+----------+----------------------+--------------
     0 |  145 | 585800 |        1 | 88866816 |        16 |        1 |                   52              f
     1 |    0 |      0 |        0 |        0 |        16 |        1 |                   52              f
(2 rows)
```

# STL\$1HASHJOIN
<a name="r_STL_HASHJOIN"></a>

分析查詢的雜湊聯結執行步驟。

所有使用者都可看見 STL\$1HASHJOIN。超級使用者可以看見所有資料列；一般使用者只能看見自己的資料。如需詳細資訊，請參閱[系統資料表和檢視中資料的可見性](cm_chap_system-tables.md#c_visibility-of-data)。

**注意**  
STL\$1HASHJOIN 僅包含在主佈建叢集上執行的查詢。但不包含在並行擴縮叢集上或無伺服器命名空間上執行的查詢。若要存取在主要叢集、並行擴縮叢集和無伺服器命名空間上執行的查詢說明計畫，建議您使用 SYS 監控檢視 [SYS\$1QUERY\$1DETAIL](SYS_QUERY_DETAIL.md)。SYS 監視檢視中的資料會格式化為更易於使用和理解。

## 資料表欄
<a name="r_STL_HASHJOIN-table-columns"></a>

[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/redshift/latest/dg/r_STL_HASHJOIN.html)

## 範例查詢
<a name="r_STL_HASHJOIN-sample-queries"></a>

下列查詢會傳回雜湊聯結中針對查詢 720 所使用的分割區數目。

```
select query, slice, tbl, num_parts
from stl_hashjoin
where query=720 limit 10;
```

```
 query | slice | tbl | num_parts
-------+-------+-----+-----------
   720 |     0 | 243 |         1
   720 |     1 | 243 |         1
(2 rows)
```

# STL\$1INSERT
<a name="r_STL_INSERT"></a>

分析查詢的插入執行步驟。

所有使用者都可看見 STL\$1INSERT。超級使用者可以看見所有資料列；一般使用者只能看見自己的資料。如需詳細資訊，請參閱[系統資料表和檢視中資料的可見性](cm_chap_system-tables.md#c_visibility-of-data)。

**注意**  
STL\$1INSERT 僅包含在主佈建叢集上執行的查詢。但不包含在並行擴縮叢集上或無伺服器命名空間上執行的查詢。若要存取在主要叢集、並行擴縮叢集和無伺服器命名空間上執行的查詢說明計畫，建議您使用 SYS 監控檢視 [SYS\$1QUERY\$1DETAIL](SYS_QUERY_DETAIL.md)。SYS 監視檢視中的資料會格式化為更易於使用和理解。

## 資料表欄
<a name="r_STL_INSERT-table-columns"></a>

[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/redshift/latest/dg/r_STL_INSERT.html)

## 範例查詢
<a name="r_STL_INSERT-sample-queries"></a>

下列範例會傳回最新查詢的插入執行步驟。

```
select slice, segment, step, tasknum, rows, tbl
from stl_insert 
where query=pg_last_query_id();
```

```
 slice | segment | step | tasknum | rows  |  tbl
-------+---------+------+---------+-------+--------
     0 |       2 |    2 |      15 | 24958 | 100548
     1 |       2 |    2 |      15 | 25032 | 100548
(2 rows)
```

# STL\$1LIMIT
<a name="r_STL_LIMIT"></a>

分析在 SELECT 查詢中使用 LIMIT 子句時發生的執行步驟。

所有使用者都可看見 STL\$1LIMIT。超級使用者可以看見所有資料列；一般使用者只能看見自己的資料。如需詳細資訊，請參閱[系統資料表和檢視中資料的可見性](cm_chap_system-tables.md#c_visibility-of-data)。

**注意**  
STL\$1LIMIT 僅包含在主佈建叢集上執行的查詢。但不包含在並行擴縮叢集上或無伺服器命名空間上執行的查詢。若要存取在主要叢集、並行擴縮叢集和無伺服器命名空間上執行的查詢說明計畫，建議您使用 SYS 監控檢視 [SYS\$1QUERY\$1DETAIL](SYS_QUERY_DETAIL.md)。SYS 監視檢視中的資料會格式化為更易於使用和理解。

## 資料表欄
<a name="r_STL_LIMIT-table-columns"></a>

[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/redshift/latest/dg/r_STL_LIMIT.html)

## 範例查詢
<a name="r_STL_LIMIT-sample-queries"></a>

為了要在 STL\$1LIMIT 中產生資料列，此範例會使用 LIMIT 子句，針對 VENUE 資料表執行下列查詢。

```
select * from venue
order by 1
limit 10;
```

```
 venueid |         venuename          |    venuecity    | venuestate | venueseats
---------+----------------------------+-----------------+------------+------------
       1 | Toyota Park                | Bridgeview      | IL         |          0
       2 | Columbus Crew Stadium      | Columbus        | OH         |          0
       3 | RFK Stadium                | Washington      | DC         |          0
       4 | CommunityAmerica Ballpark  | Kansas City     | KS         |          0
       5 | Gillette Stadium           | Foxborough      | MA         |      68756
       6 | New York Giants Stadium    | East Rutherford | NJ         |      80242
       7 | BMO Field                  | Toronto         | ON         |          0
       8 | The Home Depot Center      | Carson          | CA         |          0
       9 | Dick's Sporting Goods Park | Commerce City   | CO         |          0
      10 | Pizza Hut Park             | Frisco          | TX         |          0
(10 rows)
```

接著，執行下列查詢，以尋找您上次針對 VENUE 資料表所執行之查詢的查詢 ID。

```
select max(query)
from stl_query;
```

```
  max
--------
 127128
(1 row)
```

您可以選擇性地執行下列查詢，以驗證查詢 ID 對應至您先前執行的 LIMIT 查詢。

```
select query, trim(querytxt)
from stl_query
where query=127128;
```

```
 query  |                  btrim
--------+------------------------------------------
 127128 | select * from venue order by 1 limit 10;
(1 row)
```

最後，執行下列查詢，從 STL\$1LIMIT 資料表傳回 LIMIT 查詢的相關資訊。

```
select slice, segment, step, starttime, endtime, tasknum
from stl_limit
where query=127128
order by starttime, endtime;
```

```
  slice | segment | step |         starttime          |          endtime           | tasknum
 -------+---------+------+----------------------------+----------------------------+---------
      1 |       1 |    3 | 2013-09-06 22:56:43.608114 | 2013-09-06 22:56:43.609383 |      15
      0 |       1 |    3 | 2013-09-06 22:56:43.608708 | 2013-09-06 22:56:43.609521 |      15
  10000 |       2 |    2 | 2013-09-06 22:56:43.612506 | 2013-09-06 22:56:43.612668 |       0
(3 rows)
```

# STL\$1LOAD\$1COMMITS
<a name="r_STL_LOAD_COMMITS"></a>

傳回資訊以追蹤資料載入或對其進行故障診斷。

此檢視會在每一個資料檔案載入至資料庫資料表時記錄其進度。

所有使用者都可看見 STL\$1LOAD\$1COMMITS。超級使用者可以看見所有資料列；一般使用者只能看見自己的資料。如需詳細資訊，請參閱[系統資料表和檢視中資料的可見性](cm_chap_system-tables.md#c_visibility-of-data)。

**注意**  
STL\$1LOAD\$1COMMITS 僅包含在主佈建叢集上執行的查詢。但不包含在並行擴縮叢集上或無伺服器命名空間上執行的查詢。若要存取在主要叢集、並行擴縮叢集和無伺服器命名空間上執行的查詢說明計畫，建議您使用 SYS 監控檢視 [SYS\$1LOAD\$1DETAIL](SYS_LOAD_DETAIL.md)。SYS 監視檢視中的資料會格式化為更易於使用和理解。

## 資料表欄
<a name="r_STL_LOAD_COMMITS-table-columns"></a>

[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/redshift/latest/dg/r_STL_LOAD_COMMITS.html)

## 範例查詢
<a name="r_STL_LOAD_COMMITS-sample-queries"></a>

下列範例傳回上次 COPY 操作的詳細資訊。

```
select query, trim(filename) as file, curtime as updated
from stl_load_commits
where query = pg_last_copy_id();

 query |               file               |          updated           
-------+----------------------------------+----------------------------
 28554 | s3://dw-tickit/category_pipe.txt | 2013-11-01 17:14:52.648486 
(1 row)
```

下列查詢包含 TICKIT 資料庫中全新載入之資料表的項目：

```
select query, trim(filename), curtime
from stl_load_commits
where filename like '%tickit%' order by query;
```

```
 query |           btrim           |          curtime           
-------+---------------------------+----------------------------
 22475 | tickit/allusers_pipe.txt  | 2013-02-08 20:58:23.274186 
 22478 | tickit/venue_pipe.txt     | 2013-02-08 20:58:25.070604 
 22480 | tickit/category_pipe.txt  | 2013-02-08 20:58:27.333472 
 22482 | tickit/date2008_pipe.txt  | 2013-02-08 20:58:28.608305 
 22485 | tickit/allevents_pipe.txt | 2013-02-08 20:58:29.99489  
 22487 | tickit/listings_pipe.txt  | 2013-02-08 20:58:37.632939 
 22593 | tickit/allusers_pipe.txt  | 2013-02-08 21:04:08.400491 
 22596 | tickit/venue_pipe.txt     | 2013-02-08 21:04:10.056055 
 22598 | tickit/category_pipe.txt  | 2013-02-08 21:04:11.465049 
 22600 | tickit/date2008_pipe.txt  | 2013-02-08 21:04:12.461502 
 22603 | tickit/allevents_pipe.txt | 2013-02-08 21:04:14.785124 
 22605 | tickit/listings_pipe.txt  | 2013-02-08 21:04:20.170594 

(12 rows)
```

事實上，記錄寫入至此系統檢視的日誌檔案，並不表示已成功遞交載入，做為其包含交易的一部分。若要驗證載入遞交，請查詢 STL\$1UTILITYTEXT 檢視，並尋找與 COPY 交易相對應的 COMMIT 記錄。例如，此查詢會針對 STL\$1UTILITYTEXT 根據子查詢聯結 STL\$1LOAD\$1COMMITS 和 STL\$1QUERY：

```
select l.query,rtrim(l.filename),q.xid
from stl_load_commits l, stl_query q
where l.query=q.query
and exists
(select xid from stl_utilitytext where xid=q.xid and rtrim("text")='COMMIT');

 query |           rtrim           |  xid
-------+---------------------------+-------
 22600 | tickit/date2008_pipe.txt  | 68311
 22480 | tickit/category_pipe.txt  | 68066
  7508 | allusers_pipe.txt         | 23365
  7552 | category_pipe.txt         | 23415
  7576 | allevents_pipe.txt        | 23429
  7516 | venue_pipe.txt            | 23390
  7604 | listings_pipe.txt         | 23445
 22596 | tickit/venue_pipe.txt     | 68309
 22605 | tickit/listings_pipe.txt  | 68316
 22593 | tickit/allusers_pipe.txt  | 68305
 22485 | tickit/allevents_pipe.txt | 68071
  7561 | allevents_pipe.txt        | 23429
  7541 | category_pipe.txt         | 23415
  7558 | date2008_pipe.txt         | 23428
 22478 | tickit/venue_pipe.txt     | 68065
   526 | date2008_pipe.txt         |  2572
  7466 | allusers_pipe.txt         | 23365
 22482 | tickit/date2008_pipe.txt  | 68067
 22598 | tickit/category_pipe.txt  | 68310
 22603 | tickit/allevents_pipe.txt | 68315
 22475 | tickit/allusers_pipe.txt  | 68061
   547 | date2008_pipe.txt         |  2572
 22487 | tickit/listings_pipe.txt  | 68072
  7531 | venue_pipe.txt            | 23390
  7583 | listings_pipe.txt         | 23445
(25 rows)
```

以下範例反白顯示 is\$1partial 和 start\$1offset 欄值。

```
-- Single large file copy without scan range
SELECT count(*) FROM stl_load_commits WHERE query = pg_last_copy_id();
1

-- Single large uncompressed, delimited file copy with scan range
SELECT count(*) FROM stl_load_commits WHERE query = pg_last_copy_id();
16

-- Scan range offset logging in the file at 64MB boundary. 
SELECT start_offset FROM stl_load_commits
WHERE query = pg_last_copy_id() ORDER BY start_offset;
0
67108864
134217728
201326592
268435456
335544320
402653184
469762048
536870912
603979776
671088640
738197504
805306368
872415232
939524096
1006632960
```

# STL\$1LOAD\$1ERRORS
<a name="r_STL_LOAD_ERRORS"></a>

顯示所有 Amazon Redshift 載入錯誤的記錄。

STL\$1LOAD\$1ERRORS 包含所有 Amazon Redshift 載入錯誤的歷史記錄。如需可能載入錯誤和說明的完整清單，請參閱[載入錯誤參考](r_Load_Error_Reference.md)。

在您查詢 STL\$1LOAD\$1ERRORS 以了解有關錯誤的一般資訊之後，查詢 [STL\$1LOADERROR\$1DETAIL](r_STL_LOADERROR_DETAIL.md) 以取得其他詳細資訊，例如發生剖析錯誤的確切資料列和欄。

所有使用者都可看見 STL\$1LOAD\$1ERROR。超級使用者可以看見所有資料列；一般使用者只能看見自己的資料。如需詳細資訊，請參閱[系統資料表和檢視中資料的可見性](cm_chap_system-tables.md#c_visibility-of-data)。

**注意**  
STL\$1LOAD\$1ERRORS 僅包含在主佈建叢集上執行的查詢。但不包含在並行擴縮叢集上或無伺服器命名空間上執行的查詢。若要存取在主要叢集、並行擴縮叢集和無伺服器命名空間上執行的查詢說明計畫，建議您使用 SYS 監控檢視 [SYS\$1LOAD\$1ERROR\$1DETAIL](SYS_LOAD_ERROR_DETAIL.md)。SYS 監視檢視中的資料會格式化為更易於使用和理解。

## 資料表欄
<a name="r_STL_LOAD_ERRORS-table-columns2"></a>

[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/redshift/latest/dg/r_STL_LOAD_ERRORS.html)

## 範例查詢
<a name="r_STL_LOAD_ERRORS-sample-queries2"></a>

下列查詢會將 STL\$1LOAD\$1ERRORS 聯結至 STL\$1LOADERROR\$1DETAIL，以檢視最近載入期間發生之錯誤的詳細資訊。

```
select d.query, substring(d.filename,14,20), 
d.line_number as line, 
substring(d.value,1,16) as value,
substring(le.err_reason,1,48) as err_reason
from stl_loaderror_detail d, stl_load_errors le
where d.query = le.query
and d.query = pg_last_copy_id(); 

 query |    substring      | line |  value   |              err_reason
-------+-------------------+------+----------+----------------------------
    558| allusers_pipe.txt |  251 | 251      | String contains invalid or 
                                               unsupported UTF8 code
    558| allusers_pipe.txt |  251 | ZRU29FGR | String contains invalid or 
                                               unsupported UTF8 code
    558| allusers_pipe.txt |  251 | Kaitlin  | String contains invalid or 
                                               unsupported UTF8 code
    558| allusers_pipe.txt |  251 | Walter   | String contains invalid or 
                                               unsupported UTF8 code
```

下列範例會使用 STL\$1LOAD\$1ERRORS 與 STV\$1TBL\$1PERM 搭配來建立新檢視，然後使用該檢視來判斷將資料載入至 EVENT 資料表時發生哪些錯誤：

```
create view loadview as
(select distinct tbl, trim(name) as table_name, query, starttime,
trim(filename) as input, line_number, colname, err_code,
trim(err_reason) as reason
from stl_load_errors sl, stv_tbl_perm sp
where sl.tbl = sp.id);
```

接著，下列查詢實際上會傳回上次載入 EVENT 資料表時發生的錯誤：

```
select table_name, query, line_number, colname, starttime, 
trim(reason) as error
from loadview
where table_name ='event'
order by line_number limit 1;
```

此查詢會傳回 EVENT 資料表上次發生的載入錯誤。如果未發生任何載入錯誤，則查詢不會傳回任何資料列。在此範例中，查詢會傳回單一錯誤：

```
 table_name | query | line_number | colname | error | starttime
------+-----+----+----+--------------------------------------------------------+----------------------
event | 309 |  0 |  5 | Error in Timestamp value or format [%Y-%m-%d %H:%M:%S] | 2014-04-22 15:12:44

(1 row)
```

 如果 COPY 命令會自動分割大型、未壓縮、文字分隔的檔案資料以促進平行處理，則 *line\$1number*、*is\$1partial* 和 *start\$1offset* 欄會顯示分割的相關資訊。(如果原始檔案中的行號不可用，則行號可能是未知的。) 

```
--scan ranges information
SELECT line_number, POSITION, btrim(raw_line), btrim(raw_field_value),
btrim(err_reason), is_partial, start_offset FROM stl_load_errors
WHERE query = pg_last_copy_id();

--result
-1,51,"1008771|13463413|463414|2|28.00|38520.72|0.06|0.07|NO|1998-08-30|1998-09-25|1998-09-04|TAKE BACK RETURN|RAIL|ans cajole sly","NO","Char length exceeds DDL length",1,67108864
```

# STL\$1LOADERROR\$1DETAIL
<a name="r_STL_LOADERROR_DETAIL"></a>

顯示當使用 COPY 命令來載入資料表時發生之資料剖析錯誤的日誌。若要保留磁碟空間，針對每個載入操作，每個節點配量最多可記錄 20 個錯誤。

 將資料列中的欄位載入至資料表時，若 Amazon Redshift 無法剖析該欄位，即會發生剖析錯誤。例如，如果資料表資料欄預期 integer 資料類型，但資料檔案在該欄位中包含一串字母，則其會導致剖析錯誤。

在您查詢 [STL\$1LOAD\$1ERRORS](r_STL_LOAD_ERRORS.md) 以了解有關錯誤的一般資訊之後，查詢 STL\$1LOADERROR\$1DETAIL 以取得其他詳細資訊，例如發生剖析錯誤的確切資料列和資料欄。

STL\$1LOADERROR\$1DETAIL 檢視包含發生剖析錯誤的欄 (含) 之前的所有資料欄。使用 VALUE 欄位來查看實際上已在此資料欄中剖析的資料值，包括已正確剖析至錯誤的資料欄。

所有使用者都可看見此檢視。超級使用者可以看見所有資料列；一般使用者只能看見自己的資料。如需詳細資訊，請參閱[系統資料表和檢視中資料的可見性](cm_chap_system-tables.md#c_visibility-of-data)。

**注意**  
STL\$1LOADERROR\$1DETAIL 僅包含在主佈建叢集上執行的查詢。但不包含在並行擴縮叢集上或無伺服器命名空間上執行的查詢。若要存取在主要叢集、並行擴縮叢集和無伺服器命名空間上執行的查詢說明計畫，建議您使用 SYS 監控檢視 [SYS\$1LOAD\$1ERROR\$1DETAIL](SYS_LOAD_ERROR_DETAIL.md)。SYS 監視檢視中的資料會格式化為更易於使用和理解。

## 資料表欄
<a name="r_STL_LOADERROR_DETAIL-table-columns"></a>

[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/redshift/latest/dg/r_STL_LOADERROR_DETAIL.html)

## 範例查詢
<a name="r_STL_LOADERROR_DETAIL-samplequery"></a>

下列查詢會將 STL\$1LOAD\$1ERRORS 聯結至 STL\$1LOADERROR\$1DETAIL，以檢視載入 EVENT 資料表 (資料表 ID 為 100133) 時發生之剖析錯誤的詳細資訊：

```
select d.query, d.line_number, d.value,
le.raw_line, le.err_reason
from stl_loaderror_detail d, stl_load_errors le
where
d.query = le.query
and tbl = 100133;
```

下列範例輸出會顯示成功載入的資料欄，包括發生錯誤的資料欄。在此範例中，於第三個資料欄中發生剖析錯誤之前已成功載入兩個資料欄，此錯誤是對於預期整數的欄位，卻不正確地剖析字元字串。因為欄位預期整數，所以它將字串 "aaa" (未初始化的資料) 剖析為 null，並產生剖析錯誤。輸出顯示原始值、已剖析值和錯誤原因：

```
query  | line_number | value | raw_line | err_reason
-------+-------------+-------+----------+----------------
4      |      3      |  1201 |  1201    | Invalid digit
4      |      3      |   126 |   126    | Invalid digit
4      |      3      |       |   aaa    | Invalid digit
(3 rows)
```

當查詢聯結 STL\$1LOAD\$1ERRORS 和 STL\$1LOADERROR\$1DETAIL 時，它會顯示資料列中每個資料欄的錯誤原因，這僅表示該資料列中發生錯誤。結果中的最後一列是發生剖析錯誤的實際資料欄。

# STL\$1MERGE
<a name="r_STL_MERGE"></a>

分析查詢的合併執行步驟。當合併平行操作 (例如排序和聯結) 的結果進行後續處理時，即會進行這些步驟。

所有使用者都可看見 STL\$1MERGE。超級使用者可以看見所有資料列；一般使用者只能看見自己的資料。如需詳細資訊，請參閱[系統資料表和檢視中資料的可見性](cm_chap_system-tables.md#c_visibility-of-data)。

**注意**  
STL\$1MERGE 僅包含在主佈建叢集上執行的查詢。但不包含在並行擴縮叢集上或無伺服器命名空間上執行的查詢。若要存取在主要叢集、並行擴縮叢集和無伺服器命名空間上執行的查詢說明計畫，建議您使用 SYS 監控檢視 [SYS\$1QUERY\$1DETAIL](SYS_QUERY_DETAIL.md)。SYS 監視檢視中的資料會格式化為更易於使用和理解。

## 資料表欄
<a name="r_STL_MERGE-table-columns"></a>

[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/redshift/latest/dg/r_STL_MERGE.html)

## 範例查詢
<a name="r_STL_MERGE-sample-queries"></a>

下列範例會傳回 10 個合併執行結果。

```
select query, step, starttime, endtime, tasknum, rows
from stl_merge
limit 10;
```

```
 query | step |       starttime     |        endtime      | tasknum | rows
-------+------+---------------------+---------------------+---------+------
     9 |    0 | 2013-08-12 20:08:14 | 2013-08-12 20:08:14 |       0 |    0
    12 |    0 | 2013-08-12 20:09:10 | 2013-08-12 20:09:10 |       0 |    0
    15 |    0 | 2013-08-12 20:10:24 | 2013-08-12 20:10:24 |       0 |    0
    20 |    0 | 2013-08-12 20:11:27 | 2013-08-12 20:11:27 |       0 |    0
    26 |    0 | 2013-08-12 20:12:28 | 2013-08-12 20:12:28 |       0 |    0
    32 |    0 | 2013-08-12 20:14:33 | 2013-08-12 20:14:33 |       0 |    0
    38 |    0 | 2013-08-12 20:16:43 | 2013-08-12 20:16:43 |       0 |    0
    44 |    0 | 2013-08-12 20:17:05 | 2013-08-12 20:17:05 |       0 |    0
    50 |    0 | 2013-08-12 20:18:48 | 2013-08-12 20:18:48 |       0 |    0
    56 |    0 | 2013-08-12 20:20:48 | 2013-08-12 20:20:48 |       0 |    0
(10 rows)
```

# STL\$1MERGEJOIN
<a name="r_STL_MERGEJOIN"></a>

分析查詢的合併聯結執行步驟。

所有使用者都可看見 STL\$1MERGEJOIN。超級使用者可以看見所有資料列；一般使用者只能看見自己的資料。如需詳細資訊，請參閱[系統資料表和檢視中資料的可見性](cm_chap_system-tables.md#c_visibility-of-data)。

**注意**  
STL\$1MERGEJOIN 僅包含在主佈建叢集上執行的查詢。但不包含在並行擴縮叢集上或無伺服器命名空間上執行的查詢。若要存取在主要叢集、並行擴縮叢集和無伺服器命名空間上執行的查詢說明計畫，建議您使用 SYS 監控檢視 [SYS\$1QUERY\$1DETAIL](SYS_QUERY_DETAIL.md)。SYS 監視檢視中的資料會格式化為更易於使用和理解。

## 資料表欄
<a name="r_STL_MERGEJOIN-table-columns"></a>

[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/redshift/latest/dg/r_STL_MERGEJOIN.html)

## 範例查詢
<a name="r_STL_MERGEJOIN-sample-queries"></a>

下列範例會傳回最新查詢的合併聯結結果。

```
select sum(s.qtysold), e.eventname
from event e, listing l, sales s
where e.eventid=l.eventid
and l.listid= s.listid
group by e.eventname;

select * from stl_mergejoin where query=pg_last_query_id();
```

```
 userid | query | slice | segment | step |         starttime   |          endtime    | tasknum | rows | tbl
--------+-------+-------+---------+------+---------------------+---------------------+---------+------+-----
    100 | 27399 |     3 |       4 |    4 | 2013-10-02 16:30:41 | 2013-10-02 16:30:41 |      19 |43428 | 240
    100 | 27399 |     0 |       4 |    4 | 2013-10-02 16:30:41 | 2013-10-02 16:30:41 |      19 |43159 | 240
    100 | 27399 |     2 |       4 |    4 | 2013-10-02 16:30:41 | 2013-10-02 16:30:41 |      19 |42778 | 240
    100 | 27399 |     1 |       4 |    4 | 2013-10-02 16:30:41 | 2013-10-02 16:30:41 |      19 |43091 | 240
```

# STL\$1MV\$1STATE
<a name="r_STL_MV_STATE"></a>

對於具體化視觀表的每個狀態轉換，STL\$1MV\$1STATE 檢視都會包含一個列。

如需具體化視觀表的相關資訊，請參閱 [Amazon Redshift 中的具體化視觀表](materialized-view-overview.md)。

所有使用者都可看見 STL\$1MV\$1STATE。超級使用者可以看見所有資料列；一般使用者只能看見自己的資料。如需詳細資訊，請參閱[系統資料表和檢視中資料的可見性](cm_chap_system-tables.md#c_visibility-of-data)。

此資料表中的部份或所有資料也會在 SYS 監控檢視 [SYS\$1MV\$1STATE](SYS_MV_STATE.md) 中找到。SYS 監視檢視中的資料會格式化為更易於使用和理解。我們建議您使用 SYS 監控檢視進行查詢。

## 資料表欄
<a name="r_STL_MV_STATE-table-columns"></a>

[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/redshift/latest/dg/r_STL_MV_STATE.html)

下表顯示 `event_desc` 和 `state` 範例組合。

```
          event_desc     |     state
-------------------------+---------------
 TRUNCATE                | Recompute
 TRUNCATE                | Recompute
 Small table conversion  | Recompute
 Vacuum                  | Recompute
 Column was renamed      | Unrefreshable
 Column was dropped      | Unrefreshable
 Table was renamed       | Unrefreshable
 Column type was changed | Unrefreshable
 Schema name was changed | Unrefreshable
```

## 範例查詢
<a name="r_STL_MV_STATE-sample-query"></a>

若要檢視具體化視觀表的狀態轉換日誌，請執行下列查詢。

```
select * from stl_mv_state;
```

此查詢傳回下列範例輸出：

```
 userid |         starttime          | xid  |            event_desc       | db_name |  base_table_schema   |   base_table_name    |      mv_schema       | mv_name       |     state
--------+----------------------------+------+-----------------------------+---------+----------------------+----------------------+----------------------+---------------+---------------
    138 | 2020-02-14 02:21:25.578885 | 5180 | TRUNCATE                    | dev     | public               | mv_base_table        | public               | mv_test       | Recompute
    138 | 2020-02-14 02:21:56.846774 | 5275 | Column was dropped          | dev     |                      | mv_base_table        | public               | mv_test       | Unrefreshable
    100 | 2020-02-13 22:09:53.041228 | 1794 | Column was renamed          | dev     |                      | mv_base_table        | public               | mv_test       | Unrefreshable
      1 | 2020-02-13 22:10:23.630914 | 1893 | ALTER TABLE ALTER SORTKEY   | dev     | public               | mv_base_table_sorted | public               | mv_test       | Recompute
      1 | 2020-02-17 22:57:22.497989 | 8455 | ALTER TABLE ALTER DISTSTYLE | dev     | public               | mv_base_table        | public               | mv_test       | Recompute
    173 | 2020-02-17 22:57:23.591434 | 8504 | Table was renamed           | dev     |                      | mv_base_table        | public               | mv_test       | Unrefreshable
    173 | 2020-02-17 22:57:27.229423 | 8592 | Column type was changed     | dev     |                      | mv_base_table        | public               | mv_test       | Unrefreshable
    197 | 2020-02-17 22:59:06.212569 | 9668 | TRUNCATE                    | dev     | schemaf796e415850f4f | mv_base_table        | schemaf796e415850f4f | mv_test       | Recompute
    138 | 2020-02-14 02:21:55.705655 | 5226 | Column was renamed          | dev     |                      | mv_base_table        | public               | mv_test       | Unrefreshable
      1 | 2020-02-14 02:22:26.292434 | 5325 | ALTER TABLE ALTER SORTKEY   | dev     | public               | mv_base_table_sorted | public               | mv_test       | Recompute
```

# STL\$1NESTLOOP
<a name="r_STL_NESTLOOP"></a>

分析查詢的巢狀迴路聯結執行步驟。

所有使用者都可看見 STL\$1NESTLOOP。超級使用者可以看見所有資料列；一般使用者只能看見自己的資料。如需詳細資訊，請參閱[系統資料表和檢視中資料的可見性](cm_chap_system-tables.md#c_visibility-of-data)。

**注意**  
STL\$1NESTLOOP 僅包含在主佈建叢集上執行的查詢。但不包含在並行擴縮叢集上或無伺服器命名空間上執行的查詢。若要存取在主要叢集、並行擴縮叢集和無伺服器命名空間上執行的查詢說明計畫，建議您使用 SYS 監控檢視 [SYS\$1QUERY\$1DETAIL](SYS_QUERY_DETAIL.md)。SYS 監視檢視中的資料會格式化為更易於使用和理解。

## 資料表欄
<a name="r_STL_NESTLOOP-table-columns"></a>

[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/redshift/latest/dg/r_STL_NESTLOOP.html)

## 範例查詢
<a name="r_STL_NESTLOOP-sample-queries"></a>

由於下列查詢會忽略聯結 CATEGORY 資料表，因此它會產生局部 Cartesian 產品，而我們不建議這樣做。在這裡顯示它，是為了說明巢狀迴路。

```
select count(event.eventname), event.eventname, category.catname, date.caldate
from event, category, date
where event.dateid = date.dateid
group by event.eventname, category.catname, date.caldate;
```

下列查詢會將來自前一個查詢的結果顯示在 STL\$1NESTLOOP 檢視中。

```
select query, slice, segment as seg, step, 
datediff(msec, starttime, endtime) as duration, tasknum, rows, tbl
from stl_nestloop
where query = pg_last_query_id();
```

```
 query | slice | seg | step | duration | tasknum | rows  | tbl
-------+-------+-----+------+----------+---------+-------+-----
  6028 |     0 |   4 |    5 |       41 |      22 | 24277 | 240
  6028 |     1 |   4 |    5 |       26 |      23 | 24189 | 240
  6028 |     3 |   4 |    5 |       25 |      23 | 24376 | 240
  6028 |     2 |   4 |    5 |       54 |      22 | 23936 | 240
```

# STL\$1PARSE
<a name="r_STL_PARSE"></a>

分析將字串剖析為二進位值以進行載入的查詢步驟。

所有使用者都可看見 STL\$1PARSE。超級使用者可以看見所有資料列；一般使用者只能看見自己的資料。如需詳細資訊，請參閱[系統資料表和檢視中資料的可見性](cm_chap_system-tables.md#c_visibility-of-data)。

**注意**  
STL\$1PARSE 僅包含在主佈建叢集上執行的查詢。但不包含在並行擴縮叢集上或無伺服器命名空間上執行的查詢。若要存取在主要叢集、並行擴縮叢集和無伺服器命名空間上執行的查詢說明計畫，建議您使用 SYS 監控檢視 [SYS\$1QUERY\$1DETAIL](SYS_QUERY_DETAIL.md)。SYS 監視檢視中的資料會格式化為更易於使用和理解。

## 資料表欄
<a name="r_STL_PARSE-table-columns"></a>

[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/redshift/latest/dg/r_STL_PARSE.html)

## 範例查詢
<a name="r_STL_PARSE-sample-queries"></a>

下列範例會傳回配量 1 和區段 0 的所有查詢步驟，其中字串已剖析為二進位值。

```
select query, step, starttime, endtime, tasknum, rows
from stl_parse
where slice=1 and segment=0;
```

```
 query | step |     starttime       |        endtime      | tasknum |  rows
-------+------+---------------------+---------------------+---------+--------
   669 |    1 | 2013-08-12 22:35:13 | 2013-08-12 22:35:17 |      32 | 192497
   696 |    1 | 2013-08-12 22:35:49 | 2013-08-12 22:35:49 |      32 |      0
   525 |    1 | 2013-08-12 22:32:03 | 2013-08-12 22:32:03 |      13 |  49990
   585 |    1 | 2013-08-12 22:33:18 | 2013-08-12 22:33:19 |      13 |    202
   621 |    1 | 2013-08-12 22:34:03 | 2013-08-12 22:34:03 |      27 |    365
   651 |    1 | 2013-08-12 22:34:47 | 2013-08-12 22:34:53 |      35 | 192497
   590 |    1 | 2013-08-12 22:33:28 | 2013-08-12 22:33:28 |      19 |      0
   599 |    1 | 2013-08-12 22:33:39 | 2013-08-12 22:33:39 |      31 |     11
   675 |    1 | 2013-08-12 22:35:26 | 2013-08-12 22:35:27 |      38 |   3766
   567 |    1 | 2013-08-12 22:32:47 | 2013-08-12 22:32:48 |      23 |  49990
   630 |    1 | 2013-08-12 22:34:17 | 2013-08-12 22:34:17 |      36 |      0
   572 |    1 | 2013-08-12 22:33:04 | 2013-08-12 22:33:04 |      29 |      0
   645 |    1 | 2013-08-12 22:34:37 | 2013-08-12 22:34:38 |      29 |   8798
   604 |    1 | 2013-08-12 22:33:47 | 2013-08-12 22:33:47 |      37 |      0
(14 rows)
```

# STL\$1PLAN\$1INFO
<a name="r_STL_PLAN_INFO"></a>

使用 STL\$1PLAN\$1INFO 檢視，可以根據一組列查看查詢的 EXPLAIN 輸出。這是查看查詢計劃的其他方法。

所有使用者都可看見 STL\$1PLAN\$1INFO。超級使用者可以看見所有資料列；一般使用者只能看見自己的資料。如需詳細資訊，請參閱[系統資料表和檢視中資料的可見性](cm_chap_system-tables.md#c_visibility-of-data)。

**注意**  
STL\$1PLAN\$1INFO 僅包含在主佈建叢集上執行的查詢。但不包含在並行擴縮叢集上或無伺服器命名空間上執行的查詢。若要存取在主要叢集、並行擴縮叢集和無伺服器命名空間上執行的查詢說明計畫，建議您使用 SYS 監控檢視 [SYS\$1QUERY\$1DETAIL](SYS_QUERY_DETAIL.md)。SYS 監視檢視中的資料會格式化為更易於使用和理解。

## 資料表欄
<a name="r_STL_PLAN_INFO-table-columns"></a>

[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/redshift/latest/dg/r_STL_PLAN_INFO.html)

## 範例查詢
<a name="r_STL_PLAN_INFO-sample-queries"></a>

下列範例會比較藉由使用 EXPLAIN 命令，以及藉由查詢 STL\$1PLAN\$1INFO 檢視所傳回之簡單 SELECT 查詢的查詢計劃。

```
explain select * from category;
QUERY PLAN
-------------------------------------------------------------
XN Seq Scan on category (cost=0.00..0.11 rows=11 width=49)
(1 row)

select * from category;
catid | catgroup | catname | catdesc
-------+----------+-----------+--------------------------------------------
1 | Sports | MLB | Major League Baseball
3 | Sports | NFL | National Football League
5 | Sports | MLS | Major League Soccer
...

select * from stl_plan_info where query=256;

query | nodeid | segment | step | locus | plannode | startupcost | totalcost
| rows | bytes
-------+--------+---------+------+-------+----------+-------------+-----------+------+-------
256 | 1 | 0 | 1 | 0 | 104 | 0 | 0.11 | 11 | 539
256 | 1 | 0 | 0 | 0 | 104 | 0 | 0.11 | 11 | 539
(2 rows)
```

在此範例中，PLANNODE 104 指的是 CATEGORY 資料表的循序掃描。

```
select distinct eventname from event order by 1;

eventname
------------------------------------------------------------------------
.38 Special
3 Doors Down
70s Soul Jam
A Bronx Tale
...

explain select distinct eventname from event order by 1;

QUERY PLAN
-------------------------------------------------------------------------------------
XN Merge (cost=1000000000136.38..1000000000137.82 rows=576 width=17)
Merge Key: eventname
-> XN Network (cost=1000000000136.38..1000000000137.82 rows=576
width=17)
Send to leader
-> XN Sort (cost=1000000000136.38..1000000000137.82 rows=576
width=17)
Sort Key: eventname
-> XN Unique (cost=0.00..109.98 rows=576 width=17)
-> XN Seq Scan on event (cost=0.00..87.98 rows=8798
width=17)
(8 rows)

select * from stl_plan_info where query=240 order by nodeid desc;

query | nodeid | segment | step | locus | plannode | startupcost |
totalcost | rows | bytes
-------+--------+---------+------+-------+----------+------------------+------------------+------+--------
240 | 5 | 0 | 0 | 0 | 104 | 0                | 87.98   | 8798 | 149566         
240 | 5 | 0 | 1 | 0 | 104 | 0                | 87.98   | 8798 | 149566
240 | 4 | 0 | 2 | 0 | 117 | 0                | 109.975 | 576  | 9792
240 | 4 | 0 | 3 | 0 | 117 | 0                | 109.975 | 576  | 9792
240 | 4 | 1 | 0 | 0 | 117 | 0                | 109.975 | 576  | 9792
240 | 4 | 1 | 1 | 0 | 117 | 0                | 109.975 | 576  | 9792
240 | 3 | 1 | 2 | 0 | 114 | 1000000000136.38 | 1000000000137.82 | 576 | 9792
240 | 3 | 2 | 0 | 0 | 114 | 1000000000136.38 | 1000000000137.82 | 576 | 9792
240 | 2 | 2 | 1 | 0 | 123 | 1000000000136.38 | 1000000000137.82 | 576 | 9792
240 | 1 | 3 | 0 | 0 | 122 | 1000000000136.38 | 1000000000137.82 | 576 | 9792
(10 rows)
```

# STL\$1PROJECT
<a name="r_STL_PROJECT"></a>

包含用來評估表達式之查詢步驟的資料列。

所有使用者都可看見 STL\$1PROJECT。超級使用者可以看見所有資料列；一般使用者只能看見自己的資料。如需詳細資訊，請參閱[系統資料表和檢視中資料的可見性](cm_chap_system-tables.md#c_visibility-of-data)。

**注意**  
STL\$1PROJECT 僅包含在主佈建叢集上執行的查詢。但不包含在並行擴縮叢集上或無伺服器命名空間上執行的查詢。若要存取在主要叢集、並行擴縮叢集和無伺服器命名空間上執行的查詢說明計畫，建議您使用 SYS 監控檢視 [SYS\$1QUERY\$1DETAIL](SYS_QUERY_DETAIL.md)。SYS 監視檢視中的資料會格式化為更易於使用和理解。

## 資料表欄
<a name="r_STL_PROJECT-table-columns"></a>

[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/redshift/latest/dg/r_STL_PROJECT.html)

## 範例查詢
<a name="r_STL_PROJECT-sample-queries"></a>

下列範例會傳回查詢步驟的所有資料列，而這些查詢步驟是用來評估配量 0 和區段 1 的表達式。

```
select query, step, starttime, endtime, tasknum, rows
from stl_project
where slice=0 and segment=1;
```

```
 query  | step |         starttime   |          endtime    | tasknum | rows
--------+------+---------------------+---------------------+---------+------
  86399 |    2 | 2013-08-29 22:01:21 | 2013-08-29 22:01:21 |      25 |   -1
  86399 |    3 | 2013-08-29 22:01:21 | 2013-08-29 22:01:21 |      25 |   -1
    719 |    1 | 2013-08-12 22:38:33 | 2013-08-12 22:38:33 |       7 |   -1
  86383 |    1 | 2013-08-29 21:58:35 | 2013-08-29 21:58:35 |       7 |   -1
    714 |    1 | 2013-08-12 22:38:17 | 2013-08-12 22:38:17 |       2 |   -1
  86375 |    1 | 2013-08-29 21:57:59 | 2013-08-29 21:57:59 |       2 |   -1
  86397 |    2 | 2013-08-29 22:01:20 | 2013-08-29 22:01:20 |      19 |   -1
    627 |    1 | 2013-08-12 22:34:13 | 2013-08-12 22:34:13 |      34 |   -1
  86326 |    2 | 2013-08-29 21:45:28 | 2013-08-29 21:45:28 |      34 |   -1
  86326 |    3 | 2013-08-29 21:45:28 | 2013-08-29 21:45:28 |      34 |   -1
  86325 |    2 | 2013-08-29 21:45:27 | 2013-08-29 21:45:27 |      28 |   -1
  86371 |    1 | 2013-08-29 21:57:42 | 2013-08-29 21:57:42 |       4 |   -1
 111100 |    2 | 2013-09-03 19:04:45 | 2013-09-03 19:04:45 |      12 |   -1
    704 |    2 | 2013-08-12 22:36:34 | 2013-08-12 22:36:34 |      37 |   -1
    649 |    2 | 2013-08-12 22:34:47 | 2013-08-12 22:34:47 |      38 |   -1
    649 |    3 | 2013-08-12 22:34:47 | 2013-08-12 22:34:47 |      38 |   -1
    632 |    2 | 2013-08-12 22:34:22 | 2013-08-12 22:34:22 |      13 |   -1
    705 |    2 | 2013-08-12 22:36:48 | 2013-08-12 22:36:49 |      13 |   -1
    705 |    3 | 2013-08-12 22:36:48 | 2013-08-12 22:36:49 |      13 |   -1
      3 |    1 | 2013-08-12 20:07:40 | 2013-08-12 20:07:40 |       3 |   -1
  86373 |    1 | 2013-08-29 21:57:58 | 2013-08-29 21:57:58 |       3 |   -1
 107976 |    1 | 2013-09-03 04:05:12 | 2013-09-03 04:05:12 |       3 |   -1
  86381 |    1 | 2013-08-29 21:58:35 | 2013-08-29 21:58:35 |       8 |   -1
  86396 |    1 | 2013-08-29 22:01:20 | 2013-08-29 22:01:20 |      15 |   -1
    711 |    1 | 2013-08-12 22:37:10 | 2013-08-12 22:37:10 |      20 |   -1
  86324 |    1 | 2013-08-29 21:45:27 | 2013-08-29 21:45:27 |      24 |   -1
(26 rows)
```

# STL\$1QUERY
<a name="r_STL_QUERY"></a>

傳回有關資料庫查詢的執行資訊。

**注意**  
STL\$1QUERY 和 STL\$1QUERYTEXT 檢視僅包含查詢的相關資訊，不包含其他公用程式和 DDL 命令的相關資訊。如需 Amazon Redshift 執行之所有陳述式的清單和相關資訊，您也可以查詢 STL\$1DDLTEXT 和 STL\$1UTILITYTEXT 檢視。如需 Amazon Redshift 執行之所有陳述式的完整清單，您可以查詢 SVL\$1STATEMENTTEXT 檢視。

所有使用者都可看見 STL\$1QUERY。超級使用者可以看見所有資料列；一般使用者只能看見自己的資料。如需詳細資訊，請參閱[系統資料表和檢視中資料的可見性](cm_chap_system-tables.md#c_visibility-of-data)。

此資料表中的部份或所有資料也會在 SYS 監控檢視 [SYS\$1QUERY\$1HISTORY](SYS_QUERY_HISTORY.md) 中找到。SYS 監視檢視中的資料會格式化為更易於使用和理解。我們建議您使用 SYS 監控檢視進行查詢。

請注意，當您的查詢文字長度超過 4000 個字元時，STL\$1QUERY 只會顯示截斷的資料。若要取得完整的查詢文字，您可以在各列的查詢文字上使用 UNION。

**注意**  
若要驗證包含已執行查詢的交易是否已成功認可，您需要在系統資料表與 `sys_transaction_history` 資料表之間執行聯結操作。例如：  

```
SELECT 
    stlq.xid AS transaction_id,
    stlq.query AS query_id,
    TRIM(stlq.querytxt) AS query_text,
    th.status AS transaction_status
FROM 
    stl_query stlq
LEFT JOIN 
    sys_transaction_history th ON stlq.xid = th.transaction_id;
```

## 資料表欄
<a name="sub-r_STL_QUERY-table-columns"></a>

[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/redshift/latest/dg/r_STL_QUERY.html)

## 範例查詢
<a name="r_STL_QUERY-sample-queries"></a>

下列查詢會列出五個最新查詢。

```
select query, trim(querytxt) as sqlquery
from stl_query
order by query desc limit 5;

query |                                   sqlquery
------+--------------------------------------------------
129 | select query, trim(querytxt) from stl_query order by query;
128 | select node from stv_disk_read_speeds;
127 | select system_status from stv_gui_status
126 | select * from systable_topology order by slice
125 | load global dict registry
(5 rows)
```

下列查詢會針對 2013 年 2 月 15 日執行的查詢，依遞減順序傳回經過時間。

```
select query, datediff(seconds, starttime, endtime),
trim(querytxt) as sqlquery
from stl_query
where starttime >= '2013-02-15 00:00' and endtime < '2013-02-16 00:00'
order by date_diff desc;

 query | date_diff |  sqlquery
-------+-----------+-------------------------------------------
 55    |       119 | padb_fetch_sample: select count(*) from category
121    |         9 | select * from svl_query_summary;
181    |         6 | select * from svl_query_summary where query in(179,178);
172    |         5 | select * from svl_query_summary where query=148;
...
(189 rows)
```

下列查詢顯示查詢的佇列時間和執行時間。`concurrency_scaling_status = 1` 的查詢執行於並行擴展叢集。所有其他查詢皆執行於主要叢集。

```
SELECT w.service_class AS queue
     , q.concurrency_scaling_status
     , COUNT( * ) AS queries
     , SUM( q.aborted )  AS aborted
     , SUM( ROUND( total_queue_time::NUMERIC / 1000000,2 ) ) AS queue_secs
     , SUM( ROUND( total_exec_time::NUMERIC / 1000000,2 ) )  AS exec_secs
FROM stl_query q
     JOIN stl_wlm_query w
          USING (userid,query)
WHERE q.userid > 1
  AND service_class > 5
  AND q.starttime > '2019-03-01 16:38:00'
  AND q.endtime   < '2019-03-01 17:40:00'
GROUP BY 1,2
ORDER BY 1,2;
```

# STL\$1QUERY\$1METRICS
<a name="r_STL_QUERY_METRICS"></a>

包含已在使用者定義的查詢佇列 (服務類別) 中完成執行之查詢的指標資訊，例如已處理的資料列數目、CPU 用量、輸入/輸出和磁碟使用情形。若要檢視目前執行中之作用中查詢的指標，請參閱 [STV\$1QUERY\$1METRICS](r_STV_QUERY_METRICS.md) 系統檢視。

查詢指標每間隔一秒鐘取樣一次。因此，相同查詢的不同執行可能會傳回稍微不同的時間。另外，可能不會記錄執行時間不到一秒的查詢區段。

STL\$1QUERY\$1METRICS 會追蹤並彙總查詢、區段和步驟層級的指標。如需查詢區段和步驟的相關資訊，請參閱[查詢計劃和執行工作流程](c-query-planning.md)。許多指標 (例如 `max_rows`、`cpu_time` 等等) 是跨節點配量加總的。如需節點配量的相關資訊，請參閱[資料倉儲系統架構](c_high_level_system_architecture.md)。

若要判斷資料列報告指標的層級，請檢查 `segment` 和 `step_type` 資料欄。
+ 如果 `segment` 和 `step_type` 皆為 `-1`，則資料列報告查詢層級的指標。
+ 如果 `segment` 不是 `-1`，且 `step_type` 是 `-1`，則資料列報告區段層級的指標。
+ 如果 `segment` 和 `step_type` 皆不是 `-1`，則資料列報告步驟層級的指標。

[SVL\$1QUERY\$1METRICS](r_SVL_QUERY_METRICS.md) 檢視和 [SVL\$1QUERY\$1METRICS\$1SUMMARY](r_SVL_QUERY_METRICS_SUMMARY.md) 檢視彙總此檢視中的資料，並以更易存取的形式呈現資訊。

所有使用者都可看見 STL\$1QUERY\$1METRICS。超級使用者可以看見所有資料列；一般使用者只能看見自己的資料。如需詳細資訊，請參閱[系統資料表和檢視中資料的可見性](cm_chap_system-tables.md#c_visibility-of-data)。

此資料表中的部份或所有資料也會在 SYS 監控檢視 [SYS\$1QUERY\$1DETAIL](SYS_QUERY_DETAIL.md) 中找到。SYS 監視檢視中的資料會格式化為更易於使用和理解。我們建議您使用 SYS 監控檢視進行查詢。

## 資料表欄
<a name="r_STL_QUERY_METRICS-table-rows2"></a>

[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/redshift/latest/dg/r_STL_QUERY_METRICS.html)

## 範例查詢
<a name="r_STL_QUERY_METRICS-sample-query2"></a>

若要找出具有高 CPU 時間 (超過 1,000 秒) 的查詢，請執行下列查詢。

```
Select query, cpu_time / 1000000 as cpu_seconds
from stl_query_metrics where segment = -1 and cpu_time > 1000000000
order by cpu_time;

query | cpu_seconds
------+------------
25775 |        9540
```

若要找出具有傳回超過一百萬個資料列之巢狀迴圈聯結的使用中查詢，請執行下列查詢。

```
select query, rows 
from stl_query_metrics 
where step_type = 15 and rows > 1000000
order by rows;

query | rows      
------+-----------
25775 | 2621562702
```

若要找出已執行超過 60 秒，但已使用 CPU 時間少於 10 秒的使用中查詢，請執行下列查詢。

```
select query, run_time/1000000 as run_time_seconds
from stl_query_metrics 
where segment = -1 and run_time > 60000000 and cpu_time < 10000000;

query | run_time_seconds
------+-----------------
25775 |              114
```

# STL\$1QUERYTEXT
<a name="r_STL_QUERYTEXT"></a>

擷取 SQL 命令的查詢文字。

查詢 STL\$1QUERYTEXT 檢視，以擷取針對下列陳述式記錄的 SQL：
+ SELECT、SELECT INTO
+ INSERT、UPDATE、DELETE
+ COPY
+ UNLOAD
+ 透過執行 VACUUM 和 ANALYZE 產生的查詢
+ CREATE TABLE AS (CTAS)

若要查詢這些陳述式在特定時段的活動，請聯結 STL\$1QUERYTEXT 和 STL\$1QUERY 檢視。

**注意**  
STL\$1QUERY 和 STL\$1QUERYTEXT 檢視僅包含查詢的相關資訊，不包含其他公用程式和 DDL 命令的相關資訊。如需 Amazon Redshift 執行之所有陳述式的清單和相關資訊，您也可以查詢 STL\$1DDLTEXT 和 STL\$1UTILITYTEXT 檢視。如需 Amazon Redshift 執行之所有陳述式的完整清單，您可以查詢 SVL\$1STATEMENTTEXT 檢視。

另請參閱 [STL\$1DDLTEXT](r_STL_DDLTEXT.md)、[STL\$1UTILITYTEXT](r_STL_UTILITYTEXT.md) 和 [SVL\$1STATEMENTTEXT](r_SVL_STATEMENTTEXT.md)。

所有使用者都可看見 STL\$1QUERYTEXT。超級使用者可以看見所有資料列；一般使用者只能看見自己的資料。如需詳細資訊，請參閱[系統資料表和檢視中資料的可見性](cm_chap_system-tables.md#c_visibility-of-data)。

此資料表中的部份或所有資料也會在 SYS 監控檢視 [SYS\$1QUERY\$1TEXT](SYS_QUERY_TEXT.md) 中找到。SYS 監視檢視中的資料會格式化為更易於使用和理解。我們建議您使用 SYS 監控檢視進行查詢。

請注意，當您的查詢文字長度超過 4000 個字元時，STL\$1QUERYTEXT 只會顯示截斷的資料。若要取得完整的查詢文字，您可以在各列的查詢文字上使用 UNION。

## 資料表欄
<a name="r_STL_QUERYTEXT-table-columns"></a>

[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/redshift/latest/dg/r_STL_QUERYTEXT.html)

## 範例查詢
<a name="r_STL_QUERYTEXT-sample-queries"></a>

您可以使用 PG\$1BACKEND\$1PID() 函數，來擷取目前工作階段的資訊。例如，下列查詢會針對目前工作階段中完成的查詢傳回其查詢 ID 和一部分的查詢文字。

```
select query, substring(text,1,60)
from stl_querytext
where pid = pg_backend_pid()
order by query desc;

 query |                         substring
-------+--------------------------------------------------------------
 28262 | select query, substring(text,1,80) from stl_querytext where 
 28252 | select query, substring(path,0,80) as path from stl_unload_l
 28248 | copy category from 's3://dw-tickit/manifest/category/1030_ma
 28247 | Count rows in target table
 28245 | unload ('select * from category') to 's3://dw-tickit/manifes
 28240 | select query, substring(text,1,40) from stl_querytext where 
(6 rows)
```

### 重建儲存的 SQL
<a name="r_STL_QUERYTEXT-reconstruct-sql"></a>

若要重建儲存在 STL\$1QUERYTEXT `text` 資料欄中的 SQL，則需執行 SELECT 陳述式以從 `text` 資料欄的一或多個部分建立 SQL。請先以新的一行取代任意 (`\n`) 特殊字元，再執行重建的 SQL。下列 SELECT 陳述式顯示的結果會是 `query_statement` 欄中重建的 SQL 資料列。

```
SELECT query, LISTAGG(CASE WHEN LEN(RTRIM(text)) = 0 THEN text ELSE RTRIM(text) END) WITHIN GROUP (ORDER BY sequence) as query_statement, COUNT(*) as row_count 
FROM stl_querytext GROUP BY query ORDER BY query desc;
```

例如，下列查詢會選取 3 個資料欄。該查詢本身的長度超過 200 個字元，且會儲存在 STL\$1QUERYTEXT 的多個部分中。

```
select
1 AS a0123456789012345678901234567890123456789012345678901234567890,
2 AS b0123456789012345678901234567890123456789012345678901234567890,
3 AS b012345678901234567890123456789012345678901234
FROM stl_querytext;
```

在本範例中，查詢會儲存在 STL\$1QUERYTEXT `text` 資料欄的 2 個部分 (資料列) 中。

```
select query, sequence, text
from stl_querytext where query=pg_last_query_id() order by query desc, sequence limit 10;
```

```
query  | sequence |                                                                                             text                                                                                                   
-------+----------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    45 |        0 | select\n1 AS a0123456789012345678901234567890123456789012345678901234567890,\n2 AS b0123456789012345678901234567890123456789012345678901234567890,\n3 AS b012345678901234567890123456789012345678901234
    45 |        1 | \nFROM stl_querytext;
```

若要重建儲存在 STL\$1QUERYTEXT 中的 SQL，請執行下列 SQL。

```
select LISTAGG(CASE WHEN LEN(RTRIM(text)) = 0 THEN text ELSE RTRIM(text) END, '') within group (order by sequence) AS text 
from stl_querytext where query=pg_last_query_id();
```

若要在用戶端中使用產生的重建 SQL，請以新的一行取代任意 (`\n`) 特殊字元。

```
                                                                                                             text                                                                                                             
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 select\n1 AS a0123456789012345678901234567890123456789012345678901234567890,\n2 AS b0123456789012345678901234567890123456789012345678901234567890,\n3 AS b012345678901234567890123456789012345678901234\nFROM stl_querytext;
```

# STL\$1REPLACEMENTS
<a name="r_STL_REPLACEMENTS"></a>

顯示一個日誌，其記錄搭配 ACCEPTINVCHARS 選項的 [COPY](r_COPY.md) 命令何時取代無效的 UTF-8 字元。在至少需要一個取代項目的每個節點上，對於其前 100 個資料列的每一個都會新增一個日誌項目至 STL\$1REPLACEMENTS。

所有使用者都可看見 STL\$1REPLACEMENTS。超級使用者可以看見所有資料列；一般使用者只能看見自己的資料。如需詳細資訊，請參閱[系統資料表和檢視中資料的可見性](cm_chap_system-tables.md#c_visibility-of-data)。

**注意**  
STL\$1NESTLOOP 僅包含在主佈建叢集上執行的查詢。但不包含在並行擴縮叢集上或無伺服器命名空間上執行的查詢。若要存取在主要叢集、並行擴縮叢集和無伺服器命名空間上執行的查詢說明計畫，建議您使用 SYS 監控檢視 [SYS\$1COPY\$1REPLACEMENTS](SYS_COPY_REPLACEMENTS.md)。SYS 監視檢視中的資料會格式化為更易於使用和理解。

## 資料表欄
<a name="r_STL_REPLACEMENTS-table-columns2"></a>

[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/redshift/latest/dg/r_STL_REPLACEMENTS.html)

## 範例查詢
<a name="r_STL_REPLACEMENTS-sample-queries"></a>

下列範例會傳回最新 COPY 操作的取代項目。

```
select query, session, filename, line_number, colname
from stl_replacements
where query = pg_last_copy_id();

 query | session |   filename                                  | line_number | colname
 ------+---------+---------------------------------------------+-------------+--------
    96 |    6314 | s3://DOC-EXAMPLE-BUCKET/allusers_pipe.txt   |         251 | city
    96 |    6314 | s3://DOC-EXAMPLE-BUCKET/allusers_pipe.txt   |         317 | city
    96 |    6314 | s3://DOC-EXAMPLE-BUCKET/allusers_pipe.txt   |         569 | city
    96 |    6314 | s3://DOC-EXAMPLE-BUCKET/allusers_pipe.txt   |         623 | city
    96 |    6314 | s3://DOC-EXAMPLE-BUCKET/allusers_pipe.txt   |         694 | city
...
```

# STL\$1RESTARTED\$1SESSIONS
<a name="r_STL_RESTARTED_SESSIONS"></a>

為了要在特定內部事件後維持持續可用性，Amazon Redshift 可能會利用新的處理程序 ID (PID) 重新啟動作用中工作階段。當 Amazon Redshift 重新啟動工作階段時，STL\$1RESTARTED\$1SESSIONS 會記錄新的 PID 和舊的 PID。

 如需詳細資訊，請參閱本節中的下列範例。

所有使用者都可看見 STL\$1RESTARTED\$1SESSIONS。超級使用者可以看見所有資料列；一般使用者只能看見自己的資料。如需詳細資訊，請參閱[系統資料表和檢視中資料的可見性](cm_chap_system-tables.md#c_visibility-of-data)。

此資料表中的部份或所有資料也會在 SYS 監控檢視 [SYS\$1SESSION\$1HISTORY](SYS_SESSION_HISTORY.md) 中找到。SYS 監視檢視中的資料會格式化為更易於使用和理解。我們建議您使用 SYS 監控檢視進行查詢。

## 資料表欄
<a name="r_STL_RESTARTED_SESSIONS-table-columns2"></a>

[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/redshift/latest/dg/r_STL_RESTARTED_SESSIONS.html)

## 範例查詢
<a name="r_STL_RESTARTED_SESSIONS-sample-queries"></a>

下列範例聯結 STL\$1RESTARTED\$1SESSIONS 與 STL\$1SESSIONS，為已重新啟動的工作階段顯示使用者名稱。

```
select process, stl_restarted_sessions.newpid, user_name
from stl_sessions
inner join stl_restarted_sessions on stl_sessions.process = stl_restarted_sessions.oldpid
order by process;

...
```

# STL\$1RETURN
<a name="r_STL_RETURN"></a>

包含查詢中*傳回*步驟的詳細資訊。傳回步驟會將運算節點上完成之查詢的結果傳回至領導者節點。然後，領導者節點會合併資料，並將結果傳回至提出請求的用戶端。對於領導者節點上完成的查詢，傳回步驟會將結果傳回至用戶端。

查詢包含多個區段，每個區段包含一或多個步驟。如需詳細資訊，請參閱[查詢處理](c-query-processing.md)。

所有使用者都可看見 STL\$1RETURN。超級使用者可以看見所有資料列；一般使用者只能看見自己的資料。如需詳細資訊，請參閱[系統資料表和檢視中資料的可見性](cm_chap_system-tables.md#c_visibility-of-data)。

**注意**  
STL\$1RETURN 僅包含在主佈建叢集上執行的查詢。但不包含在並行擴縮叢集上或無伺服器命名空間上執行的查詢。若要存取在主要叢集、並行擴縮叢集和無伺服器命名空間上執行的查詢說明計畫，建議您使用 SYS 監控檢視 [SYS\$1QUERY\$1DETAIL](SYS_QUERY_DETAIL.md)。SYS 監視檢視中的資料會格式化為更易於使用和理解。

## 資料表欄
<a name="r_STL_RETURN-table-columns"></a>

[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/redshift/latest/dg/r_STL_RETURN.html)

## 範例查詢
<a name="r_STL_RETURN-sample-queries"></a>

下列範例顯示最新查詢中的哪些步驟已在每個配量上執行。

```
SELECT query, slice, segment, step, endtime, rows, packets 
from stl_return where query = pg_last_query_id();

 query |  slice | segment | step |          endtime           | rows | packets 
-------+--------+---------+------+----------------------------+------+---------
     4 |      2 |       3 |    2 | 2013-12-27 01:43:21.469043 |    3 |       0
     4 |      3 |       3 |    2 | 2013-12-27 01:43:21.473321 |    0 |       0
     4 |      0 |       3 |    2 | 2013-12-27 01:43:21.469118 |    2 |       0
     4 |      1 |       3 |    2 | 2013-12-27 01:43:21.474196 |    0 |       0
     4 |      4 |       3 |    2 | 2013-12-27 01:43:21.47704  |    2 |       0
     4 |      5 |       3 |    2 | 2013-12-27 01:43:21.478593 |    0 |       0
     4 |   12811|       4 |    1 | 2013-12-27 01:43:21.480755 |    0 |       0
(7 rows)
```

# STL\$1S3CLIENT
<a name="r_STL_S3CLIENT"></a>

記錄傳輸時間和其他效能指標。

使用 STL\$1S3CLIENT 資料表來尋找從 Amazon S3 傳輸資料所花費的時間。

所有使用者都可看見 STL\$1S3CLIENT。超級使用者可以看見所有資料列；一般使用者只能看見自己的資料。如需詳細資訊，請參閱[系統資料表和檢視中資料的可見性](cm_chap_system-tables.md#c_visibility-of-data)。

## 資料表欄
<a name="r_STL_S3CLIENT-table-columns2"></a>

[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/redshift/latest/dg/r_STL_S3CLIENT.html)

## 範例查詢
<a name="r_STL_S3CLIENT-sample-query2"></a>

下列查詢會傳回使用 COPY 命令來載入檔案所花費的時間。

```
select slice, key, transfer_time 
from stl_s3client 
where query = pg_last_copy_id();
```

結果

```
 slice |   key                       | transfer_time
 ------+-----------------------------+---------------
     0 | listing10M0003_part_00      |    16626716
     1 | listing10M0001_part_00      |    12894494
     2 | listing10M0002_part_00      |    14320978
     3 | listing10M0000_part_00      |    11293439
  3371 | prefix=listing10M;marker=   |       99395
```

下列查詢會將 `start_time` 和 `end_time` 轉換為時間戳記。

```
select userid,query,slice,pid,recordtime,start_time,end_time,
'2000-01-01'::timestamp + (start_time/1000000.0)* interval '1 second' as start_ts,
'2000-01-01'::timestamp + (end_time/1000000.0)* interval '1 second' as end_ts 
from stl_s3client where query> -1 limit 5;
```

```
 userid | query | slice |  pid  |         recordtime         |   start_time    |    end_time     |          start_ts          |           end_ts           
--------+-------+-------+-------+----------------------------+-----------------+-----------------+----------------------------+----------------------------
      0 |     0 |     0 | 23449 | 2019-07-14 16:27:17.207839 | 616436837154256 | 616436837207838 | 2019-07-14 16:27:17.154256 | 2019-07-14 16:27:17.207838
      0 |     0 |     0 | 23449 | 2019-07-14 16:27:17.252521 | 616436837208208 | 616436837252520 | 2019-07-14 16:27:17.208208 | 2019-07-14 16:27:17.25252
      0 |     0 |     0 | 23449 | 2019-07-14 16:27:17.284376 | 616436837208460 | 616436837284374 | 2019-07-14 16:27:17.20846  | 2019-07-14 16:27:17.284374
      0 |     0 |     0 | 23449 | 2019-07-14 16:27:17.285307 | 616436837208980 | 616436837285306 | 2019-07-14 16:27:17.20898  | 2019-07-14 16:27:17.285306
      0 |     0 |     0 | 23449 | 2019-07-14 16:27:17.353853 | 616436837302216 | 616436837353851 | 2019-07-14 16:27:17.302216 | 2019-07-14 16:27:17.353851
```

# STL\$1S3CLIENT\$1ERROR
<a name="r_STL_S3CLIENT_ERROR"></a>

記錄從 Amazon S3 載入檔案時配量遇到的錯誤。

使用 STL\$1S3CLIENT\$1ERROR 來尋找從 Amazon S3 傳輸資料時所遇到之錯誤的詳細資訊，做為 COPY 命令的一部分。

所有使用者都可看見 STL\$1S3CLIENT\$1ERROR。超級使用者可以看見所有資料列；一般使用者只能看見自己的資料。如需詳細資訊，請參閱[系統資料表和檢視中資料的可見性](cm_chap_system-tables.md#c_visibility-of-data)。

## 資料表欄
<a name="r_STL_S3CLIENT_ERROR-table-columns2"></a>

[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/redshift/latest/dg/r_STL_S3CLIENT_ERROR.html)

## 使用須知
<a name="w2aac59c29b9c97c11"></a>

如果看到多個錯誤具有「連線逾時」，則可能發生聯網問題。如果您使用的是增強型 VPC 路由，請驗證您在叢集 VPC 與資料來源之間具有一個有效的網路路徑。如需詳細資訊，請參閱 [Amazon Redshift 增強型 VPC 路由](https://docs.aws.amazon.com/redshift/latest/mgmt/enhanced-vpc-routing.html)。

## 範例查詢
<a name="w2aac59c29b9c97c13"></a>

下列查詢會從目前工作階段期間完成的 COPY 命令傳回錯誤。

```
select query, sliceid, substring(key from 1 for 20) as file, 
substring(error from 1 for 35) as error  
from stl_s3client_error 
where pid = pg_backend_pid()
order by query desc;
```

結果

```
 query  | sliceid |     file           |              error                             
--------+---------+--------------------+------------------------------------
 362228 |      12 | part.tbl.25.159.gz | transfer closed with 1947655 bytes 
 362228 |      24 | part.tbl.15.577.gz | transfer closed with 1881910 bytes 
 362228 |       7 | part.tbl.22.600.gz | transfer closed with 700143 bytes r 
 362228 |      22 | part.tbl.3.34.gz   | transfer closed with 2334528 bytes 
 362228 |      11 | part.tbl.30.274.gz | transfer closed with 699031 bytes r
 362228 |      30 | part.tbl.5.509.gz  | Unknown SSL protocol error in conne
 361999 |      10 | part.tbl.23.305.gz | transfer closed with 698959 bytes r
 361999 |      19 | part.tbl.26.582.gz | transfer closed with 1881458 bytes 
 361999 |       4 | part.tbl.15.629.gz | transfer closed with 2275907 bytes 
 361999 |      20 | part.tbl.6.456.gz  | transfer closed with 692162 bytes r
(10 rows)
```

# STL\$1SAVE
<a name="r_STL_SAVE"></a>

包含查詢中*儲存*步驟的詳細資訊。儲存步驟會將輸入串流儲存至暫時性資料表。暫時性資料表是暫存資料表，其會在查詢執行期間儲存中繼結果。

查詢包含多個區段，每個區段包含一或多個步驟。如需詳細資訊，請參閱[查詢處理](c-query-processing.md)。

所有使用者都可看見 STL\$1SAVE。超級使用者可以看見所有資料列；一般使用者只能看見自己的資料。如需詳細資訊，請參閱[系統資料表和檢視中資料的可見性](cm_chap_system-tables.md#c_visibility-of-data)。

**注意**  
STL\$1SAVE 僅包含在主佈建叢集上執行的查詢。但不包含在並行擴縮叢集上或無伺服器命名空間上執行的查詢。若要存取在主要叢集、並行擴縮叢集和無伺服器命名空間上執行的查詢說明計畫，建議您使用 SYS 監控檢視 [SYS\$1QUERY\$1DETAIL](SYS_QUERY_DETAIL.md)。SYS 監視檢視中的資料會格式化為更易於使用和理解。

## 資料表欄
<a name="w2aac59c29b9c99c13"></a>

[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/redshift/latest/dg/r_STL_SAVE.html)

## 範例查詢
<a name="r_STL_SAVE-sample-queries"></a>

下列範例顯示最新查詢中的哪些儲存步驟已在每個配量上執行。

```
select query, slice, segment, step, tasknum, rows,  tbl  
from stl_save where query = pg_last_query_id();

 query | slice | segment | step | tasknum | rows | tbl
-------+-------+---------+------+---------+------+-----
 52236 |     3 |       0 |    2 |      21 |    0 | 239
 52236 |     2 |       0 |    2 |      20 |    0 | 239
 52236 |     2 |       2 |    2 |      20 |    0 | 239
 52236 |     3 |       2 |    2 |      21 |    0 | 239
 52236 |     1 |       0 |    2 |      21 |    0 | 239
 52236 |     0 |       0 |    2 |      20 |    0 | 239
 52236 |     0 |       2 |    2 |      20 |    0 | 239
 52236 |     1 |       2 |    2 |      21 |    0 | 239
(8 rows)
```

# STL\$1SCAN
<a name="r_STL_SCAN"></a>

分析查詢的資料表掃描步驟。此資料表中資料列的步驟號碼一律為 0，因為掃描是區段中的第一個步驟。

所有使用者都可看見 STL\$1SCAN。超級使用者可以看見所有資料列；一般使用者只能看見自己的資料。如需詳細資訊，請參閱[系統資料表和檢視中資料的可見性](cm_chap_system-tables.md#c_visibility-of-data)。

**注意**  
STL\$1SCAN 僅包含在主佈建叢集上執行的查詢。但不包含在並行擴縮叢集上或無伺服器命名空間上執行的查詢。若要存取在主要叢集、並行擴縮叢集和無伺服器命名空間上執行的查詢說明計畫，建議您使用 SYS 監控檢視 [SYS\$1QUERY\$1DETAIL](SYS_QUERY_DETAIL.md)。SYS 監視檢視中的資料會格式化為更易於使用和理解。

## 資料表欄
<a name="r_STL_SCAN-table-columns"></a>

[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/redshift/latest/dg/r_STL_SCAN.html)

## 掃描類型
<a name="r_STL_SCAN-scan-types"></a>

[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/redshift/latest/dg/r_STL_SCAN.html)

## 使用須知
<a name="w2aac59c29b9d101c15"></a>

在理想情況下，`rows` 應該相當接近 `rows_pre_filter`。`rows` 與 `rows_pre_filter` 之間的差異若很大，表示執行引擎正在掃描稍後將捨棄的資料列，這樣做缺乏效率。`rows_pre_filter` 與 `rows_pre_user_filter` 之間的差異是掃描中幽靈資料列的數目。執行 VACUUM 以移除標記進行刪除的資料。`rows` 與 `rows_pre_user_filter` 之間的差異是查詢所篩選的資料列數目。若有許多資料列已遭使用者篩選條件捨棄，請檢閱您選擇的排序資料欄，或若這是由於大型未排序區域所致，請執行清空。

## 範例查詢
<a name="r_STL_SCAN-sample-queries"></a>

下列範例顯示 `rows_pre_filter` 大於 `rows_pre_user_filter`，因為資料表已刪除未清空的資料列 (幽靈資料列)。

```
SELECT query, slice, segment,step,rows, rows_pre_filter, rows_pre_user_filter 
from stl_scan where query = pg_last_query_id();

 query |  slice | segment | step | rows  | rows_pre_filter | rows_pre_user_filter
-------+--------+---------+------+-------+-----------------+----------------------
 42915 |      0 |       0 |    0 | 43159 |           86318 |                43159
 42915 |      0 |       1 |    0 |     1 |               0 |                    0
 42915 |      1 |       0 |    0 | 43091 |           86182 |                43091
 42915 |      1 |       1 |    0 |     1 |               0 |                    0
 42915 |      2 |       0 |    0 | 42778 |           85556 |                42778
 42915 |      2 |       1 |    0 |     1 |               0 |                    0
 42915 |      3 |       0 |    0 | 43428 |           86856 |                43428
 42915 |      3 |       1 |    0 |     1 |               0 |                    0
 42915 |  10000 |       2 |    0 |     4 |               0 |                    0
(9 rows)
```

# STL\$1SCHEMA\$1QUOTA\$1VIOLATIONS
<a name="r_STL_SCHEMA_QUOTA_VIOLATIONS"></a>

超過結構描述配額時，記錄出現次數、時間戳記、XID 和其他有用的資訊。

所有使用者都可看見 STL\$1SCHEMA\$1QUOTA\$1VIOLATIONS。超級使用者可以看見所有資料列；一般使用者只能看見自己的資料。如需詳細資訊，請參閱[系統資料表和檢視中資料的可見性](cm_chap_system-tables.md#c_visibility-of-data)。

此資料表中的部份或所有資料也會在 SYS 監控檢視 [SYS\$1SCHEMA\$1QUOTA\$1VIOLATIONS](r_SYS_SCHEMA_QUOTA_VIOLATIONS.md) 中找到。SYS 監視檢視中的資料會格式化為更易於使用和理解。我們建議您使用 SYS 監控檢視進行查詢。

## 資料表欄
<a name="r_STL_SCHEMA_QUOTA_VIOLATIONS-table-columns"></a>

[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/redshift/latest/dg/r_STL_SCHEMA_QUOTA_VIOLATIONS.html)

## 範例查詢
<a name="r_STL_SCHEMA_QUOTA_VIOLATIONS-sample-queries"></a>

下列查詢顯示配額違規的結果：

```
SELECT userid, TRIM(SCHEMA_NAME) "schema_name", quota, disk_usage, disk_usage_pct, timestamp FROM
stl_schema_quota_violations WHERE SCHEMA_NAME = 'sales_schema' ORDER BY timestamp DESC;
```

此查詢會傳回所指定結構描述的下列範例輸出：

```
userid | schema_name  | quota | disk_usage | disk_usage_pct |timestamp
-------+--------------+-------+------------+----------------+----------------------------
104    | sales_schema | 2048  | 2798       |  136.62        | 2020-04-20 20:09:25.494723
(1 row)
```

# STL\$1SESSIONS
<a name="r_STL_SESSIONS"></a>

傳回使用者工作階段歷史記錄的相關資訊。

STL\$1SESSIONS 不同於 STV\$1SESSIONS，其中 STL\$1SESSIONS 包含工作階段歷史記錄，而 STV\$1SESSIONS 包含目前作用中的工作階段。

所有使用者都可看見 STL\$1SESSIONS。超級使用者可以看見所有資料列；一般使用者只能看見自己的資料。如需詳細資訊，請參閱[系統資料表和檢視中資料的可見性](cm_chap_system-tables.md#c_visibility-of-data)。

此資料表中的部份或所有資料也會在 SYS 監控檢視 [SYS\$1SESSION\$1HISTORY](SYS_SESSION_HISTORY.md) 中找到。SYS 監視檢視中的資料會格式化為更易於使用和理解。我們建議您使用 SYS 監控檢視進行查詢。

## 資料表欄
<a name="r_STL_SESSIONS-table-columns"></a>

[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/redshift/latest/dg/r_STL_SESSIONS.html)

## 範例查詢
<a name="r_STL_SESSIONS-sample-queries"></a>

若要檢視 TICKIT 資料庫的工作階段歷史記錄，請輸入下列查詢：

```
select starttime, process, user_name, timeout_sec, timed_out
from stl_sessions
where db_name='tickit' order by starttime;
```

此查詢傳回下列範例輸出：

```
    starttime              | process |  user_name             | timeout_sec | timed_out
---------------------------+---------+------------------------+-------------+-------------
2008-09-15 09:54:06.746705 |   32358 | dwuser                 | 120         | 1
2008-09-15 09:56:34.30275  |   32744 | dwuser                 | 60          | 1
2008-09-15 11:20:34.694837 |   14906 | dwuser                 | 0           | 0
2008-09-15 11:22:16.749818 |   15148 | dwuser                 | 0           | 0
2008-09-15 14:32:44.66112  |   14031 | dwuser                 | 0           | 0
2008-09-15 14:56:30.22161  |   18380 | dwuser                 | 0           | 0
2008-09-15 15:28:32.509354 |   24344 | dwuser                 | 0           | 0
2008-09-15 16:01:00.557326 |   30153 | dwuser                 | 120         | 1
2008-09-15 17:28:21.419858 |   12805 | dwuser                 | 0           | 0
2008-09-15 20:58:37.601937 |   14951 | dwuser                 | 60          | 1
2008-09-16 11:12:30.960564 |   27437 | dwuser                 | 60          | 1
2008-09-16 14:11:37.639092 |   23790 | dwuser                 | 3600        | 1
2008-09-16 15:13:46.02195  |    1355 | dwuser                 | 120         | 1
2008-09-16 15:22:36.515106 |    2878 | dwuser                 | 120         | 1
2008-09-16 15:44:39.194579 |    6470 | dwuser                 | 120         | 1
2008-09-16 16:50:27.02138  |   17254 | dwuser                 | 120         | 1
2008-09-17 12:05:02.157208 |    8439 | dwuser                 | 3600        | 0
(17 rows)
```

# STL\$1SORT
<a name="r_STL_SORT"></a>

顯示查詢的排序執行步驟，例如使用 ORDER BY 處理的步驟。

所有使用者都可看見 STL\$1SORT。超級使用者可以看見所有資料列；一般使用者只能看見自己的資料。如需詳細資訊，請參閱[系統資料表和檢視中資料的可見性](cm_chap_system-tables.md#c_visibility-of-data)。

**注意**  
STL\$1SORT 僅包含在主佈建叢集上執行的查詢。但不包含在並行擴縮叢集上或無伺服器命名空間上執行的查詢。若要存取在主要叢集、並行擴縮叢集和無伺服器命名空間上執行的查詢說明計畫，建議您使用 SYS 監控檢視 [SYS\$1QUERY\$1DETAIL](SYS_QUERY_DETAIL.md)。SYS 監視檢視中的資料會格式化為更易於使用和理解。

## 資料表欄
<a name="r_STL_SORT-table-columns"></a>

[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/redshift/latest/dg/r_STL_SORT.html)

## 範例查詢
<a name="r_STL_SORT-sample-queries"></a>

下列範例傳回配量 0 和區段 1 的排序結果。

```
select query, bytes, tbl, is_diskbased, workmem
from stl_sort
where slice=0 and segment=1;
```

```
 query |  bytes  | tbl | is_diskbased |  workmem
-------+---------+-----+--------------+-----------
   567 | 3126968 | 241 | f            | 383385600
   604 |    5292 | 242 | f            | 383385600
   675 |  104776 | 251 | f            | 383385600
   525 | 3126968 | 251 | f            | 383385600
   585 |    5068 | 241 | f            | 383385600
   630 |  204808 | 266 | f            | 383385600
   704 |       0 | 242 | f            |         0
   669 | 4606416 | 241 | f            | 383385600
   696 |  104776 | 241 | f            | 383385600
   651 | 4606416 | 254 | f            | 383385600
   632 |       0 | 256 | f            |         0
   599 |     396 | 241 | f            | 383385600
 86397 |       0 | 242 | f            |         0
   621 |    5292 | 241 | f            | 383385600
 86325 |       0 | 242 | f            |         0
   572 |    5068 | 242 | f            | 383385600
   645 |  204808 | 241 | f            | 383385600
   590 |     396 | 242 | f            | 383385600
(18 rows)
```

# STL\$1SSHCLIENT\$1ERROR
<a name="r_STL_SSHCLIENT_ERROR"></a>

 記錄 SSH 用戶端看到的所有錯誤。

所有使用者都可看見 STL\$1SSHCLIENT\$1ERROR。超級使用者可以看見所有資料列；一般使用者只能看見自己的資料。如需詳細資訊，請參閱[系統資料表和檢視中資料的可見性](cm_chap_system-tables.md#c_visibility-of-data)。

## 資料表欄
<a name="r_STL_SSHCLIENT_ERROR-table-columns"></a>

[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/redshift/latest/dg/r_STL_SSHCLIENT_ERROR.html)

# STL\$1STREAM\$1SEGS
<a name="r_STL_STREAM_SEGS"></a>

列出串流與並行區段之間的關係。

此內容中的串流是 Amazon Redshift 串流。此系統檢視不屬於 [將擷取串流至具體化視觀表](materialized-view-streaming-ingestion.md)。

所有使用者都可看見 STL\$1STREAM\$1SEGS。超級使用者可以看見所有資料列；一般使用者只能看見自己的資料。如需詳細資訊，請參閱[系統資料表和檢視中資料的可見性](cm_chap_system-tables.md#c_visibility-of-data)。

**注意**  
STL\$1STREAM\$1SEGS 僅包含在主佈建叢集上執行的查詢。但不包含在並行擴縮叢集上或無伺服器命名空間上執行的查詢。若要存取在主要叢集、並行擴縮叢集和無伺服器命名空間上執行的查詢說明計畫，建議您使用 SYS 監控檢視 [SYS\$1QUERY\$1DETAIL](SYS_QUERY_DETAIL.md)。SYS 監視檢視中的資料會格式化為更易於使用和理解。

## 資料表欄
<a name="r_STL_STREAM_SEGS-table-columns"></a>

[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/redshift/latest/dg/r_STL_STREAM_SEGS.html)

## 範例查詢
<a name="r_STL_STREAM_SEGS-sample-queries"></a>

若要針對最新查詢檢視串流與並行區段之間的關係，請輸入下列查詢：

```
select *
from stl_stream_segs
where query = pg_last_query_id();

 query | stream | segment
-------+--------+---------
    10 |      1 |       2
    10 |      0 |       0
    10 |      2 |       4
    10 |      1 |       3
    10 |      0 |       1
(5 rows)
```

# STL\$1TR\$1CONFLICT
<a name="r_STL_TR_CONFLICT"></a>

顯示資訊以識別並解決交易與資料庫資料表的衝突。

當兩個以上使用者正在查詢和修改資料表中的資料列，以致其交易無法序列化時，即會發生交易衝突。交易若執行將中斷序列化的陳述式，其會遭到停止並進行復原。每次發生交易衝突，Amazon Redshift 就會將資料列寫入至 STL\$1TR\$1CONFLICT 系統資料表，其中包含已取消之交易的詳細資訊。如需詳細資訊，請參閱[Amazon Redshift 中的隔離層級](c_serial_isolation.md)。

只有超級使用者才能看到 STL\$1TR\$1CONFLICT。如需詳細資訊，請參閱[系統資料表和檢視中資料的可見性](cm_chap_system-tables.md#c_visibility-of-data)。

此資料表中的部份或所有資料也會在 SYS 監控檢視 [SYS\$1TRANSACTION\$1HISTORY](SYS_TRANSACTION_HISTORY.md) 中找到。SYS 監視檢視中的資料會格式化為更易於使用和理解。我們建議您使用 SYS 監控檢視進行查詢。

## 資料表欄
<a name="r_STL_TR_CONFLICT-table-columns"></a>

[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/redshift/latest/dg/r_STL_TR_CONFLICT.html)

## 範例查詢
<a name="r_STL_TR_CONFLICT-sample-query"></a>

若要傳回涉及特定資料表之衝突的相關資訊，請執行一個指定資料表 ID 的查詢：

```
select * from stl_tr_conflict where table_id=100234
order by xact_start_ts;

xact_id|process_|      xact_start_ts       |        abort_time        |table_
       |id      |                          |                          |id
-------+--------+--------------------------+--------------------------+------
  1876 |  8551  |2010-03-30 09:19:15.852326|2010-03-30 09:20:17.582499|100234
  1928 | 15034  |2010-03-30 13:20:00.636045|2010-03-30 13:20:47.766817|100234
  1991 | 23753  |2010-04-01 13:05:01.220059|2010-04-01 13:06:06.94098 |100234
  2002 | 23679  |2010-04-01 13:17:05.173473|2010-04-01 13:18:27.898655|100234
(4 rows)
```

您可以從序列化違規之錯誤訊息的 DETAIL 區段取得資料表 ID (錯誤 1023)。

# STL\$1UNDONE
<a name="r_STL_UNDONE"></a>

顯示已復原之交易的相關資訊。

所有使用者都可看見 STL\$1UNDONE。超級使用者可以看見所有資料列；一般使用者只能看見自己的資料。如需詳細資訊，請參閱[系統資料表和檢視中資料的可見性](cm_chap_system-tables.md#c_visibility-of-data)。

此資料表中的部份或所有資料也會在 SYS 監控檢視 [SYS\$1TRANSACTION\$1HISTORY](SYS_TRANSACTION_HISTORY.md) 中找到。SYS 監視檢視中的資料會格式化為更易於使用和理解。我們建議您使用 SYS 監控檢視進行查詢。

## 資料表欄
<a name="r_STL_UNDONE-table-columns"></a>

[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/redshift/latest/dg/r_STL_UNDONE.html)

## 範例查詢
<a name="r_STL_UNDONE-sample-query"></a>

若要檢視所有已復原之交易的精簡日誌，請輸入下列命令：

```
select xact_id, xact_id_undone, table_id from stl_undone;
```

此命令會傳回下列範例輸出：

```
 xact_id | xact_id_undone | table_id
---------+----------------+----------
1344 |           1344 |   100192
1326 |           1326 |   100192
1551 |           1551 |   100192
(3 rows)
```

# STL\$1UNIQUE
<a name="r_STL_UNIQUE"></a>

分析在 SELECT 清單中使用 DISTINCT 函數時發生的執行步驟，或在 UNION 或 INTERSECT 查詢中複製或移除時發生的執行步驟。

所有使用者都可看見 STL\$1UNIQUE。超級使用者可以看見所有資料列；一般使用者只能看見自己的資料。如需詳細資訊，請參閱[系統資料表和檢視中資料的可見性](cm_chap_system-tables.md#c_visibility-of-data)。

**注意**  
STL\$1UNIQUE 僅包含在主佈建叢集上執行的查詢。但不包含在並行擴縮叢集上或無伺服器命名空間上執行的查詢。若要存取在主要叢集、並行擴縮叢集和無伺服器命名空間上執行的查詢說明計畫，建議您使用 SYS 監控檢視 [SYS\$1QUERY\$1DETAIL](SYS_QUERY_DETAIL.md)。SYS 監視檢視中的資料會格式化為更易於使用和理解。

## 資料表欄
<a name="r_STL_UNIQUE-table-columns"></a>

[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/redshift/latest/dg/r_STL_UNIQUE.html)

## 範例查詢
<a name="r_STL_UNIQUE-sample-queries"></a>

假設您執行下列查詢：

```
select distinct eventname
from event order by 1;
```

假設前一個查詢的 ID 為 6313，下列範例會顯示唯一步驟針對區段 0 與 1 中之每個配量所產生的資料列數目。

```
select query, slice, segment, step, datediff(msec, starttime, endtime) as msec, tasknum, rows 
from stl_unique where query = 6313
order by query desc, slice, segment, step;
```

```
 query | slice | segment | step | msec | tasknum | rows
-------+-------+---------+------+------+---------+------
  6313 |     0 |       0 |    2 |    0 |      22 |  550
  6313 |     0 |       1 |    1 |  256 |      20 |  145
  6313 |     1 |       0 |    2 |    1 |      23 |  540
  6313 |     1 |       1 |    1 |   42 |      21 |  127
  6313 |     2 |       0 |    2 |    1 |      22 |  540
  6313 |     2 |       1 |    1 |  255 |      20 |  158
  6313 |     3 |       0 |    2 |    1 |      23 |  542
  6313 |     3 |       1 |    1 |   38 |      21 |  146
(8 rows)
```

# STL\$1UNLOAD\$1LOG
<a name="r_STL_UNLOAD_LOG"></a>

記錄卸載操作的詳細資訊。

STL\$1UNLOAD\$1LOG 會針對 UNLOAD 陳述式所建立的每一個檔案記錄一個資料列。例如，若 UNLOAD 建立 12 個檔案，則 STL\$1UNLOAD\$1LOG 將包含 12 個對應資料列。

所有使用者都可看見 STL\$1UNLOAD\$1LOG。超級使用者可以看見所有資料列；一般使用者只能看見自己的資料。如需詳細資訊，請參閱[系統資料表和檢視中資料的可見性](cm_chap_system-tables.md#c_visibility-of-data)。

**注意**  
STL\$1UNLOAD\$1LOG 僅包含在主佈建叢集上執行的查詢。但不包含在並行擴縮叢集上或無伺服器命名空間上執行的查詢。若要存取在主要叢集、並行擴縮叢集和無伺服器命名空間上執行的查詢說明計畫，建議您使用 SYS 監控檢視 [SYS\$1UNLOAD\$1HISTORY](SYS_UNLOAD_HISTORY.md) 和 [SYS\$1UNLOAD\$1DETAIL](SYS_UNLOAD_DETAIL.md)。SYS 監視檢視中的資料會格式化為更易於使用和理解。

## 資料表欄
<a name="r_STL_UNLOAD_LOG-table-columns"></a>

[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/redshift/latest/dg/r_STL_UNLOAD_LOG.html)

## 範例查詢
<a name="r_STL_UNLOAD_LOG-sample-query"></a>

若要取得透過 UNLOAD 命令寫入 Amazon S3 的檔案清單，您可以在 UNLOAD 完成後呼叫 Amazon S3 清單操作。您也可以查詢 STL\$1UNLOAD\$1LOG。

下列查詢會傳回已由 UNLOAD 針對前一個完成的查詢建立之檔案的路徑名稱：

```
select query, substring(path,0,40) as path
from stl_unload_log
where query = pg_last_query_id() 
order by path;
```

此命令會傳回下列範例輸出：

```
 
 query |             path
-------+--------------------------------------
  2320 | s3://amzn-s3-demo-bucket/venue0000_part_00
  2320 | s3://amzn-s3-demo-bucket/venue0001_part_00
  2320 | s3://amzn-s3-demo-bucket/venue0002_part_00
  2320 | s3://amzn-s3-demo-bucket/venue0003_part_00
(4 rows)
```

# STL\$1USAGE\$1CONTROL
<a name="r_STL_USAGE_CONTROL"></a>

STL\$1USAGE\$1CONTROL 檢視包含達到用量限制時所記錄的資訊。如需使用限制的相關資訊，請參閱《Amazon Redshift 管理指南》**中的[管理用量限制](https://docs.aws.amazon.com/redshift/latest/mgmt/managing-cluster-usage-limits.html)。

只有超級使用者才能看到 STL\$1USAGE\$1CONTROL。如需詳細資訊，請參閱[系統資料表和檢視中資料的可見性](cm_chap_system-tables.md#c_visibility-of-data)。

## 資料表欄
<a name="r_STL_USAGE_CONTROL-table-columns"></a>

[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/redshift/latest/dg/r_STL_USAGE_CONTROL.html)

## 範例查詢
<a name="r_STL_USAGE_CONTROL-sample-queries"></a>

下列 SQL 範例會傳回一些達到用量限制時記錄的資訊。

```
select query, pid, eventtime, feature_type
from stl_usage_control
order by eventtime desc
limit 5;
```

# STL\$1USERLOG
<a name="r_STL_USERLOG"></a>

記錄資料庫使用者之下列變更的詳細資訊：
+ 建立使用者
+ 捨棄使用者
+ 更改使用者 (重新命名)
+ 更改使用者 (更改屬性)

只有超級使用者才能看到 STL\$1USERLOG。如需詳細資訊，請參閱[系統資料表和檢視中資料的可見性](cm_chap_system-tables.md#c_visibility-of-data)。

此資料表中的部份或所有資料也會在 SYS 監控檢視 [SYS\$1USERLOG](SYS_USERLOG.md) 中找到。SYS 監視檢視中的資料會格式化為更易於使用和理解。我們建議您使用 SYS 監控檢視進行查詢。

## 資料表欄
<a name="r_STL_USERLOG-table-columns"></a>

[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/redshift/latest/dg/r_STL_USERLOG.html)

## 範例查詢
<a name="r_STL_USERLOG-sample-queries"></a>

下列範例會執行四個使用者動作，然後查詢 STL\$1USERLOG 檢視。

```
create user userlog1 password 'Userlog1';
alter user userlog1 createdb createuser;
alter user userlog1 rename  to userlog2;
drop user userlog2;

select userid, username, oldusername, action, usecreatedb, usesuper from stl_userlog order by recordtime desc;
```

```
 userid |  username | oldusername |  action | usecreatedb | usesuper
--------+-----------+-------------+---------+-------------+----------
    108 | userlog2  |             | drop    |           1 |   1
    108 | userlog2  | userlog1    | rename  |           1 |   1
    108 | userlog1  |             | alter   |           1 |   1
    108 | userlog1  |             | create  |           0 |   0
 (4 rows)
```

# STL\$1UTILITYTEXT
<a name="r_STL_UTILITYTEXT"></a>

擷取在資料庫上執行之非 SELECT SQL 命令的文字。

查詢 STL\$1UTILITYTEXT 檢視，以擷取已在系統上執行之 SQL 陳述式的下列子集：
+ ABORT、BEGIN、COMMIT、END、ROLLBACK
+ ANALYZE
+ CALL
+ 取消
+ COMMENT
+ CREATE、ALTER、DROP DATABASE
+ CREATE、ALTER、DROP USER
+ EXPLAIN
+ GRANT、REVOKE
+ LOCK
+ RESET
+ SET
+ SHOW
+ TRUNCATE

另請參閱 [STL\$1DDLTEXT](r_STL_DDLTEXT.md)、[STL\$1QUERYTEXT](r_STL_QUERYTEXT.md) 和 [SVL\$1STATEMENTTEXT](r_SVL_STATEMENTTEXT.md)。

使用 STARTTIME 和 ENDTIME 資料欄，來了解已在特定時段記錄哪些陳述式。SQL 文字的長區塊會分成數行，一行 200 個字元；SEQUENCE 欄會識別屬於單一陳述式的文字片段。

STL\$1UTILITYTEXT 系統資料表支援具體化視觀表的 MANUAL 和 AUTO REFRESH 操作。若要在具體化視觀表上識別 AUTO REFRESH，請尋找欄 `label`。所有 AUTO REFRESH 查詢都有值為 `maintenance` 的標籤。

所有使用者都可看見 STL\$1UTILITYTEXT。超級使用者可以看見所有資料列；一般使用者只能看見自己的資料。如需詳細資訊，請參閱[系統資料表和檢視中資料的可見性](cm_chap_system-tables.md#c_visibility-of-data)。

此資料表中的部份或所有資料也會在 SYS 監控檢視 [SYS\$1QUERY\$1HISTORY](SYS_QUERY_HISTORY.md) 中找到。SYS 監視檢視中的資料會格式化為更易於使用和理解。我們建議您使用 SYS 監控檢視進行查詢。

## 資料表欄
<a name="r_STL_UTILITYTEXT-table-columns"></a>

[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/redshift/latest/dg/r_STL_UTILITYTEXT.html)

## 範例查詢
<a name="r_STL_UTILITYTEXT-sample-queries"></a>

下列查詢會傳回已在 2012 年 1 月 26 日執行之「公用程式」命令的文字。在此案例中，系統已執行部分 SET 命令和 SHOW ALL 命令：

```
select starttime, sequence, rtrim(text)
from stl_utilitytext
where starttime like '2012-01-26%'
order by starttime, sequence;

starttime          | sequence |              rtrim
---------------------------+-----+----------------------------------
2012-01-26 13:05:52.529235 |   0 | show all;
2012-01-26 13:20:31.660255 |   0 | SET query_group to ''
2012-01-26 13:20:54.956131 |   0 | SET query_group to 'soldunsold.sql'
...
```

### 重建儲存的 SQL
<a name="r_STL_UTILITYTEXT-reconstruct-sql"></a>

若要重建儲存在 STL\$1UTILITYTEXT `text` 資料欄中的 SQL，則需執行 SELECT 陳述式以從 `text` 資料欄的一或多個部分建立 SQL。請先以新的一行取代任意 (`\n`) 特殊字元，再執行重建的 SQL。下列 SELECT 陳述式顯示的結果會是 `query_statement` 欄中重建的 SQL 資料列。

```
SELECT LISTAGG(CASE WHEN LEN(RTRIM(text)) = 0 THEN text ELSE RTRIM(text) END) WITHIN GROUP (ORDER BY sequence) as query_statement 
FROM stl_utilitytext GROUP BY xid order by xid;
```

例如，下列查詢會將 query\$1group 設為一個零的字串。該查詢本身的長度超過 200 個字元，且會儲存在 STL\$1UTILITYTEXT 的多個部分中。

```
set query_group to '00000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000                  000000';
```

在本範例中，查詢會儲存在 STL\$1UTILITYTEXT `text` 資料欄的 2 個部分 (資料列) 中。

```
select query, sequence, text
from stl_utilitytext where query=pg_last_query_id() order by query desc, sequence limit 10;
```

```
         starttime          | sequence |                                                                                                   text                                                                                                   
----------------------------+----------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 2019-07-23 22:55:34.926198 |        0 | set query_group to '00000000000000000000000000000000000000000000000000000000000000000000000000000000\n0000000000000000000000000000000000000000000000000000000000000000000000000000000000
 2019-07-23 22:55:34.926198 |        1 |                   000000';
```

若要重建儲存在 STL\$1UTILITYTEXT 中的 SQL，請執行下列 SQL。

```
select LISTAGG(CASE WHEN LEN(RTRIM(text)) = 0 THEN text ELSE RTRIM(text) END, '') within group (order by sequence) AS query_statement 
from stl_utilitytext where query=pg_last_query_id();
```

若要在用戶端中使用產生的重建 SQL，請以新的一行取代任意 (`\n`) 特殊字元。

```
                                                                                                                                      query_statement                                                                                                                                       
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 set query_group to '00000000000000000000000000000000000000000000000000000000000000000000000000000000\n0000000000000000000000000000000000000000000000000000000000000000000000000000000000                  000000';
```

# STL\$1VACUUM
<a name="r_STL_VACUUM"></a>

顯示已清空之資料表的資料列和區塊統計資訊。

此檢視顯示每個清空操作啟動和完成時特有的資訊，並示範執行此操作的優點。如需執行此命令之需求的相關資訊，請參閱 [VACUUM](r_VACUUM_command.md) 命令說明。

只有超級使用者才能看到 STL\$1VACUUM。如需詳細資訊，請參閱[系統資料表和檢視中資料的可見性](cm_chap_system-tables.md#c_visibility-of-data)。

此資料表中的部份或所有資料也會在 SYS 監控檢視 [SYS\$1VACUUM\$1HISTORY](SYS_VACUUM_HISTORY.md) 中找到。SYS 監視檢視中的資料會格式化為更易於使用和理解。我們建議您使用 SYS 監控檢視進行查詢。

## 資料表欄
<a name="r_STL_VACUUM-table-columns"></a>

[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/redshift/latest/dg/r_STL_VACUUM.html)

## 範例查詢
<a name="r_STL_VACUUM-sample-queries"></a>

下列查詢報告資料表 108313 的清空統計資訊。在一系列插入和刪除之後已清空此資料表。

```
select xid, table_id, status, rows, sortedrows, blocks, eventtime,
                reclaimable_rows, reclaimable_space_mb
from stl_vacuum where table_id=108313 order by eventtime;

 xid   | table_id | status                  | rows | sortedrows | blocks |  eventtime           | reclaimable_rows | reclaimable_space_mb 
-------+----------+-------------------------+------+------------+--------+----------------------+------------------+----------------------
 14294 |   108313 | Started                 | 1950 |        408 |     28 |  2016-05-19 17:36:01 |              984 |                   17          
 14294 |   108313 | Finished                |  966 |        966 |     11 |  2016-05-19 18:26:13 |                0 |                    0 
 15126 |   108313 | Skipped(sorted>=95%)    |  966 |        966 |     11 |  2016-05-19 18:26:38 |                0 |                    0
```

在 VACUUM 開始時，資料表包含 1,950 列，儲存在 28 個 1 MB 區塊中。Amazon Redshift 估計，透過清空操作可以回收 984 個磁碟空間，即 17 個磁碟空間區塊。

在「已完成」狀態的列中，ROWS 欄顯示的值為 966，而 BLOCKS 欄的值從 28 下降為 11。清空回收了估計的磁碟空間量，清空操作完成後沒有剩餘可回收的列或空間。

在排序階段 (交易 15126) 中，清空能夠略過資料表，因為已依排序索引鍵順序插入資料列。

下列範例會在大型 INSERT 操作之後顯示 SALES 資料表 (此範例中的資料表 110116) 上 SORT ONLY 清空的統計資訊：

```
vacuum sort only sales;

select xid, table_id, status, rows, sortedrows, blocks, eventtime
from stl_vacuum order by xid, table_id, eventtime;

xid |table_id|     status      | rows  |sortedrows|blocks|     eventtime
----+--------+-----------------+-------+----------+------+--------------------
...
2925| 110116 |Started Sort Only|1379648|   172456 |  132 | 2011-02-24 16:25:21...
2925| 110116 |Finished         |1379648|  1379648 |  132 | 2011-02-24 16:26:28...
```

# STL\$1WINDOW
<a name="r_STL_WINDOW"></a>

分析執行視窗函數的查詢步驟。

所有使用者都可看見 STL\$1WINDOW。超級使用者可以看見所有資料列；一般使用者只能看見自己的資料。如需詳細資訊，請參閱[系統資料表和檢視中資料的可見性](cm_chap_system-tables.md#c_visibility-of-data)。

**注意**  
STL\$1WINDOW 僅包含在主佈建叢集上執行的查詢。但不包含在並行擴縮叢集上或無伺服器命名空間上執行的查詢。若要存取在主要叢集、並行擴縮叢集和無伺服器命名空間上執行的查詢說明計畫，建議您使用 SYS 監控檢視 [SYS\$1QUERY\$1DETAIL](SYS_QUERY_DETAIL.md)。SYS 監視檢視中的資料會格式化為更易於使用和理解。

## 資料表欄
<a name="r_STL_WINDOW-table-columns"></a>

[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/redshift/latest/dg/r_STL_WINDOW.html)

## 範例查詢
<a name="r_STL_WINDOW-sample-queries"></a>

下列範例傳回配量 0 和區段 3 的視窗函數結果。

```
select query, tasknum, rows, is_diskbased, workmem
from stl_window
where slice=0 and segment=3;
```

```
 query | tasknum | rows | is_diskbased | workmem
-------+---------+------+--------------+----------
 86326 |      36 | 1857 | f            | 95256616
   705 |      15 | 1857 | f            | 95256616
 86399 |      27 | 1857 | f            | 95256616
   649 |      10 |    0 | f            | 95256616
(4 rows)
```

# STL\$1WLM\$1ERROR
<a name="r_STL_WLM_ERROR"></a>

記錄所有發生的 WLM 相關錯誤。

所有使用者都可看見 STL\$1WLM\$1ERROR。超級使用者可以看見所有資料列；一般使用者只能看見自己的資料。如需詳細資訊，請參閱[系統資料表和檢視中資料的可見性](cm_chap_system-tables.md#c_visibility-of-data)。

## 資料表欄
<a name="r_STL_WLM_ERROR-table-columns"></a>

[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/redshift/latest/dg/r_STL_WLM_ERROR.html)

# STL\$1WLM\$1RULE\$1ACTION
<a name="r_STL_WLM_RULE_ACTION"></a>

記錄 WLM 查詢監控規則所產生之動作的詳細資訊，而此規則與使用者定義的查詢相關聯。如需詳細資訊，請參閱[WLM 查詢監控規則](cm-c-wlm-query-monitoring-rules.md)。

所有使用者都可看見 STL\$1WLM\$1RULE\$1ACTION。超級使用者可以看見所有資料列；一般使用者只能看見自己的資料。如需詳細資訊，請參閱[系統資料表和檢視中資料的可見性](cm_chap_system-tables.md#c_visibility-of-data)。

## 資料表欄
<a name="r_STL_WLM_RULE_ACTION-table-columns"></a>

[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/redshift/latest/dg/r_STL_WLM_RULE_ACTION.html)

## 範例查詢
<a name="r_STL_WLM_RULE_ACTION-sample-queries"></a>

下列範例尋找查詢監控規則已停止的查詢。

```
Select query, rule
from stl_wlm_rule_action 
where action = 'abort'
order by query;
```

# STL\$1WLM\$1QUERY
<a name="r_STL_WLM_QUERY"></a>

在 WLM 處理的服務類別中包含每個嘗試執行之查詢的記錄。

所有使用者都可看見 STL\$1WLM\$1QUERY。超級使用者可以看見所有資料列；一般使用者只能看見自己的資料。如需詳細資訊，請參閱[系統資料表和檢視中資料的可見性](cm_chap_system-tables.md#c_visibility-of-data)。

此資料表中的部份或所有資料也會在 SYS 監控檢視 [SYS\$1QUERY\$1HISTORY](SYS_QUERY_HISTORY.md) 中找到。SYS 監視檢視中的資料會格式化為更易於使用和理解。我們建議您使用 SYS 監控檢視進行查詢。

## 資料表欄
<a name="r_STL_WLM_QUERY-table-columns"></a>

[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/redshift/latest/dg/r_STL_WLM_QUERY.html)

## 範例查詢
<a name="r_STL_WLM_QUERY-sample-queries"></a>

 **檢視佇列和執行中的平均查詢時間** 

下列查詢顯示大於 4 之服務類別的目前組態。如需服務類別 ID 的清單，請參閱 [WLM 服務類別 ID](cm-c-wlm-system-tables-and-views.md#wlm-service-class-ids)。

下列查詢會傳回每個查詢花費在查詢佇列以及執行每個服務類別的平均時間 (以微秒為單位)。

```
select service_class as svc_class, count(*),
avg(datediff(microseconds, queue_start_time, queue_end_time)) as avg_queue_time,
avg(datediff(microseconds, exec_start_time, exec_end_time )) as avg_exec_time
from stl_wlm_query
where service_class > 4
group by service_class
order by service_class;
```

此查詢傳回下列範例輸出：

```
 svc_class | count | avg_queue_time | avg_exec_time
-----------+-------+----------------+---------------
         5 | 20103 |              0 |         80415
         5 |  3421 |          34015 |        234015
         6 |    42 |              0 |        944266
         7 |   196 |           6439 |       1364399
(4 rows)
```

 **檢視佇列和執行中的查詢時間上限** 

下列查詢會傳回每個查詢花費在任何查詢佇列以及執行每個服務類別的時間量上限 (以微秒為單位)。

```
select service_class as svc_class, count(*),
max(datediff(microseconds, queue_start_time, queue_end_time)) as max_queue_time,
max(datediff(microseconds, exec_start_time, exec_end_time )) as max_exec_time
from stl_wlm_query
where svc_class > 5  
group by service_class
order by service_class;
```

```
 svc_class | count | max_queue_time | max_exec_time
-----------+-------+----------------+---------------
         6 |    42 |              0 |       3775896
         7 |   197 |          37947 |      16379473
(4 rows)
```