---
title: "Broker: start, stop, status, access control and logs"
description: "Control CoraDB brokers and CAS processes: start, stop, status, ACLs, packet encryption, run-time parameters, SQL and access logs."
url: "https://www.coradb.ai/manual/admin/control_broker.html"
markdown_url: "https://www.coradb.ai/manual/markdown/admin/control_broker.md"
product: "CoraDB"
version: "1.0"
keywords: "coradb broker start, coradb broker status, cora_broker, cora_cas, broker acl, broker logs, sql log, cas error, broker_log_converter, broker_log_top"
---

# Broker: start, stop, status, access control and logs

A broker (**cora_broker**) accepts application connections and hands them to its CAS processes (**cora_cas**), which run the statements against the database servers. Brokers are configured in `coradb_broker.conf` (see [Broker configuration](https://www.coradb.ai/manual/admin/config_broker.html)) and controlled with `coradb broker`.


## Starting broker

Enter the command below to start the broker.

``` bash
$ coradb broker start
@ coradb broker start
++ coradb broker start: success
```

The following message is returned if the broker is already running.

``` bash
$ coradb broker start
@ coradb broker start
++ coradb broker is running.
```

## Stopping broker

Enter the command below to stop the broker.

``` bash
$ coradb broker stop
@ coradb broker stop
++ coradb broker stop: success
```

The following message is returned if the broker has stopped.

``` bash
$ coradb broker stop
@ coradb broker stop
++ coradb broker is not running.
```

## Restarting broker

Enter the command below to restart the whole brokers.

``` bash
$ coradb broker restart
```

## Checking broker status

The **coradb broker status** utility allows you to check the broker status such as number of completed jobs and the number of standby jobs by providing various options.

``` bash
coradb broker status [options] [expr]
```

- *expr*: A part of the broker name or "SERVICE=ON\|OFF"

Specifying *expr* performs that the status of specific brokers which include *expr* in their names is monitored; specifying no argument means that status of all brokers which are registered in the broker environment configuration file ( **coradb_broker.conf** ) is monitored.

If "SERVICE=ON" is specified on *expr*, only the status of working brokers is displayed; if "SERVICE=OFF" is specified, only the status of stopped brokers is displayed.

The following \[options\] are available with the **coradb broker status** utility. -b, -q, -c, -m, -S, -P and -f are options to define the information to print; -s, -l and -t are options to control printing. All of these are possible to use as combining each other.

**-b**

Displays the status information of a broker but does not display information on broker application server.

**-q**

Displays standby jobs in the job queue.

**-f**

Displays information of DB and host accessed by broker.

If it is used with the **-b** option, additional information on CAS is displayed. But SELECT, INSERT, UPDATE, DELETE, OTHERS items which shown on **-b** option are excluded.

If it is used with the **-P** option, STMT-POOL-RATIO is additionally printed. This item shows the ratio to use statements in the pool when you are using prepared statements.

**-l SECOND**

The **-l** option is only used with -f option together. It specifies accumulation period (unit: sec.) when displaying the number of application servers whose client status is Waiting or Busy. If it is omitted, the default value (1 second) is specified.

**-t**

Displays results in tty mode on the screen. The output can be redirected and used as a file.

**-s SECOND**

Regularly displays the status of broker based on specified period. It returns to a command prompt if q is entered.

If you do not specify options or arguments, the status of all brokers is displayed.

``` bash
$ coradb broker status
@ coradb broker status
% query_editor
----------------------------------------
ID   PID   QPS   LQS PSIZE STATUS
----------------------------------------
 1 28434     0     0 50144 IDLE
 2 28435     0     0 50144 IDLE
 3 28436     0     0 50144 IDLE
 4 28437     0     0 50140 IDLE
 5 28438     0     0 50144 IDLE

% broker1 OFF
```

- % query_editor: The broker name
- ID: Serial number of CAS within the broker
- PID: CAS process ID within the broker
- QPS: The number of queries processed per second
- LQS: The number of long-duration queries processed per second
- PSIZE: Size of CAS
- STATUS: The current status of CAS (BUSY, IDLE, CLIENT_WAIT, CLOSE_WAIT)
- % broker1 OFF: broker1's SERVICE parameter is set to OFF. So, broker1 is not started.

The following shows the detail status of broker for 5 seconds. The display will reset per 5 seconds as the new status information. To escape the display of the status, press \<Q\>.

``` bash
$ coradb broker status -b -s 5
@ coradb broker status

 NAME                    PID  PORT   AS   JQ    TPS    QPS   SELECT   INSERT   UPDATE   DELETE   OTHERS     LONG-T     LONG-Q   ERR-Q  UNIQUE-ERR-Q  #CONNECT  #REJECT
=======================================================================================================================================================================
* query_editor         13200 30000    5    0      0      0        0        0        0        0        0     0/60.0     0/60.0       0             0         0        0
* broker1              13269 33000    5    0     70     60       10       20       10       10       10     0/60.0     0/60.0      30            10       213        1
```

- NAME: The broker name
- PID: Process ID of the broker
- PORT: Port number of the broker
- AS: The number of CAS
- JQ: The number of standby jobs in the job queue
- TPS: The number of transactions processed per second (calculated only when the option is configured to "-b -s \<sec\>")
- QPS: The number of queries processed per second (calculated only when the option is configured to "-b -s \<sec\>")
- SELECT: The number of SELECT queries after staring of the broker. When there is an option of "-b -s \<sec\>", it is updated every time with the number of SELECTs which have been executed during the seconds specified by this option.
- INSERT: The number of INSERT queries after staring of the broker. When there is an option of "-b -s \<sec\>", it is updated every time with the number of INSERTs which have been executed during the seconds specified by this option.
- UPDATE: The number of UPDATE queries after staring of the broker. When there is an option of "-b -s \<sec\>", it is updated every time with the number of UPDATEs which have been executed during the seconds specified by this option.
- DELETE: The number of DELETE queries after staring of the broker. When there is an option of "-b -s \<sec\>", it is updated every time with the number of DELETEs which have been executed during the seconds specified by this option.
- OTHERS: The number of queries like CREATE and DROP except for SELECT, INSERT, UPDATE, DELETE. When there is an option of "-b -s \<sec\>", it is updated every time with the number of queries which have been executed during the seconds specified by this option.
- LONG-T: The number of transactions which exceed LONG_TRANSACTION_TIME. / the value of the LONG_TRANSACTION_TIME parameter. When there is an option of "-b -s \<sec\>", it is updated every time with the number of transactions which have been executed during the seconds specified by this option.
- LONG-Q: The number of queries which exceed LONG_QUERY_TIME. / the value of the LONG_QUERY_TIME parameter. When there is an option of "-b -s \<sec\>", it is updated every time with the number of queries which have been executed during the seconds specified by this option.
- ERR-Q: The number of queries with errors found. When there is an option of "-b -s \<sec\>", it is updated every time with the number of errors which have occurred during the seconds specified by this option.
- UNIQUE-ERR-Q: The number of queries with unique key errors found. When there is an option of "-b -s \<sec\>", it is updated every time with the number of unique key errors which have occurred during the seconds specified by this option.
- \#CONNECT: The number of connections that an application client accesses to CAS after starting the broker.
- \#REJECT: The count that an application client excluded from ACL IP list is rejected to access a CAS. Regarding ACL setting, see [Limiting broker access](https://www.coradb.ai/manual/admin/control_broker.html#limiting-broker-access).

The following checks the status of broker whose name includes broker1 and job status of a specific broker in the job queue with the **-q** option. If you do not specify broker1 as an argument, list of jobs in the job queue for all brokers is displayed.

``` bash
% coradb broker status -q broker1
@ coradb broker status
% broker1
----------------------------------------
ID   PID   QPS   LQS PSIZE STATUS
----------------------------------------
 1 28444     0     0 50144 IDLE
 2 28445     0     0 50140 IDLE
 3 28446     0     0 50144 IDLE
 4 28447     0     0 50144 IDLE
 5 28448     0     0 50144 IDLE
```

The following monitors the status of a broker whose name includes broker1 with the **-s** option. If you do not specify broker1 as an argument, monitoring status for all brokers is performed regularly. It returns to a command prompt if q is not entered.

``` bash
% coradb broker status -s 5 broker1
% broker1
----------------------------------------
ID   PID   QPS   LQS PSIZE STATUS
----------------------------------------
 1 28444     0     0 50144 IDLE
 2 28445     0     0 50140 IDLE
 3 28446     0     0 50144 IDLE
 4 28447     0     0 50144 IDLE
 5 28448     0     0 50144 IDLE
```

With the **-t** option, it display information of TPS and QPS to a file. To cancel displaying, press \<Ctrl+C\> to stop program.

``` bash
% coradb broker status -b -t -s 1 > log_file
```

The following views information of server/database accessed by broker, the last access times of applications, the IP addresses accessed to CAS and the versions of drivers etc. with the **-f** option.

``` bash
$ coradb broker status -f broker1
@ coradb broker status
% broker1 
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
ID   PID   QPS   LQS PSIZE STATUS         LAST ACCESS TIME      DB       HOST   LAST CONNECT TIME       CLIENT IP   CLIENT VERSION    SQL_LOG_MODE   TRANSACTION STIME  #CONNECT  #RESTART
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 1 26946     0     0 51168 IDLE         2011/11/16 16:23:42  e-commerce  localhost 2011/11/16 16:23:40      10.0.1.101     9.2.0.0062              NONE 2011/11/16 16:23:42         0         0
 2 26947     0     0 51172 IDLE         2011/11/16 16:23:34      -          -                   -          0.0.0.0                                -                   -         0         0
 3 26948     0     0 51172 IDLE         2011/11/16 16:23:34      -          -                   -          0.0.0.0                                -                   -         0         0
 4 26949     0     0 51172 IDLE         2011/11/16 16:23:34      -          -                   -          0.0.0.0                                -                   -         0         0
 5 26950     0     0 51172 IDLE         2011/11/16 16:23:34      -          -                   -          0.0.0.0                                -                   -         0         0
```

Meaning of each column in code above is as follows:

- LAST ACCESS TIME: Time when CAS runs or the latest time when an application client accesses CAS
- DB: Name of a database which CAS accesses most recently
- HOST: Name of a which CAS accesses most recently
- LAST CONNECT TIME: Most recent time when CAS accesses a database
- CLIENT IP: IP of an application clients currently being connected to an application server(CAS). If no application client is connected, 0.0.0.0 is displayed.
- CLIENT VERSION: A driver's version of an application client currently being connected to a CAS
- SQL_LOG_MODE: SQL logging mode of CAS. If the mode is same as the mode configured in the broker, "-" is displayed.
- TRANSACTION STIME: Transaction start time
- \#CONNECT: The number of connections that an application client accesses to CAS after starting the broker
- \#RESTART: The number of connection that CAS is re-running after starting the broker


Enter the command below with the **-b** and **-f** options to display AS(T W B Ns-W Ns-B) and CANCELED additionally.

``` text
// The -f option is added upon execution of broker status information. Configuring Ns-W and Ns-B are displayed as long as N seconds by using the -l.
% coradb broker status -b -f -l 2
@ coradb broker status
NAME          PID    PSIZE PORT  AS(T W B 2s-W 2s-B) JQ TPS QPS LONG-T LONG-Q  ERR-Q UNIQUE-ERR-Q CANCELED ACCESS_MODE SQL_LOG  #CONNECT #REJECT
================================================================================================================================================
query_editor 16784 56700 30000      5 0 0     0   0   0  16  29 0/60.0 0/60.0      1            1        0          RW     ALL         4       1
```

Meaning of added columns in code above is as follows:

- AS(T): Total number of CAS being executed
- AS(W): The number of CAS in the status of Waiting
- AS(B): The number of CAS in the status of Busy
- AS(Ns-W): The number of CAS that the client belongs to has been waited for N seconds.
- AS(Ns-B): The number of CAS that the client belongs to has been Busy for N seconds.
- CANCELED: The number of queries have cancelled by user interruption since the broker starts (if it is used with the **-l** *N* option, it specifies the number of accumulations for *N* seconds).


## Limiting broker access

To limit the client applications accessing the broker, set to **ON** for the **ACCESS\_ CONTROL** parameter in the **coradb_broker.conf** file, and enter a name of the file in which the users and the list of databases and IP addresses allowed to access the **ACCESS_CONTROL_FILE** parameter value are written. The default value of the **ACCESS_CONTROL** broker parameter is **OFF**. The **ACCESS_CONTROL** and **ACCESS_CONTROL_FILE** parameters must be written under \[broker\] which common parameters are specified.

The format of **ACCESS_CONTROL_FILE** is as follows:

``` text
[%<broker_name>]
<db_name>:<db_user>:<ip_list_file>
... 
```

- \<broker_name\>: A broker name. It is the one of broker names specified in **coradb_broker.conf** .
- \<db_name\>: A database name. If it is specified as \*, all databases are allowed to access the broker server.
- \<db_user\>: A database user ID. If it is specified as \*, all database user IDs are allowed to access the broker server.
- \<ip_list_file\>: Names of files in which the list of accessible IPs are stored. Several files such as ip_list_file1, ip_list_file2, ... can be specified by using a comma (,).

\[%\<*broker_name*\>\] and \<*db_name*\>:\<*db_user*\>:\<*ip_list_file*\> can be specified separately for each broker. A separated line can be specified for the same \<*db_name*\> and the same \<*db_user*\>. List of IPs can be written up to the maximum of 256 lines per \<*db_name*\>:\<*db_user*\> in a broker.

The format of the ip_list_file is as follows:

``` text
<ip_addr>
... 
```

- \<ip_addr\>: An IP address that is allowed to access the server. If the last digit of the address is specified as \*, all IP addresses in that rage are allowed to access the broker server.

If a value for **ACCESS_CONTROL** is set to ON and a value for **ACCESS_CONTROL_FILE** is not specified, the broker will only allow the access requests from the localhost.

If the analysis of **ACCESS_CONTROL_FILE** and ip_list_file fails when starting a broker, the broker will not be run.

``` text
# coradb_broker.conf
[broker]
MASTER_SHM_ID           =30001
ADMIN_LOG_FILE          =log/broker/coradb_broker.log
ACCESS_CONTROL   =ON
ACCESS_CONTROL_FILE     =/home1/coradb/access_file.txt
[%QUERY_EDITOR]
SERVICE                 =ON
BROKER_PORT             =30000
......
```

The following example shows the content of **ACCESS_CONTROL_FILE**. The \* symbol represents everything, and you can use it when you want to specify database names, database user IDs and IPs in the IP list file which are allowed to access the broker server.

``` text
[%QUERY_EDITOR]
dbname1:dbuser1:READIP.txt
dbname1:dbuser2:WRITEIP1.txt,WRITEIP2.txt
*:dba:READIP.txt
*:dba:WRITEIP1.txt
*:dba:WRITEIP2.txt

[%BROKER2]
dbname:dbuser:iplist2.txt

[%BROKER3]
dbname:dbuser:iplist2.txt

[%BROKER4]
dbname:dbuser:iplist2.txt
```

The brokers specified above are QUERY_EDITOR, BROKER2, BROKER3, and BROKER4.

The QUERY_EDITOR broker only allows the following application access requests.

- When a user logging into *dbname1* with a *dbuser1* account connects from IPs registered in READIP.txt
- When a user logging into *dbname1* with a *dbuser2* account connects from IPs registered in WRITEIP1.txt and WRITEIP2.txt
- When a user logging into every database with a **DBA** account connects from IPs registered in READIP.txt, WRITEIP1.txt, and WRITEIP2.txt

The following example shows how to specify the IPs allowed in ip_list_file.

``` text
192.168.1.25
192.168.*
10.*
*
```

The descriptions for the IPs specified in the example above are as follows:

- The first line setting allows an access from 192.168.1.25.
- The second line setting allows an access from all IPs starting with 192.168.
- The third line setting allows an access from all IPs starting with 10.
- The fourth line setting allows an access from all IPs.

For the broker which has already been running, you can modify the configuration file or check the currently applied status of configuration by using the following commands.

To configure databases, database user IDs and IPs allowed to access the broker and then apply the modified configuration to the server, use the following command.

``` bash
coradb broker acl reload [<BR_NAME>]
```

- \<BR_NAME\>: A broker name. If you specify this value, you can apply the changes only to specified brokers. If you omit it, you can apply the changes to all brokers.

To display the databases, database user IDs and IPs that are allowed to access the broker in running on the screen, use the following command.

``` bash
coradb broker acl status [<BR_NAME>]
```

- \<BR_NAME\>: A broker name. If you specify the value, you can display the specified broker configuration. If you omit it, you can display all broker configurations.

The below is an example of displaying results.

``` bash
$ coradb broker acl status 
ACCESS_CONTROL=ON 
ACCESS_CONTROL_FILE=access_file.txt 

[%broker1] 
e-commerce:dba:iplist1.txt 
       CLIENT IP LAST ACCESS TIME 
========================================== 
    10.20.129.11 
  10.113.153.144 2013-11-07 15:19:14 
  10.113.153.145 
  10.113.153.146 
         10.64.* 2013-11-07 15:20:50 

testdb:dba:iplist2.txt 
       CLIENT IP LAST ACCESS TIME 
========================================== 
               * 2013-11-08 10:10:12 
```

**Broker logs**

If you try to access brokers through IP addresses that are not allowed, the following logs will be created.

- ACCESS_LOG

``` text
1 192.10.10.10 - - 1288340944.198 1288340944.198 2010/10/29 17:29:04 ~ 2010/10/29 17:29:04 14942 - -1 db1 dba : rejected
```

- SQL LOG

``` text
10/29 10:28:57.591 (0) CLIENT IP 192.10.10.10 10/29 10:28:57.592 (0) connect db db1 user dba url jdbc:coradb:192.10.10.10:30000:db1::: - rejected
```

> **Note:**
> For details on how to limit an access to the database server, see [Limiting database server access](https://www.coradb.ai/manual/admin/control_server.html#limiting-database-server-access).


## Packet encryption

In an unencrypted communication environment, someone can monitor and interpret all the traffic between clients and a database server, and collected information could be used illegally. In order to access information in an unsafe communication environment while avoiding such an information leakage, data transmitted and received must be encrypted. CoraDB Broker can be configured in safe mode. In this case, all data transmitted and received between the database server and the client are encrypted.

CoraDB supports encrypted connections between clients and the server using TLS (Transport Layer Security) protocol. TLS provides data encryption mechanism as well as detecting data tampering, loss, hence ensures providing secure and trusted communication channel between clients and the server. CoraDB provides these TLS functions using [OpenSSL](https://www.openssl.org).

CoraDB Broker can be configured for encrypted mode (**SSL = ON**) or non-encrypted mode (**SSL = OFF**) using **SSL** parameter in **coradb_broker.conf**. A Broker must be restarted when the encryption parameter is changed. When a Broker is configured in encryption mode, clients such as **jdbc client** must connect in encryption mode, otherwise the connection to the broker will be rejected. The opposite is also true. That is, a connection request of clients using encryption mode to non-secure broker will be refused.

When SSL parameter is not specified in coradb_broker.conf, that broker will be started in non-encrypted mode (**'SSL = OFF'** is the default). The following is an example of setting the Broker **'query_editor'** in **encrypted mode** (coradb_broker.conf).

``` text
# coradb_broker.conf
[query_editor]
SERVICE                 =ON
SSL                     =ON
BROKER_PORT             =30000
....
```

**Certificate and private key**

In order to exchange an encrypted **symmetric session key** which will be used in a secure communication session, a public key and a private key are required in the server.

The public key used by the server is included in the certificate **'cas_ssl_cert.crt'**, and the private key is included in **'cas_ssl_cert.key'**. The certificate and private key are located in the **\$CORADB/conf** directory.

This certificate, **'self-signed'** certificate, was created with the OpenSSL command tool utility, and can be replaced with another certificate issued by a public **CA** (Certificate Authorities, for example **IdenTrust** or **DigiCert**) if desired. Or, existing certificate/private key can be replaced by generating new one using OpenSSL command utility as shown below.

``` bash
$ openssl genrsa -out my_cert.key 2048                                               # create 2048 bit size RSA private key
$ openssl req -new -key my_cert.key -out my_cert.csr                                 # create CSR (Certificate Signing Request)
$ openssl x509 -req -days 365 -in my_cert.csr -signkey my_cert.key -out my_cert.crt  # create a certificate valid for 1 year.
```

And replace **my_cert.key** and **my_cert.crt** with \$CORADB/conf/cas_ssl_cert.key and \$CORADB/conf/cas_ssl_cert.crt respectively.

## Managing a specific broker

Enter the code below to run *broker1* only. Note that *broker1* should have already been configured in the shared memory.

``` bash
% coradb broker on broker1
```

The following message is returned if *broker1* has not been configured in the shared memory.

``` bash
% coradb broker on broker1
Cannot open shared memory
```

Enter the code below to stop *broker1* only. Note that service pool of *broker1* can also be removed.

``` bash
% coradb broker off broker1
```

For example, once Read Only broker is connected to active servers.

Enter the code below to reset broker1.

``` bash
% coradb broker reset broker1
```

## Dynamically changing broker parameters

You can configure the parameters related to running the broker in the configuration file ( **coradb_broker.conf** ). You can also modify some broker parameters temporarily while the broker is running by using the **broker_changer** utility. For details, see [Broker configuration](https://www.coradb.ai/manual/admin/config_broker.html).

The syntax for the **broker_changer** utility, which is used to change broker parameters while the broker is running, is as follows. Enter the name of the currently running broker for the *broker_name* . The *parameters* can be used only for dynamically modifiable parameters. The *value* must be specified based on the parameter to be modified. You can specify the broker CAS identifier ( *cas_id* ) to apply the changes to the specific broker CAS.

*cas_id* is an ID to be output by **coradb broker status** command.

``` text
broker_changer <broker_name> [<cas_id>] <conf-name> <conf-value>
```

Enter the following to configure the **SQL_LOG** parameter to **ON** so that SQL logs can be written to the currently running broker. Such dynamic parameter change is effective only while the broker is running.

``` bash
% broker_changer query_editor sql_log on
OK
```

``` bash
% broker_changer broker_m access_mode ro
OK
```

> **Note:**
> If you want to control the service using coradb utilities on Windows Vista or the later versions of Window, you are recommended to open the command prompt window as an administrator. For details, see the notes of [CoraDB utilities](https://www.coradb.ai/manual/admin.html#utility-on-windows).


## Broker configuration information

**coradb broker info** dumps the currently "working" broker parameters' configuration information(coradb_broker.conf). broker parameters' information can be dynamically changed by **broker_changer** command; with **coradb broker info** command, you can see the configuration information of the working broker.

``` bash
% coradb broker info
```

As a reference, to see the configuration information of the currently "working" system(coradb.conf), use **coradb paramdump** *database_name* command. By **SET SYSTEM PARAMETERS** syntax, the configuration information of the system parameters can be changed dynamically; with **coradb broker info** command, you can see the configuration information of the system parameters.


## Broker logs

There are three types of logs that relate to starting the broker: access, error and SQL logs. Each log can be found in the log directory under the installation directory. You can change the directory where these logs are to be stored through **LOG_DIR** and **ERROR_LOG_DIR** parameters of the broker configuration file (**coradb_broker.conf**).

### Checking the access log

The access log file records information on the application client and is stored to **\$CORADB/log/broker/**`<broker_name>`**.access** file. If the **ACCESS_LOG** parameter is configured to **ON** in the broker configuration file, when the broker stops properly, the access log file is stored.

The maximum size of the ACCESS_LOG file can be specified through the ACCESS_LOG_MAX_SIZE parameter. When the ACCESS_LOG file is larger than the specified size, it is backed up in the name of broker_name.access.YYYYMMDDHHMISS, and the log is recorded in a new file (broker_name.access).

The record of denied access is recorded in broker_name.access.denied. It is backed up with the same rules as the ACCESS_LOG file.

The following example and description show an access log file created in the log directory:

``` text
1 192.168.56.4 2020/11/10 14:41:55 testdb dba NEW 6
```

- 1: ID assigned to the application server of the broker
- 192.168.56.4: IP address of the application client
- 2020/11/10 14:41:55: Time when the client's request processing started
- testdb: The name of the database that the client requested to connect to
- dba: The user name of the database that the client requested to connect to
- NEW: Connection type
  - NEW: New connection
  - OLD: Change client or reconnection of existing connection due to CAS restart
  - REJ: Connection denied (Recorded only in access.denied file)
- 6: session-id (session-id assigned by server)

### Checking the error log

The error log file records information on errors that occurred during the client's request processing and is stored to **\$CORADB/log/broker/error_log**`<broker_name>_<app_server_num>`**.err** file. For error codes and error messages, see [CAS error](https://www.coradb.ai/manual/admin/control_broker.html#cas-error).

The following example and description show an error log:

``` text
Time: 02/04/09 13:45:17.687 - SYNTAX ERROR *** ERROR CODE = -493, Tran = 1, EID = 38
Syntax: Unknown class "unknown_tbl". select * from unknown_tbl
```

- Time: 02/04/09 13:45:17.687: Time when the error occurred

- - SYNTAX ERROR: Type of error (e.g. SYNTAX ERROR, ERROR, etc.)

- \*\*\* ERROR CODE = -493: Error code

- Tran = 1: Transaction ID. -1 indicates that no transaction ID is assigned.

- EID = 38: Error ID. This ID is used to find the SQL log related to the server or client logs when an error occurs during SQL statement processing.

- Syntax ...: Error message (An ellipsis ( ... ) indicates omission.)

### Managing the SQL log

The SQL log file records SQL statements requested by the application client and is stored with the name of *\<broker_name\>\_\<app_server_num\>*. sql.log. The SQL log is generated in the log/broker/sql_log directory when the SQL_LOG parameter is set to ON. Note that the size of the SQL log file to be generated cannot exceed the value set for the SQL_LOG_MAX_SIZE parameter. CoraDB offers the **broker_log_top** and **coradb_replay** utilities to manage SQL logs. Each utility should be executed in a directory where the corresponding SQL log exists.

The following examples and descriptions show SQL log files:

``` text
13-06-11 15:07:39.282 (0) STATE idle
13-06-11 15:07:44.832 (0) CLIENT IP 192.168.10.100
13-06-11 15:07:44.835 (0) CLIENT VERSION 1.0.0.0248
13-06-11 15:07:44.835 (0) session id for connection 0
13-06-11 15:07:44.836 (0) connect db e-commerce user dba url jdbc:coradb:192.168.10.200:30000:e-commerce:dba:********: session id 12
13-06-11 15:07:44.836 (0) DEFAULT isolation_level 4, lock_timeout -1
13-06-11 15:07:44.840 (0) end_tran COMMIT
13-06-11 15:07:44.841 (0) end_tran 0 time 0.000
13-06-11 15:07:44.841 (0) *** elapsed time 0.004

13-06-11 15:07:44.844 (0) check_cas 0
13-06-11 15:07:44.848 (0) set_db_parameter lock_timeout 1000
13-06-11 15:09:36.299 (0) check_cas 0
13-06-11 15:09:36.303 (0) get_db_parameter isolation_level 4
13-06-11 15:09:36.375 (1) prepare 0 CREATE TABLE unique_tbl (a INT PRIMARY key);
13-06-11 15:09:36.376 (1) prepare srv_h_id 1
13-06-11 15:09:36.419 (1) set query timeout to 0 (no limit)
13-06-11 15:09:36.419 (1) execute srv_h_id 1 CREATE TABLE unique_tbl (a INT PRIMARY key);
13-06-11 15:09:38.247 (1) execute 0 tuple 0 time 1.827
13-06-11 15:09:38.247 (0) auto_commit
13-06-11 15:09:38.344 (0) auto_commit 0
13-06-11 15:09:38.344 (0) *** elapsed time 1.968

13-06-11 15:09:54.481 (0) get_db_parameter isolation_level 4
13-06-11 15:09:54.484 (0) close_req_handle srv_h_id 1
13-06-11 15:09:54.484 (2) prepare 0 INSERT INTO unique_tbl VALUES (1);
13-06-11 15:09:54.485 (2) prepare srv_h_id 1
13-06-11 15:09:54.488 (2) set query timeout to 0 (no limit)
13-06-11 15:09:54.488 (2) execute srv_h_id 1 INSERT INTO unique_tbl VALUES (1);
13-06-11 15:09:54.488 (2) execute 0 tuple 1 time 0.001
13-06-11 15:09:54.488 (0) auto_commit
13-06-11 15:09:54.505 (0) auto_commit 0
13-06-11 15:09:54.505 (0) *** elapsed time 0.021

...

13-06-11 15:19:04.593 (0) get_db_parameter isolation_level 4
13-06-11 15:19:04.597 (0) close_req_handle srv_h_id 2
13-06-11 15:19:04.597 (7) prepare 0 SELECT * FROM unique_tbl  WHERE ROWNUM BETWEEN 1 AND 5000;
13-06-11 15:19:04.598 (7) prepare srv_h_id 2 (PC)
13-06-11 15:19:04.602 (7) set query timeout to 0 (no limit)
13-06-11 15:19:04.602 (7) execute srv_h_id 2 SELECT * FROM unique_tbl  WHERE ROWNUM BETWEEN 1 AND 5000;
13-06-11 15:19:04.602 (7) execute 0 tuple 1 time 0.001
13-06-11 15:19:04.607 (0) end_tran COMMIT
13-06-11 15:19:04.607 (0) end_tran 0 time 0.000
13-06-11 15:19:04.607 (0) *** elapsed time 0.009
```

- 13-06-11 15:07:39.282: Time when the application sent the request
- (1): Sequence number of the SQL statement group. If prepared statement pooling is used, it is uniquely assigned to each SQL statement in the file.
- CLIENT IP: An IP of an application client
- CLIENT VERSION: A driver's version of an application client
- Prepare 0: Whether or not it is a prepared statement
- Prepare srv_h_id 1: Prepares the SQL statement as srv_h_id 1.
- (PC): It is displayed if the data in the plan cache is used.
- Execute 0 tuple 1 time 0.001: One row is executed. The time spent is 0.001 seconds.
- auto_commit/auto_rollback: Automatically committed or rolled back. The second auto_commit/auto_rollback is an error code. 0 indicates that the transaction has been completed without an error.


#### broker_log_top

The **broker_log_top** utility analyzes the SQL logs which are generated for a specific period. As a result, the information of SQL statements and time execution are displayed in files by order of the longest execution time; the results of SQL statements are stored in **log.top.q** and those of execution time are stored in **log.top.res**, respectively.

The **broker_log_top** utility is useful to analyze a long running query. The syntax is as follows:

``` text
broker_log_top [options] sql_log_file_list
```

- *sql_log_file_list*: names of log files to analyze.

The following is \[options\] used on **broker_log_top**.

**-t**

The result is displayed in transaction unit.

**-F DATETIME**

Specifies the execution start date and time of the SQL statements to be analyzed. The input format is YY-MM-DD\[ hh\[:mm\[:ss\[.msec\]\]\]\], and the part enclosed by \[\] can be omitted. If you omit the value, it is regarded as that 0 is input for hh, mm, ss and msec.

**-T DATETIME**

Specifies the execution end date and time of the SQL statements to be analyzed. The input format is the same with the *DATE* in the **-F** options.

All logs are displayed by SQL statement if any option is not specified.

The following sets the search range to milliseconds

``` text
broker_log_top -F "13-01-19 15:00:25.000" -T "13-01-19 15:15:25.180" log1.log
```

The part where the time format is omitted is set to 0 by default. This means that -F "13-01-19 00:00:00.000" -T "13-01-20 00:00:00.000" is input.

``` text
broker_log_top -F "13-01-19" -T "13-01-20" log1.log
```

The following logs are the results of executing the broker_log_top utility; logs are generated from Nov. 11th to Nov. 12th 2013, and it is displayed in the order of the longest execution of SQL statements. Each month and day are separated by a hyphen (-) when specifying period. Note that "\*.sql.log" is not recognized so the SQL logs should be separated by a white space on Windows.

``` sql
--Execution broker_log_top on Linux
% broker_log_top -F "13-11-11" -T "13-11-12" -t *.sql.log

query_editor_1.sql.log
query_editor_2.sql.log
query_editor_3.sql.log
query_editor_4.sql.log
query_editor_5.sql.log

--Executing broker_log_top on Windows
% broker_log_top -F "13-11-11" -T "13-11-12" -t query_editor_1.sql.log query_editor_2.sql.log query_editor_3.sql.log query_editor_4.sql.log query_editor_5.sql.log
```

The **log.top.q** and **log.top.res** files are generated in the same directory where the analyzed logs are stored when executing the example above; In the **log.top.q** file, you can see each SQL statement, and its line number. In the **log.top.res** file, you can see the minimum execution time, the maximum execution time, the average execution time, and the number of execution queries for each SQL statement.

``` sql
--log.top.q file
[Q1]-------------------------------------------
broker1_6.sql.log:137734
13-11-11 18:17:59.396 (27754) execute_all srv_h_id 34 select a.int_col, b.var_col from dml_v_view_6 a, dml_v_view_6 b, dml_v_view_6 c , dml_v_view_6 d, dml_v_view_6 e where a.int_col=b.int_col and b.int_col=c.int_col and c.int_col=d.int_col and d.int_col=e.int_col order by 1,2;
13-11-11 18:18:58.378 (27754) execute_all 0 tuple 497664 time 58.982
.
.
[Q4]-------------------------------------------
broker1_100.sql.log:142068
13-11-11 18:12:38.387 (27268) execute_all srv_h_id 798 drop table list_test;
13-11-11 18:13:08.856 (27268) execute_all 0 tuple 0 time 30.469

--log.top.res file

              max       min        avg   cnt(err)
-----------------------------------------------------
[Q1]        58.982    30.371    44.676    2 (0)
[Q2]        49.556    24.023    32.688    6 (0)
[Q3]        35.548    25.650    30.599    2 (0)
[Q4]        30.469     0.001     0.103 1050 (0)
```


#### coradb_replay

**coradb_replay** utility replays the SQL log in the broker and outputs the results sorted in order from the large difference(from the slower query than the existing one) by comparing the difference in the execution time of playback and the existing execution time.

This utility plays back the queries that are logged in the SQL log, but does not execute the queries to change the data. If any options are not given, only SELECT queries are run; if **-r** option is given, it changes the UPDATE and DELETE queries into SELECT queries and runs them.

``` text
coradb_replay -I <broker_host> -P <broker_port> -d <db_name> [options] <sql_log_file> <output_file> 
```

- *broker_host*: IP address or host name of the CoraDB broker
- *broker_port*: Port number of the CoraDB broker
- *db_name*: The name of database to run the query
- *sql_log_file*: SQL log file of the CoraDB broker(\$CORADB/log/broker/sql_log/\*.log, \*.log.bak)
- *output_file*: File name to save the execution result

The following is \[options\] used in **coradb_replay**.

**-u DB_USER**

Specifies the DB account(default: public).

**-p DB_PASSWORD**

Specifies database password

**-r**

Changes UPDATE and DELETE queries into SELECT queries

**-h SECOND**

Specifies the term to wait between queries to run(default: 0.01 sec)

**-D SECOND**

The queries are output to *output_file* only when the specified term is bigger than (replayed execution time - previous execution time)(default: 0.01 sec).

**-F DATETIME**

Specifies the execution start date and time of the SQL statements to be replayed. The input format is YY\[-MM\[-DD\[ hh\[:mm\[:ss\[.msec\]\]\]\]\]\], and the part enclosed by \[\] can be omitted. If you omit the value, it is regarded as that 01 is input for MM and DD, and 0 is input for hh, mm, ss and msec.

**-T DATETIME**

Specifies the execution end date and time of the SQL statements to be replayed. The input format is the same with the *DATE* in the **-F** options.

``` bash
$ coradb_replay -I testhost -P 33000 -d testdb -u dba -r testdb_1_11_1.sql.log.bak output.txt 
```

If you run the above command, the summary of execution result is displayed on the console.

``` sql
------------------- Result Summary -------------------------- 
* Total queries : 153103 
* Skipped queries (see skip.sql) : 5127 
* Error queries (see replay.err) : 30 
* Slow queries (time diff > 0.000 secs) : 89987 
* Max execution time diff : 0.016 
* Avg execution time diff : -0.001 

coradb_replay run time : 245.308417 sec 
```

- Total queries: Number of total queries within the specified date and time. They include DDL and DML
- Skipped queries: Number of queries which cannot be changed from UPDATE/DELETE into SELECT when **-r** option is specified. These queries are saved into skip.sql
- Slow queries: Number of queries of which execution time difference is bigger than the specified value by **-D** option(the replayed execution time is slower than the previous execution time plus the specified value). If you omit the **-D** option, this option value is specified as 0.01 second
- Max execution time diff: The biggest value among the differences of the execution time(unit: sec)
- Avg execution time diff: Average value of the differences of the execution time(unit: sec)
- coradb_replay run time: Execution time of this utility

"Skipped queries" are the cases which query-transform from UPDATE/DELETE to SELECT is impossible by the internal reason; the queries which are written to skip.sql are needed to check separately.

Also, you should consider that the execution time of the transformed queries does not include the data modification time.

In the *output.txt* file, SQLs that the replayed SQL execution time is slower than the SQL execution time in SQL log are written. That is, {(the replayed SQL execution time) - {(the execution time in SQL log) + (the specified time by **-D** option)} is sorted in descending order. Because **-r** option is used, UPDATE/DELETE is rewritten into SELECT and run.

``` text
EXEC TIME (REPLAY / SQL_LOG / DIFF): 0.003 / 0.001 / 0.002 
SQL: UPDATE NDV_QUOTA_INFO SET last_mod_date = now() , used_quota = ( SELECT IFNULL(sum(file_size),0) FROM NDV_RECYCLED_FILE_INFO WHERE user_id = ? ) + ( SELECT IFNULL(sum(file_size),0) FROM NDV_FILE_INFO WHERE user_id = ? ) WHERE user_id = ? /* SQL : NDVMUpdResetUsedQuota */ 
REWRITE SQL: select NDV_QUOTA_INFO, class NDV_QUOTA_INFO, cast( SYS_DATETIME as datetime), cast((select ifnull(sum(NDV_RECYCLED_FILE_INFO.file_size), 0) from NDV_RECYCLED_FILE_INFO NDV_RECYCLED_FILE_INFO where (NDV_RECYCLED_FILE_INFO.user_id= ?:0 ))+(select ifnull(sum(NDV_FILE_INFO.file_size), 0) from NDV_FILE_INFO NDV_FILE_INFO where (NDV_FILE_INFO.user_id= ?:1 )) as bigint) from NDV_QUOTA_INFO NDV_QUOTA_INFO where (NDV_QUOTA_INFO.user_id= ?:2 ) 
BIND 1: 'babaemo' 
BIND 2: 'babaemo' 
BIND 3: 'babaemo' 
```

- EXEC TIME: (replay time / execution time in the SQL log / difference between the two execution times)
- SQL: The original SQL which exists in the SQL log of the broker
- REWRITE SQL: Transformed SELECT queries from UPDATE/DELETE queries by **-r** option.


## CAS error

CAS error is an error which occurs in broker application server(CAS), and it can happen on all applications which access to CAS with drivers.

Below shows the CAS error code table. CCI and JDBC's error messages can be different each other on the same CAS error code. If there is only one message, they are the same, but if there are two messages, then the first one is CCI error message and the second one is JDBC error message.

| Error code name(error number) | Error message (CCI / JDBC) | Note |
|---|---|---|
| CAS_ER_INTERNAL(-10001) |  |  |
| CAS_ER_NO_MORE_MEMORY(-10002) | Memory allocation error |  |
| CAS_ER_COMMUNICATION(-10003) | Cannot receive data from client / Communication error |  |
| CAS_ER_ARGS(-10004) | Invalid argument |  |
| CAS_ER_TRAN_TYPE(-10005) | Invalid transaction type argument / Unknown transaction type |  |
| CAS_ER_SRV_HANDLE(-10006) | Server handle not found / Internal server error |  |
| CAS_ER_NUM_BIND(-10007) | Invalid parameter binding value argument / Parameter binding error | The number of data to be bound does not match with the number of data to be transferred. |
| CAS_ER_UNKNOWN_U_TYPE(-10008) | Invalid T_CCI_U_TYPE value / Parameter binding error |  |
| CAS_ER_DB_VALUE(-10009) | Cannot make DB_VALUE |  |
| CAS_ER_TYPE_CONVERSION(-10010) | Type conversion error |  |
| CAS_ER_PARAM_NAME(-10011) | Invalid T_CCI_DB_PARAM value / Invalid database parameter name | The name of the system parameter is not valid. |
| CAS_ER_NO_MORE_DATA(-10012) | Invalid cursor position / No more data |  |
| CAS_ER_OBJECT(-10013) | Invalid oid / Object is not valid |  |
| CAS_ER_OPEN_FILE(-10014) | Cannot open file / File open error |  |
| CAS_ER_SCHEMA_TYPE(-10015) | Invalid T_CCI_SCH_TYPE value / Invalid schema type |  |
| CAS_ER_VERSION(-10016) | Version mismatch | The DB server version does not compatible with the client (CAS) version. |
| CAS_ER_FREE_SERVER(-10017) | Cannot process the request. Try again later | The CAS which handles connection request of applications cannot be assigned. |
| CAS_ER_NOT_AUTHORIZED_CLIENT(-10018) | Authorization error | Access is denied. |
| CAS_ER_QUERY_CANCEL(-10019) | Cannot cancel the query |  |
| CAS_ER_NOT_COLLECTION(-10020) | The attribute domain must be the set type |  |
| CAS_ER_COLLECTION_DOMAIN(-10021) | Heterogeneous set is not supported / The domain of a set must be the same data type |  |
| CAS_ER_NO_MORE_RESULT_SET(-10022) | No More Result |  |
| CAS_ER_INVALID_CALL_STMT(-10023) | Illegal CALL statement |  |
| CAS_ER_STMT_POOLING(-10024) | Invalid plan |  |
| CAS_ER_DBSERVER_DISCONNECTED(-10025) | Cannot communicate with DB Server |  |
| CAS_ER_MAX_PREPARED_STMT_COUNT_EXCEEDED(-10026) | Cannot prepare more than MAX_PREPARED_STMT_COUNT statements |  |
| CAS_ER_HOLDABLE_NOT_ALLOWED(-10027) | Holdable results may not be updatable or sensitive |  |
| CAS_ER_HOLDABLE_NOT_ALLOWED_KEEP_CON_OFF(-10028) | Holdable results are not allowed while KEEP_CONNECTION is off |  |
| CAS_ER_NOT_IMPLEMENTED(-10100) | None / Attempt to use a not supported service |  |
| CAS_ER_SSL_TYPE_NOT_ALLOWED(-10103) | None / The requested SSL mode is not permitted |  |
| CAS_ER_IS(-10200) | None / Authentication failure |  |
