1.对一个表执行ddl(新增字段)会不会阻塞表,影响读写?

在一次项目升级之前需要执行一个新增字段的脚本(alter table...),表的数据量是260多万,执行时间是72秒,感觉略长,不知道会不会影响项目对数据库的操作,故连百度带问一番,得出一些结果。

结论是:执行alter table...会影响读写

2.MySQL官方文档alter table的解释

ALTER TABLE operations that use the COPY algorithm wait for other operations that are modifying the table to complete. After alterations are applied to the table copy, data is copied over, the original table is deleted, and the table copy is renamed to the name of the original table. While the ALTER TABLE operation executes, the original table is readable by other sessions(读,不阻塞) (with the exception noted shortly). Updates and writes to the table started after the ALTER TABLE operation begins are stalled until the new table is ready(更新|写入阻塞), then are automatically redirected to the new table. The temporary copy of the table is created in the database directory of the original table unless it is a RENAME TO operation that moves the table to a database that resides in a different directory.

The exception referred to earlier is that ALTER TABLE blocks reads (not just writes)(读写都会阻塞,当数据库操作.frm文件时) at the point where it is ready to install a new version of the table .frm file, discard the old file, and clear outdated table structures from the table and table definition caches. At this point, it must acquire an exclusive lock. To do so, it waits for current readers to finish, and blocks new reads and writes.

3.总结

肯定会影响写入的,读取会有一段时间的影响,最后决定在升级项目,停服时执行alter table...,这样不会影响写入;

还是要看官方文档,别自己猜。

关于ddl(新增字段)对数据库锁表|读写操作的影响_资料的更多相关文章

  1. informix 数据库锁表分析和解决方法

    一.前言 在联机事务处理(OLTP)的数据库应用系统中,多用户.多任务的并发性是系统最重要的技术指标之一.为了提高并发性,目前大部分RDBMS都采用加锁技术.然而由于现实环境的复杂性,使用加锁技术又不 ...

  2. oracle数据库锁表,什么SQL引起了锁表?ORACLE解锁的方法

    --查询数据库锁表记录 select sess.sid, sess.serial#, lo.oracle_username, lo.os_user_name, ao.object_name, lo.l ...

  3. MySQL基础学习——SQL对数据库进行操作、对数据库的表进行操作

    1.SQL对数据库进行操作: 创建数据库: 语法: create database 数据库名称 [character set 字符集 collate 字符集校对规则];字符集校对规则即所用字符集的数据 ...

  4. Mysql新增字段到大数据表导致锁表

    昨天晚上7点左右,对一张表进行加字段,大概200多万条记录,字段90多个的大表,结果造成mysql锁表,进而导致服务不可用.执行语句如下: ALTER TABLE `sc_stockout_order ...

  5. 解决mySQL数据库锁表问题。

    先用这条命令查询数据库阻塞的进程 SELECT * FROM information_schema.innodb_trx 找到后在根据下图这个字段:try_mysql_thread_id 作为这条数据 ...

  6. Oracle数据库锁表及解锁进程

    下午代码迁移,更新数据库记录时for update语句无法执行,数据库被锁,KILL掉几个进程搞定. Oracle数据库操作中,我们有时会用到锁表查询以及解锁和kill进程等操作,那么这些操作是怎么实 ...

  7. oracle数据库锁表

    在团队开发一个项目的时候,避免不了两个或两个以上的人同时操作某一数据库中的同一张表,这时候,如果一个用户没有提交事务,或者忘记提交事务,那么其他用户就不能对这张表进行操作了,这是很烦人的事情,下面是查 ...

  8. Oracle数据库锁表查询

    --查看数据库最大连接数 select value from v$parameter where name = 'processes'; --更改数据库连接数 alter system scope = ...

  9. Oracle数据库锁表的查询方法以及解锁的方法

    1,锁表语句简单查询方法   select t2.username,t2.sid,t2.serial#,t2.logon_time from v$locked_object t1,v$session ...

随机推荐

  1. c/c++ 继承与多态 静态调用与动态调用

    静态调用,与动态调用. 动态调用条件:必须用父类的引用或者指针,并且调用的必须是虚方法. #include <iostream> class Base{ public: virtual i ...

  2. 取消导航栏navigationBar的半透明/毛玻璃效果

    iOS 7.0以上的系统,导航栏默认有毛玻璃效果,遮住了颜色 原因是7.0以上的系统,导航栏默认有毛玻璃效果,遮住了颜色,取消掉这个效果就行了. if( ([[[UIDevice currentDev ...

  3. 列表、enumerate()函数,以及查看数据类型所有的内置方法

    随便看看 """ forList(): 测试list和enumerate()函数 examineFun(): 查看数据类型所有的内置方法 ""&quo ...

  4. RH2288V3服务器 硬件安装以及更换硬件

    滑道类型:L型滑道.可伸缩滑道.报轨 L型滑道:只适用于华为机柜. 准备工具:防静电带或者防静电手套.螺丝刀.浮动螺母安装条. 安装服务器步骤: 1.安装L型滑道   2.安装浮动螺母  3.安装服务 ...

  5. 什么是tomcat集群?

    什么是tomcat集群? 利用nginx对请求进行分流,将请求分配给不同的tomcat去处理,减少每个tomcat的负载量,提高服务器的响应速度. 目标 实现高性能负载均衡的tomcat集群. 工具 ...

  6. 简单用数组模拟顺序栈(c++)

    **栈是一种操作受限制的线性表,太多官方的话我也不说了,我们都知道栈元素是先进后出的,它有两种存储结构,分别是顺序存储结构和链式存储结构. **今天我先记一下顺序存储结构,后面我会加上链式存储结构的. ...

  7. SpringBoot四大神器之Actuator

    介绍 Spring Boot有四大神器,分别是auto-configuration.starters.cli.actuator,本文主要讲actuator.actuator是spring boot提供 ...

  8. apt-get 详解&&配置阿里源

    配置apt-get的下载源 1.复制原文件备份 sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak 2.编辑源列表文件 sudo vim / ...

  9. InvalidOperationException: Unable to resolve service for type 'Microsoft.AspNetCore.Identity.UserManager`1[Microsoft.AspNetCore.Identity.IdentityUser]'

    在新建asp.net core 应用后, 添加了自定义的ApplicationDbContext 和ApplicationUser ,并添加了Identity认证后, 会出现 InvalidOpera ...

  10. Linux笔记-ps -aux的结果解析

    参考: https://blog.csdn.net/flyingleo1981/article/details/7739490 ps 的参数说明ps 提供了很多的选项参数,常用的有以下几个: l 长格 ...