MySQL performance_schema not working properly? - mysql

I have MySQL 5.6.19 community server running on my Ubuntu 14.04. Lately I have been trying to monitor MySQL server using performance_schema. Previously I used to do this by running SHOW FULL PROCESSLIST query every 5 second using a cronjob.
I configured performance_schema.setup_consumers table as follows.
mysql> use performance_schema;
mysql> select * from setup_consumers;
+--------------------------------+---------+
| NAME | ENABLED |
+--------------------------------+---------+
| events_stages_current | NO |
| events_stages_history | NO |
| events_stages_history_long | NO |
| events_statements_current | YES |
| events_statements_history | NO |
| events_statements_history_long | NO |
| events_waits_current | NO |
| events_waits_history | NO |
| events_waits_history_long | NO |
| global_instrumentation | YES |
| thread_instrumentation | YES |
| statements_digest | YES |
+--------------------------------+---------+
By default the events_statements_history is not enabled. I enabled it as follows.
mysql> update setup_consumers set enabled="YES" where name="events_statements_history";
Query OK, 1 row affected (0.01 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> select * from setup_consumers;
+--------------------------------+---------+
| NAME | ENABLED |
+--------------------------------+---------+
| events_stages_current | NO |
| events_stages_history | NO |
| events_stages_history_long | NO |
| events_statements_current | YES |
| events_statements_history | YES |
| events_statements_history_long | NO |
| events_waits_current | NO |
| events_waits_history | NO |
| events_waits_history_long | NO |
| global_instrumentation | YES |
| thread_instrumentation | YES |
| statements_digest | YES |
+--------------------------------+---------+
Now enabled, the events_statements_history table should now be able to capture queries but somehow it is not. Following is the result.
mysql> select count(sql_text) from events_statements_history;
+-----------------+
| count(sql_text) |
+-----------------+
| 0 |
+-----------------+
I do not understand as to why it is not logging in any queries?

The performance schema records data when three conditions are met:
The running thread is instrumented
The instrument currently executed is enabled
The consumers for the data to record are enabled
Threads
By default, every thread (1) is instrumented.
To check if threads are instrumented:
select THREAD_ID, NAME, PROCESSLIST_ID, PROCESSLIST_USER, PROCESSLIST_HOST, INSTRUMENTED from threads;
To change which threads are instrumented by default, use table setup_actors.
Instruments
By default, instruments for statements (aka, queries), are enabled (2).
To see which queries are not instrumented:
select * from setup_instruments where name like "statement/%" and enabled='NO';
To instrument all queries:
update setup_instruments set enabled="YES" where name like "statement/%";
Consumers
By default, only a few consumers are instrumented (3).
To see which consumers are instrumented, or to change this, use select / update on table setup_consumers.
This part seems fine per the question, so check part (1) and (2).

As a side-note, if there is nothing inside the setup_% tables then you might need to enable the performance schema,
https://dev.mysql.com/doc/refman/5.5/en/performance-schema-quick-start.html

Related

Can I create MySQL View with SHOW keywords?

I need to create view like
create view GetProcessList
as
show processlist
Is it possible?
Is it possible?
No you can only create a view base on a SELECT statement , not a SHOW statement. But if your question is really how you can access the processlist as if it were a table....then this is already available in the information_schema meta-database:
MariaDB [information_schema]> SELECT * FROM information_schema.PROCESSLIST;
+----+------+-----------+--------------------+---------+------+----------------------+----------------------------------------------+---------+-------+-----------+----------+-------------+---------------+----------+
| ID | USER | HOST | DB | COMMAND | TIME | STATE | INFO | TIME_MS | STAGE | MAX_STAGE | PROGRESS | MEMORY_USED | EXAMINED_ROWS | QUERY_ID |
+----+------+-----------+--------------------+---------+------+----------------------+----------------------------------------------+---------+-------+-----------+----------+-------------+---------------+----------+
| 42 | root | localhost | information_schema | Query | 0 | Filling schema table | SELECT * FROM information_schema.PROCESSLIST | 0.561 | 0 | 0 | 0.000 | 83104 | 0 | 204 |
+----+------+-----------+--------------------+---------+------+----------------------+----------------------------------------------+---------+-------+-----------+----------+-------------+---------------+----------+
1 row in set (0.00 sec)

MySQL "Waiting for table metadata lock" hangs on 1 particular table

I'm trying to add a column to a specific table. Every time I run the migration up or down a SLEEP command pops up and blocks everything. Much like many other people who have run into this problem, I kill the blocking process and everything works as expected.
Ex:MySql alter table hangs
I've tried running the migration against a different table and have no issues. Seems to be something specific with this particular table.
Where or what should I be looking for? Why would this issue occur so consistently?
Thanks.
mysql> show processlist;
+-----+------+-----------------+--------+---------+------+---------------------------------+----------------------------------------------+
| Id | User | Host | db | Command | Time | State | Info |
+-----+------+-----------------+--------+---------+------+---------------------------------+----------------------------------------------+
| 351 | root | localhost:54691 | database | Sleep | 25 | | NULL |
| 352 | root | localhost:54692 | NULL | Sleep | 54 | | NULL |
| 377 | root | localhost | database | Query | 0 | starting | show processlist |
| 381 | root | localhost:54858 | database | Query | 5 | Waiting for table metadata lock | ALTER TABLE company ADD COLUMN active |
| 382 | root | localhost:54860 | database | Sleep | 5 | | NULL |
+-----+------+-----------------+--------+---------+------+---------------------------------+----------------------------------------------+
5 rows in set (0.00 sec)
The offending process in this case was 382.
The answers to many other similar posts say to kill the SLEEP process and then "debug". My problem was related to a circular import issue in Python, not related to MySQL.

Mysql table does not accept any update request

I am using Server version: 5.6.27-log MySQL Community Server (GPL) and I have a problem with a table.
I tried to update some fields with a GUI software, but when I came back to the command line, the lines I tried to update where not updated.
I tried to see if the table was locked using SHOW OPEN TABLES as stated in various other questions. But my table does not appear to be locked:
+--------------------+-------------------------------------------------+--------+-------------+
| Database | Table | In_use | Name_locked |
+--------------------+-------------------------------------------------+--------+-------------+
| arcdev | SCHEDULED_COMMAND | 0 | 0 |
And as soon as I try to make an update like:
UPDATE SCHEDULED_COMMAND SET field = 1;
The server just keeps loading and nothing happen. I tried on other tables and everything worked just fine.
I also tried some DELETE requests and even a DROP TABLE and nothing work so far...
What am I missing?
Thank you for your precious help!
EDIT: Here is the result of the SHOW PROCESSLIST command while a request is hanging:
+--------+----------+---------------------------------------+-----------+---------+------+----------+-------------------------------+
| Id | User | Host | db | Command | Time | State | Info |
+--------+----------+---------------------------------------+-----------+---------+------+----------+-------------------------------+
| 282588 | rdsadmin | localhost:17966 | mysql | Sleep | 2 | | NULL |
| 534575 | arc | XXXXXX:49376 | arcdev | Sleep | 17 | | NULL |
| 534579 | arc | XXXXXX:49443 | arcdev | Query | 0 | init | SHOW PROCESSLIST |
| 534659 | arc | XXXXXX:49836 | arcdev | Query | 14 | updating | DELETE FROM SCHEDULED_COMMAND |
+--------+----------+---------------------------------------+-----------+---------+------+----------+-------------------------------+

How check which query taking time in processlist

I have been trying to check slow query in process-list but its showing null & time is huge. Is any other way to check slow queries without enable the logs.
| ID | USER | HOST | DB | COMMAND | TIME | STATE | INFO | TIME_MS | ROWS_SENT | ROWS_EXAMINED | ROWS_READ |
| 1149040 | test | 127.0.0.1:58759 | NULL | Sleep | 206 | | NULL | 206054 | 0 | 0 | 6447 |
Thanks
Use:
select * from information_schema.processlist where command!='sleep' and time>10;
This will return queries take more than 10 seconds and is not in sleep mode.
Null value indicates no query is being executed.

'events_statements_summary_by_digest table' is missing

In my MySQL 5.6.27 default installation the 'events_statements_summary_by_digest' table is missing in the 'performance_schema' database.
In fact, I think more tables are missing. Did I something wrong during the installation? How can I fix this?
use performance_schema;
show tables;
+----------------------------------------------+
| Tables_in_performance_schema |
+----------------------------------------------+
| cond_instances |
| events_waits_current |
| events_waits_history |
| events_waits_history_long |
| events_waits_summary_by_instance |
| events_waits_summary_by_thread_by_event_name |
| events_waits_summary_global_by_event_name |
| file_instances |
| file_summary_by_event_name |
| file_summary_by_instance |
| mutex_instances |
| performance_timers |
| rwlock_instances |
| setup_consumers |
| setup_instruments |
| setup_timers |
| threads |
+----------------------------------------------+
17 rows in set (0.00 sec)
The changelog for 5.6.9 says
"If you upgrade to this release of MySQL from an earlier version, you must run mysql_upgrade (and restart the server) to incorporate this change into the performance_schema database. (Bug #14075527)"
events_statements_summary_by_digest was added in 5.6.5.