Slide 1

Slide 1 text

Banco de dados em Containers Fernando Ike PGConf.Brasil 2018

Slide 2

Slide 2 text

Cache/Buffer

Slide 3

Slide 3 text

Cache An auxiliary memory from which high-speed retrieval is possible. https://en.oxforddictionaries.com/definition/cache

Slide 4

Slide 4 text

Buffer A temporary memory area in which data is stored while it is being processed or transferred, especially one used while streaming video or downloading audio. https://en.oxforddictionaries.com/definition/buffer

Slide 5

Slide 5 text

https://momjian.us/main/writings/pgsql/hw_performance/

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

Database cache Filesystem cache Disk cache Store data (disk)

Slide 8

Slide 8 text

What’s is Virtual Machine? “...an efficient, isolated duplicate of a real computer machine...” Gerald Popek and Robert Goldberg

Slide 9

Slide 9 text

VM Infrastructure Hypervisor App A Artifact Bin/Libs App B Bin/Libs App C Bin/Libs Guest OS Guest OS Guest OS

Slide 10

Slide 10 text

What’s container? Container is a type of virtualization, more common call “operating-system-level virtualization”

Slide 11

Slide 11 text

Container Infrastructure Hypervisor Docker App A Artifact Bin/Libs App B Bin/Libs App C Bin/Libs

Slide 12

Slide 12 text

Ephemera Ephemera (singular: ephemeron) are any transitory written or printed matter not meant to be retained or preserved

Slide 13

Slide 13 text

Stateless application Applications don’t need to store anything in a persistent disk. Data application are storage in other part of architecture system

Slide 14

Slide 14 text

Stateful application Application that need to store “locally” data and need to recover that easy after an “interruption”

Slide 15

Slide 15 text

Cap Theorem

Slide 16

Slide 16 text

Union filesystem It allows files and directories of separate file systems, known as branches, to be transparently overlaid, forming a single coherent file system.

Slide 17

Slide 17 text

Container layers

Slide 18

Slide 18 text

Main filesytem for internal container data AUFS Overlayfs Overlayfs2 Device-Mapper Bind/Mount

Slide 19

Slide 19 text

Databases operation Plan what type of workload to use Maintain, organize and “improve” dataset together application Install security fix releases Archive “old” data (sanitize) Upgrade Database version Tuning OS, Database and Application

Slide 20

Slide 20 text

What’s means in OS handle... sysctl /proc /sys limits overcommit

Slide 21

Slide 21 text

What’s means in the PostgreSQL Shared Buffers WAL Max_connections Effective_cache_size Checkpoint_segments Random_page_cost

Slide 22

Slide 22 text

Container Volumes They are a mechanism for persisting data generated and/or used by container

Slide 23

Slide 23 text

Why to use PostgreSQL within containers Lower footprint to start Easy to change postgresql.conf and use git to have history change (tracking) Less surface attack in the “application Can “restrict” Linux Capabilities within container “Small” database by microservice Use always a Container Storage

Slide 24

Slide 24 text

Tips One database per type of workload Take care to restrict network, consider restrict database access only own application Push database log to Monitoring system/service Clusters and data replication are more complex Database use intensive CPU and IO, think if there is another service with the same workload type Database is prepare to support two version of application (Deploy strategies without downtime)

Slide 25

Slide 25 text

version: "3" services: db: image: postgres environment: - POSTGRES_USER=postgres - POSTGRES_PASSWORD=postgress - POSTGRES_DB=postgres ports: - "5433:5432" volumes: - pgdata:/var/lib/postgresql/data networks: - postgres volumes: pgdata: networks: postgres:

Slide 26

Slide 26 text

Demo

Slide 27

Slide 27 text

Demo code https://gist.github.com/fike/158204255cfbc368f36fad66ccd999a7

Slide 28

Slide 28 text

● Bruce Momjian - Performance tuning ● Docker Volumes ● Kubernetes Volumes ● Oxford Dictionaries ● Formal requirements for virtualizable third generation architectures - Gerald J. Popek and Robert P. Goldberg ● CAP Theorem and Distributed Database Management Systems References

Slide 29

Slide 29 text

// http://www.10deploys.com // [email protected] // https://twitter.com/fernandoike // http://www.fernandoike.com // https://www.linkedin.com/in/fernandoike/ Contacts