Author Archives: James Coyle

View Table Sizes in MySQL/ MariaDB Databases

Get Social!

MySQL and MariaDB present a bunch of queryable objects that give you all sorts of insights into what’s happening with the database. 

The size of data stored in tabels is one such thing that can be easily queried directly in SQL, providing you have SELECT access to the information_schema. 

Create the two below views in a schema of your choice:

CREATE  OR REPLACE VIEW schema_size AS
SELECT   table_schema
,        round(SUM(((data_length + index_length) / 1024 / 1024)), 2) table_size_mb
FROM     information_schema.tables  
WHERE table_schema IN ('dv', 'da', 'hue')  
GROUP BY table_schema
ORDER BY table_size_mb DESC;

CREATE  OR REPLACE VIEW table_size AS
SELECT   table_schema
,        table_name 
,        round(SUM(((data_length + index_length) / 1024 / 1024)), 2) table_size_mb
FROM     information_schema.tables  
WHERE table_schema IN ('dv', 'da', 'hue')  
GROUP BY table_schema
,        table_name 
ORDER BY table_size_mb DESC;

See schema_size and table_size for more info.

You can now query each view to get the size, in megabytes, of a whole schema or individual table respectivley. 

SELECT * 
FROM   schema_size;

SELECT * 
FROM   table_size;
  • schema_size – displays the aggregated size of each schema in the database.
  • table_size – lists all tables in the database. You can add a filter to the table_schema column to limit the output.

MySQL/ MariaDB Table Size

Get Social!

Create a MySQL or MariaDB view to show the size of each table in the database:

See database size for more information.

CREATE  OR REPLACE VIEW table_size AS
SELECT   table_schema
,        table_name 
,        round(SUM(((data_length + index_length) / 1024 / 1024)), 2) table_size_mb
FROM     information_schema.tables  
WHERE table_schema IN ('dv', 'da', 'hue')  
GROUP BY table_schema
,        table_name 
ORDER BY table_size_mb DESC

MySQL/ MariaDB Schema Size

Get Social!

Create a MySQL or MariaDB view to show the aggregated size of each schema in the database:

See database size for more information.

CREATE  OR REPLACE VIEW schema_size AS
SELECT   table_schema
,        round(SUM(((data_length + index_length) / 1024 / 1024)), 2) table_size_mb
FROM     information_schema.tables  
WHERE table_schema IN ('dv', 'da', 'hue')  
GROUP BY table_schema
ORDER BY table_size_mb DESC

Docker images Filter Options

Get Social!

The below is an excerpt from docker.com listing the –filter options available for docker images.

danglingboolean – true or false – will show dangling images.
label
label=<key> or label=<key>=<value>
before
<image-name>[:<tag>]<image id> or <image@digest> – filter images created before given id or references
since
<image-name>[:<tag>]<image id> or <image@digest> – filter images created since given id or references
reference
(pattern of an image reference) – filter images whose reference matches the specified pattern

Docker ps Filter Options

Get Social!

The below is an excerpt from docker.com listing the –filter options available with docker ps.

idContainer’s ID
nameContainer’s name
labelAn arbitrary string representing either a key or a key-value pair. Expressed as <key> or <key>=<value>
exitedAn integer representing the container’s exit code. Only useful with --all.
statusOne of createdrestartingrunningremovingpausedexited, or dead
ancestorFilters containers which share a given image as an ancestor. Expressed as <image-name>[:<tag>],<image id>, or <image@digest>
before or sinceFilters containers created before or after a given container ID or name
volumeFilters running containers which have mounted a given volume or bind mount.
networkFilters running containers connected to a given network.
publish or exposeFilters containers which publish or expose a given port. Expressed as <port>[/<proto>] or <startport-endport>/[<proto>]
healthFilters containers based on their healthcheck status. One of startinghealthyunhealthy or none.
isolationWindows daemon only. One of defaultprocess, or hyperv.
is-taskFilters containers that are a “task” for a service. Boolean option (true or false)

Remove Docker Container Based On Regex

Get Social!

This simple one-liner will take a regular expression (regex) and remove any Docker containers matching the pattern based on the name field. You can change the name match to be any other field accepted by the –filter switch.

Run the following docker ps command and substitute NAMEHERE* with the pattern you’d like to match. Careful, this command will delete any containers it finds.

docker ps --filter name=NAMEHERE* -aq | xargs docker stop | xargs docker rm

You can also filter on various other keys, such as status and volume using exactly the same method. Just replace the –filter element with the key from the below table, and the expression you want to match. 

idContainer’s ID
nameContainer’s name
labelAn arbitrary string representing either a key or a key-value pair. Expressed as <key> or <key>=<value>
exitedAn integer representing the container’s exit code. Only useful with --all.
statusOne of createdrestartingrunningremovingpausedexited, or dead
ancestorFilters containers which share a given image as an ancestor. Expressed as <image-name>[:<tag>],<image id>, or <image@digest>
before or sinceFilters containers created before or after a given container ID or name
volumeFilters running containers which have mounted a given volume or bind mount.
networkFilters running containers connected to a given network.
publish or exposeFilters containers which publish or expose a given port. Expressed as <port>[/<proto>] or <startport-endport>/[<proto>]
healthFilters containers based on their healthcheck status. One of startinghealthyunhealthy or none.
isolationWindows daemon only. One of defaultprocess, or hyperv.
is-taskFilters containers that are a “task” for a service. Boolean option (true or false)

See Docker PS Filter Options.

You can also filter for multiple conditions by passing the –filter switch multiple times. For example, name=webserver and status=running would look like this:

docker ps --filter name=webserver --filter status=running -aq | xargs docker stop | xargs docker rm

Visit our advertisers

Quick Poll

Are you using Docker.io?

Visit our advertisers