Moderne Datenbankentwicklung - Tools & Konzepte€“ Gut sind Rollen für Reader, Editor, Admins...

22
Moderne Datenbankentwicklung Thomas Koch Tools & Konzepte

Transcript of Moderne Datenbankentwicklung - Tools & Konzepte€“ Gut sind Rollen für Reader, Editor, Admins...

Page 1: Moderne Datenbankentwicklung - Tools & Konzepte€“ Gut sind Rollen für Reader, Editor, Admins und ... Liquibase Flyway Dbdeploy ... Supports XML, YAML, JSON and SQL formats

ModerneDatenbankentwicklung

Thomas Koch

Tools & Konzepte

Page 2: Moderne Datenbankentwicklung - Tools & Konzepte€“ Gut sind Rollen für Reader, Editor, Admins und ... Liquibase Flyway Dbdeploy ... Supports XML, YAML, JSON and SQL formats

Moderne Software

Entwicklung

Implementierung

Deployment

Test

Betrieb

Monitoring

Dokumentation

● Coding Style● Patterns● Versionierung

● Test – Framework● Automatisierung

● Icinga / Nagios● Logs

● Continuous Integration● Continuous Delivery

● Infrastruktur● Konfiguration● Wartung

● Code – Doku● Wiki – Doku● Automatisierung

Security● Benutzer● Sicherheitslücken

Page 3: Moderne Datenbankentwicklung - Tools & Konzepte€“ Gut sind Rollen für Reader, Editor, Admins und ... Liquibase Flyway Dbdeploy ... Supports XML, YAML, JSON and SQL formats

Moderne DatenbankEntwicklung

Implementierung

Deployment

Test

Betrieb

Monitoring

Dokumentation

● Coding Style● Patterns● Versionierung

● Test – Framework● Automatisierung

● Icinga / Nagios● Logs

● Continuous Integration● Continuous Delivery

● Infrastruktur● Konfiguration● Wartung

● Code – Doku● Wiki – Doku● Automatisierung

Security● Benutzer● Sicherheitslücken

Page 4: Moderne Datenbankentwicklung - Tools & Konzepte€“ Gut sind Rollen für Reader, Editor, Admins und ... Liquibase Flyway Dbdeploy ... Supports XML, YAML, JSON and SQL formats

5/22Vortrag: Moderne DatenbankentwicklungThomas Koch

Bewertungskatalog

● Überblick über Zustandder Datenbank

● Ableiten von weiterenMaßnahmen

● Nachverfolgung & Bericht

● Unterteilung nachKategorien

● Bewertung– 0 bis 5 Punkte je

Stichpunkt einer Kategorie

– Durchschnitt je Kategorie

Page 5: Moderne Datenbankentwicklung - Tools & Konzepte€“ Gut sind Rollen für Reader, Editor, Admins und ... Liquibase Flyway Dbdeploy ... Supports XML, YAML, JSON and SQL formats

Vortrag: Moderne DatenbankentwicklungThomas Koch

6/22

Security

● Schema public und Rolle public

● Rollen

– Unterscheidung Entwickler, Admins und Software

– Gut sind Rollen für Reader, Editor, Admins undSuperadmins

● Benutzung von (NO)INHERIT

● Owner von Tabellen (und anderen Objekten)

● pg_hba.conf – vermeiden von

– trust

– md5 (und Passwort im Code & Versionskontrolle)

– All (databases & IP address)

Page 6: Moderne Datenbankentwicklung - Tools & Konzepte€“ Gut sind Rollen für Reader, Editor, Admins und ... Liquibase Flyway Dbdeploy ... Supports XML, YAML, JSON and SQL formats

Vortrag: Moderne DatenbankentwicklungThomas Koch

7/22

Implementierung

● Coding Convention

– Einrückungen

– Groß/Kleinschreibung

– Namen

● DB-Schema

– Umgang mit Schema public

– Verteilung DB-Objekte je Schema

– Trennung nach Komponenten(Export, Kunden- und Produktverwaltung usw.)

ODER / UND

Art der Daten (Stammdaten, OLTP, OLAP, Archivdaten usw.)

— Template für Funktionen

— Verwendung von NULL

— Datum statt BOOLEAN (manchmal)

Page 7: Moderne Datenbankentwicklung - Tools & Konzepte€“ Gut sind Rollen für Reader, Editor, Admins und ... Liquibase Flyway Dbdeploy ... Supports XML, YAML, JSON and SQL formats

Vortrag: Moderne DatenbankentwicklungThomas Koch

8/22

Implementierung

● Pattern (Konzepte)

– Audit-Spalten → create_dt, change_dt,change_info

– Historisierung (Protokollierung)

– Konstanten (Magic Numbers/Strings)

country_id = 12 → 'Deutschland'::Country::INT

– Views & Funktionen als Schnittstelle

– Prozesstabellen

Page 8: Moderne Datenbankentwicklung - Tools & Konzepte€“ Gut sind Rollen für Reader, Editor, Admins und ... Liquibase Flyway Dbdeploy ... Supports XML, YAML, JSON and SQL formats

Vortrag: Moderne DatenbankentwicklungThomas Koch

9/22

Test

● Auswahl eines passenden Test-Frameworks → pgTAP

● Test von

– Struktur → Existenz von Tabellen, Funktionen, Constraints …

– Logik → Arbeitsweise von Funktionen, Trigger, Views ...

– Performance

● Ausführung auf verschiedenen Umgebungen

– Dev (meist local) → alle Tests

– Test → alle Tests

– Staging → Struktur und Performance Tests

– Live → Struktur Test

● Siehe Vortrag „Teste die Datenbank!“ (letztes Jahr)

Page 9: Moderne Datenbankentwicklung - Tools & Konzepte€“ Gut sind Rollen für Reader, Editor, Admins und ... Liquibase Flyway Dbdeploy ... Supports XML, YAML, JSON and SQL formats

Vortrag: Moderne DatenbankentwicklungThomas Koch

10/22

1. Verwende niemals einegemeinsame Datenbank für dieEntwicklung im Team.

2. Habe immer eine einzigmaßgebliche Quelle für dasSchema.

3. Versioniere immer die Datenbank.

3 Rules for Database Work

Quelle: http://odetocode.com/blogs/scott/archive/2008/01/30/three-rules-for-database-work.aspx http://www.heise.de/developer/artikel/Kontinuierliche-Datenbankmigration-mit-Liquibase-und-Flyway-1857773.html

Page 10: Moderne Datenbankentwicklung - Tools & Konzepte€“ Gut sind Rollen für Reader, Editor, Admins und ... Liquibase Flyway Dbdeploy ... Supports XML, YAML, JSON and SQL formats

Vortrag: Moderne DatenbankentwicklungThomas Koch

11/22

Datenbankversionierung

Versionierung von sämtlichen DB-Code

● Änderungsskripte während derImplementierung

– Nutzen eines Deployment Tools

– Review durch DBA / Kollegen

● Regelmäßiger Export der aktuellen DB-Struktur

– Historie über die Änderung einzelner DB-Objekte

– Skript / Befehl für den Export in kleine Dateien ?

Page 11: Moderne Datenbankentwicklung - Tools & Konzepte€“ Gut sind Rollen für Reader, Editor, Admins und ... Liquibase Flyway Dbdeploy ... Supports XML, YAML, JSON and SQL formats

Vortrag: Moderne DatenbankentwicklungThomas Koch

12/22

DB Deployment Tools

● Liquibase

● Flyway

● Dbdeploy

● MigrateDB

Page 12: Moderne Datenbankentwicklung - Tools & Konzepte€“ Gut sind Rollen für Reader, Editor, Admins und ... Liquibase Flyway Dbdeploy ... Supports XML, YAML, JSON and SQL formats

Vortrag: Moderne DatenbankentwicklungThomas Koch

13/22

Liquibase

● Supports code branching and merging

● Supports multiple developers

● Supports multiple database types

● Supports XML, YAML, JSON and SQL formats

● Supports context-dependent logic

● Generate Database change documentation

● Generate Database "diffs"

● Run through your build process, embedded in yourapplication or on demand

● Automatically generate SQL scripts for DBA codereview

Quelle: http://www.liquibase.org

Page 13: Moderne Datenbankentwicklung - Tools & Konzepte€“ Gut sind Rollen für Reader, Editor, Admins und ... Liquibase Flyway Dbdeploy ... Supports XML, YAML, JSON and SQL formats

Vortrag: Moderne DatenbankentwicklungThomas Koch

14/22

Deployment mit CI-Tool

● Entwickeln einer Deployment-Pipeline inJenkins, Bamboo …

– DB-Code auschecken

– Neue Änderungsskripe ausführen (Update)

– Automatisierte Tests ausführen

– Rollback & Update

● Separat für jede Umgebung (Test & Staging)automatisiert nach jedem Checkin

● Für LIVE wahrscheinlich eher auf Knopfdruckbzw. einzelne Schritte manuell

Page 14: Moderne Datenbankentwicklung - Tools & Konzepte€“ Gut sind Rollen für Reader, Editor, Admins und ... Liquibase Flyway Dbdeploy ... Supports XML, YAML, JSON and SQL formats

15/22Vortrag: Moderne DatenbankentwicklungThomas Koch

Monitoring - pgbadger

Quelle: http://http://dalibo.github.io/pgbadger/samplev7.html

Auswertung postgres.log

Page 15: Moderne Datenbankentwicklung - Tools & Konzepte€“ Gut sind Rollen für Reader, Editor, Admins und ... Liquibase Flyway Dbdeploy ... Supports XML, YAML, JSON and SQL formats

16/22Vortrag: Moderne DatenbankentwicklungThomas Koch

Monitoring - pgcluu

Quelle: http://pgcluu.darold.net

Auswertung Systemtabellen

Page 16: Moderne Datenbankentwicklung - Tools & Konzepte€“ Gut sind Rollen für Reader, Editor, Admins und ... Liquibase Flyway Dbdeploy ... Supports XML, YAML, JSON and SQL formats

17/22Vortrag: Moderne DatenbankentwicklungThomas Koch

Monitoring - PoWa

Quelle: http://http://dalibo.github.io/powa/

Page 17: Moderne Datenbankentwicklung - Tools & Konzepte€“ Gut sind Rollen für Reader, Editor, Admins und ... Liquibase Flyway Dbdeploy ... Supports XML, YAML, JSON and SQL formats

Vortrag: Moderne DatenbankentwicklungThomas Koch

18/22

Monitoring

● Plugins für Nagios, Icinga, Zabbix und …

● check_postgres

● New Relic – Application Monitoring (java, .net, php u.a.)

● Weitere unter https://wiki.postgresql.org/wiki/Monitoring

Quelle: https://newrelic.com

Page 18: Moderne Datenbankentwicklung - Tools & Konzepte€“ Gut sind Rollen für Reader, Editor, Admins und ... Liquibase Flyway Dbdeploy ... Supports XML, YAML, JSON and SQL formats

Vortrag: Moderne DatenbankentwicklungThomas Koch

19/22

Betrieb

● Infrastruktur

– Virtualisierung

– CPU

– Platten

– RAM

– Netzwerk

● Backup / Recovery

– Prozess

– Und wie oft getestet?

● Replikation

● Hot Standby

Page 19: Moderne Datenbankentwicklung - Tools & Konzepte€“ Gut sind Rollen für Reader, Editor, Admins und ... Liquibase Flyway Dbdeploy ... Supports XML, YAML, JSON and SQL formats

Vortrag: Moderne DatenbankentwicklungThomas Koch

20/22

Betrieb

● DB-Version / Upgrade-Strategie

– Major-Versionen

– Minor-Versionen

● Konfiguration

– Manuell

– Über Puppet, Chef oder …

– Versionierung

● Cronjobs (Wartung)

– Konfiguration

– Versionierung

– Monitoring

Page 20: Moderne Datenbankentwicklung - Tools & Konzepte€“ Gut sind Rollen für Reader, Editor, Admins und ... Liquibase Flyway Dbdeploy ... Supports XML, YAML, JSON and SQL formats

Vortrag: Moderne DatenbankentwicklungThomas Koch

21/22

Dokumentation

● Mit welchen Tool?

● Zustand & Qualität (Wie aktuell?)

● Inhalt

– Struktur der Dokumentation (Chaos)

– DB-Modell

– Konzepte & Ideen

– Gründe & Entscheidungen

Page 21: Moderne Datenbankentwicklung - Tools & Konzepte€“ Gut sind Rollen für Reader, Editor, Admins und ... Liquibase Flyway Dbdeploy ... Supports XML, YAML, JSON and SQL formats

22/22Vortrag: Moderne DatenbankentwicklungThomas Koch

Zusammenfassung

● Implementierung– Schema

– Coding Convention

– Konzepte (audit, Konstantenetc.)

● Test– Automatisiert mit pgTAP

● Deployment – Deployment-Tool

– CI-Server

● Security– User & Rollen

● Betrieb– Infrastruktur

– Backup / Recovery

– Replikation

– Hot Standby

● Monitoring– Log → pgbadger

– Systemtabellen → pgcluu

– real time → PoWa

● Dokumentation– DB-Modell

– Konzepte

– Gründe & Entscheidungen

Page 22: Moderne Datenbankentwicklung - Tools & Konzepte€“ Gut sind Rollen für Reader, Editor, Admins und ... Liquibase Flyway Dbdeploy ... Supports XML, YAML, JSON and SQL formats

ModerneDatenbankentwicklung