# Manage SQL Database Logs

Database Logs คือ ฟีเจอร์สำหรับการนำ logs ที่เกิดขึ้นใน SQL Database มาแสดงผลที่ Database Instance Detail เพื่อให้สามารถตรวจสอบการใช้งาน SQL Database ได้ภายใน NCS

ปัจจุบันรองรับการแสดงผล logs 2 ประเภท ของ SQL Database ดังนี้

* General Log
  * แสดง log เมื่อมีการ Query
  * แสดง log เมื่อมีการ Audit อื่น ๆ เช่น Create/Delete Database User, Create/Delete Database Schema เป็นต้น
* Slow Query Log แสดงการ Query ที่ใช้เวลานานกว่า 1 วินาที

## Prerequisite

* มี Database Instance ใน Project ([ขั้นตอนการสร้าง SQL Database Instance](/ncs-documents/database-as-a-service/sql-database/create-sql-database-instance.md))

### **สามารถดู Logs ได้ที่ tab: Logs ที่หน้า Database Instance Detail**

ส่วนประกอบต่าง ๆ ใน tab: Logs มีดังนี้

### 1. status ของ logs และ toggle เพื่อเปลี่ยน status

* logs มี status เป็น Disabled (toggle มี state เป็น off)

<figure><img src="/files/lblV7skodldtb7jIFtzh" alt=""><figcaption><p>Logs มีสถานะเป็น Disabled</p></figcaption></figure>

* logs มี status เป็น Enabled (toggle มี state เป็น on)

<figure><img src="/files/3ycDmgBj5Sc1b2ELLfwm" alt=""><figcaption><p>Logs มีสถานะเป็น Enabled</p></figcaption></figure>

{% hint style="info" %}
status เริ่มต้นหลังสั่งสร้าง Database Instance สำเร็จ เป็น Disabled หากต้องการเริ่มใช้งานจะต้องสั่ง [Enable Logs](/ncs-documents/database-as-a-service/sql-database/manage-sql-database-logs/enable-logs.md) ก่อน ถึงจะสามารถใช้งานได้
{% endhint %}

### 2. ตารางการแสดงผล Logs

แต่ละ column แสดงข้อมูลของ Logs แต่ละประเภท ดังนี้

* General Log
  * Time: เวลาที่ Logs เกิดขึ้น
  * Duration: ระยะเวลาของการ Query (หน่วย ms)
  * Message: รายละเอียดของ Logs

<figure><img src="/files/66n9QkLZT59PSOgIXp9S" alt=""><figcaption><p>ตัวอย่าง General Log</p></figcaption></figure>

* Slow Query Log
  * Time: เวลาที่ Logs เกิดขึ้น
  * Duration: ระยะเวลาของการ Query (หน่วย s)
  * User Information: ข้อมูลของ Database User ที่ทำให้เกิด Slow Query Log
  * Message: รายละเอียดของ Logs

<figure><img src="/files/W0LzosWweWOaUcHPzdGr" alt=""><figcaption><p>ตัวอย่าง Slow Query Log</p></figcaption></figure>

### 3. Pending Size

แสดง Size ของไฟล์ Logs ที่เกิดขึ้น แต่ยังไม่นำแสดงผลที่ NCS

<figure><img src="/files/wb829hDhV2onnx3j1P8M" alt=""><figcaption><p>ตัวอย่างค่า Pending Size</p></figcaption></figure>

{% hint style="info" %}
Logs ที่จะนำมาแสดงผลได้ หรือถูกนับอยู่ใน Pending Size จะเป็น Logs ที่เกิดในช่วงที่ status เป็น Enabled เท่านั้น
{% endhint %}

## คำสั่งที่ใช้จัดการ Database Logs มีดังต่อไปนี้

* [Enable Logs](/ncs-documents/database-as-a-service/sql-database/manage-sql-database-logs/enable-logs.md)
* [Disable Logs](/ncs-documents/database-as-a-service/sql-database/manage-sql-database-logs/disable-logs.md)
* [Refresh Logs](/ncs-documents/database-as-a-service/sql-database/manage-sql-database-logs/refresh-logs.md)
* [Load More Logs](/ncs-documents/database-as-a-service/sql-database/manage-sql-database-logs/load-more-logs.md)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs-epc.gitbook.io/ncs-documents/database-as-a-service/sql-database/manage-sql-database-logs.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
