数据库管理: Relational Database AdministrationDBA

  • Post author:
  • Post category:其他

一、工作内容

在这里插入图片描述

二、 数据库介绍

数据库生命周期:

需求分析 -> 设计数据库 -> 构建数据库 -> 监控与维护
在这里插入图片描述

数据库有如下的架构:

在这里插入图片描述

instance:

通过对应的configuration 提供逻辑隔离

在这里插入图片描述

schema:

instance层级下面,与database并列的是系统schema
Database层级下面也有对应的user schemas
在这里插入图片描述

设计database objects的时候,需要考虑:

  • tables
  • constraints(常出现的是说foreign key)
  • indexes(提高查询速度,优化query)
  • keys(主键与外键)
  • views(不复制数据内容)
  • aliases
  • event
  • triggers
  • log files

三、数据库管理中重要的内容

1. system objects and database configuration

不同的数据库system objects形式不一样,内容差不多。

Db2:
在这里插入图片描述

mysql:
在instance下面的schema负责系统相关配置
在这里插入图片描述

例子:mysql的系统操作

使用名为information_schema的database, 其中有一个table,名字叫COLUMNS , 里面会存所有tables的column名字, 这一列叫做COLUMN_NAME.

这个很有用,记不住自己tables的所有column都是什么,就从这里查询.

举例:

查询table名字为country的所有column:

SELECT COLUMN_NAME FROM COLUMNS WHERE TABLE_NAME = 'country';


另外一个table名为TABLES, 里面存储一些有用的信息:

engine: 使用的引擎.关于mysql的引擎,详细见博文storge engines in mysql
datalength : size of table
indexlength: size of indexes
table_schema
table_name
等等

举个例子:

在这里插入图片描述

2. configuration files

配置文件是instance层级的内容。

  • 安装时的配置:目录、端口,内存分配、connection timeout\maximum packet size等。
  • 配置文件通常是.conf文件

在这里插入图片描述

配置的时候,记得关掉database的服务,再修改config文件

3. database storage

逻辑层 到 物理层面的映射

tablespaces -> containers(一对一或者一对多)

tablespace的好处是,对外统一逻辑存储方便管理,对内可以分布式的物理存储

在这里插入图片描述
storage groups, 可以配合 tablespace 提高performance

partitions:

在这里插入图片描述

四、备份与恢复 backup and restore

1. backup

backup种类:

在这里插入图片描述

hot or cold: 指的是是否要关闭数据库。热备就是可以在数据库运行的时候进行备份。

其中第二类备份的方式,我们可以做如下详细的说明:

differential backup 比 incremental 更快一些。
point in time 通常是从log中sql恢复。
其实备份的时候,不用学究的对应到底是哪种备份手段。
在这里插入图片描述

2. mysql backup命令

几个关键的命令:

  1. 数据库全备份

    	mysqldump --host=127.0.0.1 --port=3306 --user=root --password --flush-logs\
    	 --delete-master-logs  --databases world > world_mysql_full_backup.sql
    
  2. 从sql文件导入:
    source world_mysql_update_B.sql;

  3. 查看log文件:

    mysql --host=127.0.0.1 --port=3306 --user=root --password --execute="SHOW BINARY LOGS;"
    
  4. 从log文件恢复sql文件
    mysql将所有的导入导出加密为二进制log文件,我们可以用如下命令来恢复.

    mysqlbinlog /var/lib/mysql/binlog.000003 /var/lib/mysql/binlog.000004 > logfile.sql
    

3. transaction log

主要是辅助数据恢复。

Database transaction logs keep track of all activities that change the database structure and record transactions that insert, update, or delete data in the database.
在这里插入图片描述

五、security and user management

本部分几个重要的概念:

认证与授权

Authentication is the process of verifying that the user is who they claim to be.
Authorization is the process of giving users permissions or privileges to access the objects and data in the database.​

user, group, role
用户就是账户:A database user is a user account that is allowed to access specified database objects.
用户分组方便管理:Groups are logical groupings of users to simplify user management.
role说明具体权限(面向数据库的,可以将role grant 给对应的user or group):A database role defines a set of permissions needed to undertake a specific role in the database.

这部分不会做详细说明,比如如何加密,如何监听等。简单带过。

1. overview

谈及安全,具体包括:数据库服务器,操作系统,数据库,以及数据。
具体手段:用户账户权限管理,数据加密,监控与监听等。

在这里插入图片描述

2. users, groups, and roles

在这里插入图片描述

六、 monitoring and optimization

这里的监控与上一小节的监控是两个范畴。这里的监控主要是面向优化而言。系统的内存硬盘,如何提高数据库查询的效率等。

1. overview

Database performance is measured by using key performance indicators, known as metrics, that enable DBAs to optimize organizations’ databases.

You should monitor at the infrastructure, platform, query, and user levels.

A database diagnostic log file(注意与之前主要用于数据备份与恢复的transaction log不同), also known as an error log or troubleshooting log, contains timestamped messages for various types of informational messages, events, warnings, and error details.

Database optimization commands include OPTIMIZE TABLE in MySQL, VACUUM, and REINDEX in PostgreSQL, and RUNSTATS and REORG in Db2.

Query execution plans show details of the steps used to access data when running query statements. 在mysql中对应着explain关键字。

2. monitoring tasks:

  1. forcasting future hardware requirements based on database usage pattern. 硬件层面
  2. analyzing the performance of individual applications or database queries 查询层面
  3. tracking the usage of indexes and tables 优化层面
  4. determining the root cause of any system performance degradation 系统
  5. optimizing database elements to provide the best possible performance.
  6. assessing the impact of any optimization activities. 评估优化效果

3. 监控内容与手段

内容:

  1. 数据吞吐量 database throughput: number of queries executed per second.
  2. 数据库资源使用情况database resource usage:cpu,memory,storage…
    • average max latest
    • time sequence
  3. database avilibility
  4. 数据库响应database responsiveness: avg response time per query
  5. database contention:用于评估多个进程同时获取同一个数据库内容的能力
  6. units of work: 那个transaction最消耗database的resource
  7. network connections
  8. most frequent queries
  9. locked object
    10.store procedures
  10. buffer pools
  11. top consumers

工具:

在这里插入图片描述
在这里插入图片描述

4. optimization

Database optimization commands include OPTIMIZE TABLE in MySQL
VACUUM, and REINDEX in PostgreSQL
RUNSTATS and REORG in Db2.

using indexes 提高查询速度

七、troubleshooting and automation

1. common issues

  • inadequate hardware
  • server or database configuration
    • client server database
  • network connectivity
  • queries and application logic

2. use logs for troubleshooting

logs中有: error, information, event(比如user connection), warning等有用的信息.

在这里插入图片描述
类型有很多:

在这里插入图片描述

内容包括:

在这里插入图片描述

3. automating database tasks

主要就是shell脚本的编写。具体怎么写,就是shell的功底了。

能做的工作包括:

在这里插入图片描述


版权声明:本文为allenhsu6原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。