MySQL export without –lock-tables

One of the difficulties with mysqldump is to deal with lock tables.

But there is an option in mysqldump we can use to change how to dump safely without locking all tables:

--single-transaction

This option sets the transaction isolation mode to REPEATABLE READ and sends a START TRANSACTION SQL statement to the server before dumping data. It is useful only with transactional tables such as InnoDB, because then it dumps the consistent state of the database at the time when START TRANSACTION was issued without blocking any applications.

When using this option, you should keep in mind that only InnoDB tables are dumped in a consistent state. For example, any MyISAM or MEMORY tables dumped while using this option may still change state.

While a --single-transaction dump is in process, to ensure a valid dump file (correct table contents and binary log coordinates), no other connection should use the following statements: ALTER TABLE, CREATE TABLE, DROP TABLE, RENAME TABLE, TRUNCATE TABLE. A consistent read is not isolated from those statements, so use of them on a table to be dumped can cause the SELECT that is performed by mysqldump to retrieve the table contents to obtain incorrect contents or fail.

The --single-transaction option and the --lock-tables option are mutually exclusive because LOCK TABLES causes any pending transactions to be committed implicitly.

To dump large tables, combine the --single-transaction option with the --quick option.

oracle block map

Script for oracle block map

Sometimes, in order to see fragmented tables in Oracle database, you need to check the block map in datafiles.

Here, I’m sharing with you a script for checking that 🙂

col segment_name format a30
col owner format a30
col segment_type format a30
col partition_name format a45
col segment_type format a30
select  file_id,
        block_id,
        block_id + blocks - 1   end_block,
        blocks,
        owner,
        segment_name,
        partition_name,
        segment_type
from dba_extents
where
        tablespace_name = 'SYSAUX'
union all
select  file_id,
        block_id,
        block_id + blocks - 1   end_block,
        blocks,
        'free'                  owner,
        'free'                  segment_name,
        null                    partition_name,
        null                    segment_type
from dba_free_space 
where tablespace_name = 'SYSAUX'
order by 1,2;