Slide 1

Slide 1 text

Database as a Code! Грамин Максим @GraminMaksim

Slide 2

Slide 2 text

Disclaimer  Мало Java  Много DB  «Личное мнение на личном опыте»(c) 2

Slide 3

Slide 3 text

 Дизайн  Разработка  Сопровождение  Мониторинг  Тюнинг 3

Slide 4

Slide 4 text

Типичный проект  Несколько СУБД разных видов  Много инстансов БД  Их становится всё больше … 4

Slide 5

Slide 5 text

New Trends and Challenges for DBAs https://www.quest.com/infographic/new-trends-and-challenges-for-dbas8130723/ 5

Slide 6

Slide 6 text

DBAs Face New Challenges: Trend in Database Administration https://www.quest.com/whitepaper/dbas-face-new-challenges-trend-in-database-administration8130482/ 6

Slide 7

Slide 7 text

DBAs Face New Challenges: Trend in Database Administration https://www.quest.com/whitepaper/dbas-face-new-challenges-trend-in-database-administration8130482/ 7

Slide 8

Slide 8 text

DBAs Face New Challenges: Trend in Database Administration https://www.quest.com/whitepaper/dbas-face-new-challenges-trend-in-database-administration8130482/ 8

Slide 9

Slide 9 text

DBAs Face New Challenges: Trend in Database Administration https://www.quest.com/whitepaper/dbas-face-new-challenges-trend-in-database-administration8130482/ 9

Slide 10

Slide 10 text

10

Slide 11

Slide 11 text

Управление инфраструктурой  Много серверов  Много ОС’ей  Много софта 11

Slide 12

Slide 12 text

Infrastructure as Code  SCM Ansible, Chef, Puppet, etc  DSL Ansible Playbooks, Chef Recipes  Markets Ansible Galaxy, Chef Supermarket  COMMUNITY! 12

Slide 13

Slide 13 text

Everything as Сode  Continuous integration Jenkins pipeline  Documentation DocBook, LaTeX, AsciiDoc  Network octodns, dnscontrol  etc etc 13

Slide 14

Slide 14 text

А что насчет «Database as Code»? 14

Slide 15

Slide 15 text

«Database as Code» https://speakerdeck.com/tastapod/arent-we-forgetting-someone https://twitter.com/tastapod https://dannorth.net 15

Slide 16

Slide 16 text

https://dzone.com/articles/database-as-code-a-novel-concept 16

Slide 17

Slide 17 text

"Database as Code"? 17

Slide 18

Slide 18 text

Миграторы  Liquibase  Flyway  DbMaintain, dbdeploy, gh-ost, etc 18

Slide 19

Slide 19 text

Pyrseas  Describe db-schema as YAML  Compare with another db-scheme  Generate modifying SQL https://github.com/perseas/Pyrseas 19

Slide 20

Slide 20 text

2bass - DB schema as code tool  Idempotent DDL scripts  Modify your database schema  Run:  bass init  bass plan  bass apply https://github.com/CourseOrchestra/2bass 20

Slide 21

Slide 21 text

pgbedrock Manage a Postgres:  Cluster's roles  Role memberships  Schema ownership  Privileges https://github.com/Squarespace/pgbedrock 21

Slide 22

Slide 22 text

А что еще конфигурировать кроме схемы БД?  DBA-tasks (start/stop db, etc)  Space Management (create TS, move table, shrink table, etc)  Performance Tuning (set system params, on/off trace, etc)  Security and Auditing (grant/revoke priv, RLS, on/off audit etc)  Metrics (cpu, ram, read/write, connections, etc)  Preventing the problem (fk without indexes, table without stats, etc) 22

Slide 23

Slide 23 text

Ну какой нафик SQL в 2к18-м? 23

Slide 24

Slide 24 text

https://db-engines.com/en/ranking_trend 24

Slide 25

Slide 25 text

SQL in NoSQL 25

Slide 26

Slide 26 text

SQL in NewSQL 26

Slide 27

Slide 27 text

SQL in BigData 27

Slide 28

Slide 28 text

SQL in Streams 28

Slide 29

Slide 29 text

SQL in Clouds 29

Slide 30

Slide 30 text

А что еще конфигурировать кроме схемы БД? 30 Oracle Postgresql

Slide 31

Slide 31 text

The Information Schema is an ANSI-standard Support:  Microsoft SQL Server  MySQL  PostgreSQL  HSQLDB Not support:  Oracle Database  IBM DB2  SQLite  Sybase ASE 31

Slide 32

Slide 32 text

Не только схема данных Oracle:  v$session  v$process  v$bh  user_tables Postgresql:  pg_database  pg_user  pg_stat_activity  pg_stat_replication MySQL:  processlist  partitions  statistics  etc 32

Slide 33

Slide 33 text

В т.ч. и для NoSQL Cassandra:  tables  keyspaces  sessions  hints ClickHouse:  tables  database  processes  merges Cockroach:  tables  schemata  columns  statistics 33

Slide 34

Slide 34 text

Oracle 34

Slide 35

Slide 35 text

Postgresql 35

Slide 36

Slide 36 text

36 Cassandra

Slide 37

Slide 37 text

> Большинство проблем конфигурирования, администрирования и сопровождения БД можно решить кодом, SQL-кодом … 37

Slide 38

Slide 38 text

Как в этом всем разобраться? 38

Slide 39

Slide 39 text

Сайты со скриптами  dbrnd.com/postgresql-dba-scripts  dbrnd.com/category/mysql-dba-script  orafaq.com/wiki/Scripts  oracle-base.com/dba/scripts  dba-oracle.com/oracle_dba_scripts.htm  red-gate.com/products/dba/sql-scripts-manager/scripts 39

Slide 40

Slide 40 text

Репозитории со скриптами  dataegret/pg-utils Useful DBA tools by PostgreSQL-Consulting.com  pgexperts/pgx_scripts A collection of useful little scripts for database analysis and administration  gwenshap/Oracle-DBA-Scripts Scripts that make my job as a DBA a bit easier 40

Slide 41

Slide 41 text

41

Slide 42

Slide 42 text

Идея  «Управляемые» скрипты github.com/sql-boot/sql-boot-postgresql github.com/sql-boot/sql-boot-oracle github.com/sql-boot/sql-boot-clickhouse github.com/v_pooupkin/my-postgresql-conf  REST-интерфейс github.com/sql-boot/sql-boot  Интеграция «со всем» Мониторинг, визуализация данных, безопасность, etc 42

Slide 43

Slide 43 text

Архитектура 43

Slide 44

Slide 44 text

https://github.com/sql-boot/sql-boot-postgresql 44

Slide 45

Slide 45 text

Запуск 45

Slide 46

Slide 46 text

Rest query examples  GET table/persons  DROP table/persons  GET table/bookings/size?select=row_estimate  GET table/bookings/size/limit=10  GET table/bookings/size/limit=10&top=100  GET table/bookings/count?cache=true 46

Slide 47

Slide 47 text

http://…/table/bookings.ticket_flights/size https://github.com/sql-boot/sql-boot-postgresql/blob/master/database/schema/table/README.md#size 47

Slide 48

Slide 48 text

http://…/table/bookings/no_stat https://github.com/sql-boot/sql-boot-postgresql/tree/master/database/schema/table#no_stat В 48

Slide 49

Slide 49 text

http://…/table/bookings/depends https://github.com/sql-boot/sql-boot-postgresql/tree/master/database/schema/table#depends В 49

Slide 50

Slide 50 text

Автотесты 50

Slide 51

Slide 51 text

51

Slide 52

Slide 52 text

Maximum integration 52

Slide 53

Slide 53 text

Swagger Или может быть Grafeas …. 53

Slide 54

Slide 54 text

Monitoring «SQL-BOOT» 54

Slide 55

Slide 55 text

«SQL-BOOT» plantuml-rest-service Diagrams  DOT  GraphML  Asciidoctor 55

Slide 56

Slide 56 text

https://github.com/sql-boot/sql-boot-oracle/tree/master/database/schema/table#relations 56

Slide 57

Slide 57 text

https://github.com/sql-boot/sql-boot-postgresql/tree/master/database/schema/table#depends 57

Slide 58

Slide 58 text

«SQL-BOOT» Security 58

Slide 59

Slide 59 text

Chatops «SQL-BOOT» > /db-bot show process on postgres_test > /db-bot show process on oracle_prod > /db-bot analyze persons on postgres_test > /db-bot analyze persons on oracle_prod http 59

Slide 60

Slide 60 text

Пример конфигурации 60

Slide 61

Slide 61 text

ORACLE C* POSTGRESQL «SQL-BOOT» INFLUXDB TELEGRAF Read simple sql-files SQL http://sql-boot-server:8080/process 61

Slide 62

Slide 62 text

Выводы  Конфигурирование БД – это не только миграции схемы  SQL – это тоже код  Интеграция с другими инструментами 63

Slide 63

Slide 63 text

@GraminMaksim github.com/sql-boot/sql-boot [email protected] Спасибо за внимание! Вопросы? 64