SlideShare a Scribd company logo
Sharing Code and
Experiences
@fabriziomello
About me
I was born in Dom Pedrito in the South of Brazil
But I lived in Bagé since I was 1 year old
Bagé is 236 miles away from Porto Alegre
Porto Alegre is the FISL city
In my hometown Bagé is common
people...
● … be born there
● … grow up there
● … build a family there
● … spend the entire life there
● … and die there.
Until 2005 this lifestyle
fitted with my “old” needs
Then I had an opportunity
to work 100% of my time
with FOOS
Background
● Bachelor in Information Systems in 2002
● Entrepeneur at http://timbira.com
● Agile Methodologies Specialization student 2014/2015
● PostgreSQL colaborator since 2008 (Brazilian
community and now the international too)
FOSS and me
● My first contact was using Linux in 1997
● I fell in love with this culture since then
● In 1999 I met PostgreSQL so since then I
knew this would be part of my life
But FOSS bite me awile :-)
● Because of this decision I had a lot of
troubles, including financial…
● But here I am :-)
Is a global program that
offers students stipends to
write code for open source
projects.
We have worked with the
open source community to
identify and fund exciting
projects for the upcoming
summer.
Connect students to
open source communities
GSoC and PostgreSQL
● Since 2006
● Cool projects
○ Fast GiST index build
○ New phpPgAdmin Plugin Architecture (brazilian)
○ pgAdmin database designer
○ Better indexing for ranges
○ Document collection Foreign-data Wrapper
And now my project ...
PostgreSQL 9.1 introduced a new kind of table
Unlogged Tables
What means “Unlogged”?
First we need to know what means “WAL”
PostgreSQL is Full-ACID and to guarantee data
integrity uses a standard method called
WAL (Write-Ahead Logging)
WAL (Write-Ahead Logging)
“In computer science, write-ahead logging (WAL) is a family
of techniques for providing atomicity and durability (two of
the ACID properties) in database systems.
In a system using WAL, all modifications are written to a log
before they are applied. Usually both redo and undo
information is stored in the log.”
http://en.wikipedia.org/wiki/Write-ahead_logging
Ok, and what means “Unlogged” ?
● Unlogged means that the data written in
these tables is not written to WAL.
● So it makes written really, really fast
compared to written into regular tables.
So I’ll use it to all of my tables...
● However you won’t want to do that, because
○ They are neither crash-safe (an unlogged table is
automatically truncated after a crash or unclean
shutdown)
○ And they are nor replicated using SR
But there are some cool use cases
● Speed ETL jobs
● Cache
● Session State
● Queues?!
● ...
And now we have the power to ...
● change from UNLOGGED to LOGGED
○ ALTER TABLE name SET LOGGED;
● change from LOGGED to UNLOGGED
○ ALTER TABLE name SET UNLOGGED;
Already committed
commit: f41872d0c1239d36ab03393c39ec0b70e9ee2a3c
author: Alvaro Herrera <alvherre@alvh.no-ip.org>
date: Fri, 22 Aug 2014 14:27:00 -0400
Implement ALTER TABLE .. SET LOGGED / UNLOGGED
This enables changing permanent (logged) tables to unlogged and
vice-versa.
(Docs for ALTER TABLE / SET TABLESPACE got shuffled in an order that
hopefully makes more sense than the original.)
Author: Fabrízio de Royes Mello
Reviewed by: Christoph Berg, Andres Freund, Thom Brown
Some tweaking by Álvaro Herrera
Current implementation
1. Acquire AcessExclusiveLock
2. Check dependencies
a. Cannot change temp tables
b. Check Foreign Keys
3. Create new heap/toast with new relpersistence
4. Rewrite heap/toast
5. Rewrite indexes
Currently Caveats
● AccessExclusiveLock
● Rewrite all datafiles
PostgreSQL GSoC2015
Improve the performance of
ALTER TABLE SET LOGGED
UNLOGGED statement
Improvements
● Don’t rewrite datafiles when wal_level =
minimal
● Create wal records for datafiles when
wal_level != minimal
Main Problems
● To change an Unlogged to Logged (or vice-
versa) we need
○ Drop/Create the InitFork
○ and it is not a transactional operation
GSoC2015 : Main Problems
● ALTER TABLE ... SET LOGGED
○ if we drop the InitFork
○ and a crash occurs we're in a inconsistent state
○ in catalog the relation is marked as unlogged and
we don't have the InitFork anymore
GSoC2015 : Main Problems
● ALTER TABLE ... SET UNLOGGED
○ if we create the InitFork and the transaction
rollback or a crash occurs we're in a inconsistent
state because in the catalog the relation is marked
as logged and during the crash recovery we
truncate the relation if the InitFork exists leading us
to a inconsistent state
Idea if “wal_level = minimal”
● Acquire AcessExclusiveLock
● Check dependencies
○ Cannot change temp tables
○ Check Foreign Keys
● Create a “TransientInitFork” to crash recovery detection
● FlushRelationBuffers and fsync relation
● Drop/Create the “InitFork”
● Change Catalog
● Drop the “TransientInitFork”
Idea if “wal_level != minimal”
● Same of the “wal_level = minimal”
● Plus
○ xlog all pages of datafiles (heap, toast, index)
Questions?
Special thanks to
● GSoC2014
○ Stephen Frost (mentor)
○ Josh Berkus and Thom Brown (organizers)
○ Christoph Berg (patch review)
○ Álvaro Herrera (patch review and commit)
● GSoC2015
○ Josh Berkus and Thom Brown (organizers)
○ Ashutosh Baspat (mentor)
PGBR2015 call for papers is open!!
● When?
○ November 18, 19 and 20
● Where
○ Porto Alegre, Brasil
● http://pgbr.postgresql.org.br
GSoC2014 - PGCon2015 Presentation June, 2015

More Related Content

PDF
GSoC2014 - PGDay Ijui/RS Presentation October, 2016
PDF
Dojo plpgsql
PDF
Keep calm and Database Continuous Deployment
PDF
Bad Smells (mal cheiros) em Bancos de Dados
PDF
Como posso colaborar com o PostgreSQL
PDF
EXPLicando o Explain no PostgreSQL
PDF
Bad Smells (mal cheiros) em Bancos de Dados
PDF
Bad Smells em Bancos de Dados
GSoC2014 - PGDay Ijui/RS Presentation October, 2016
Dojo plpgsql
Keep calm and Database Continuous Deployment
Bad Smells (mal cheiros) em Bancos de Dados
Como posso colaborar com o PostgreSQL
EXPLicando o Explain no PostgreSQL
Bad Smells (mal cheiros) em Bancos de Dados
Bad Smells em Bancos de Dados

Viewers also liked (14)

PDF
NoSQL + SQL = PostgreSQL (DBA Brasil 1.0 - São Paulo/SP)
PDF
Dojo PHP (treinanto programação orientada a objetos em PHP)
PDF
Sharing Code and Experiences
ODP
Postgres Wonderland - PGDay Cascavél 2013
PDF
GSoC2014 - Uniritter Presentation May, 2015
PDF
Planejador de Consultas do PostgreSQL
PPTX
Курс лекций на программу МВА в РУДН 16 февраля 2016 Тема "Управление изменени...
PPT
יחידת הוראה לחנכה
PDF
Tutorial Database Refactoring
PDF
NoSQL + SQL = PostgreSQL (TDC2014 - Porto Alegre/RS)
PDF
PostgreSQL: How to Store Passwords Safely
PDF
PROCERGS 2015-03-25: Bad Smells em Bancos de Dados
PDF
Greenplum: O banco de dados open source massivamente paralelo baseado em Post...
PDF
DevOps e PostgreSQL: Replicação de forma simplificada | Miguel Di Ciurcio
NoSQL + SQL = PostgreSQL (DBA Brasil 1.0 - São Paulo/SP)
Dojo PHP (treinanto programação orientada a objetos em PHP)
Sharing Code and Experiences
Postgres Wonderland - PGDay Cascavél 2013
GSoC2014 - Uniritter Presentation May, 2015
Planejador de Consultas do PostgreSQL
Курс лекций на программу МВА в РУДН 16 февраля 2016 Тема "Управление изменени...
יחידת הוראה לחנכה
Tutorial Database Refactoring
NoSQL + SQL = PostgreSQL (TDC2014 - Porto Alegre/RS)
PostgreSQL: How to Store Passwords Safely
PROCERGS 2015-03-25: Bad Smells em Bancos de Dados
Greenplum: O banco de dados open source massivamente paralelo baseado em Post...
DevOps e PostgreSQL: Replicação de forma simplificada | Miguel Di Ciurcio
Ad

Similar to GSoC2014 - PGCon2015 Presentation June, 2015 (20)

PDF
Sprint Boot & Kotlin - Meetup.pdf
PDF
10 things, an Oracle DBA should care about when moving to PostgreSQL
PDF
Getting big without getting fat, in perl
PDF
Scalable, good, cheap
PPTX
Liquibase Integration with MuleSoft
PDF
Validating Big Data Pipelines - Big Data Spain 2018
PDF
How we use Bottle and Elasticsearch
PPTX
Scala - the good, the bad and the very ugly
PDF
POUG Meetup 1st MArch 2019 - utPLSQL v3 - Testing Framework for PL/SQL
PDF
Improve the deployment process step by step
PDF
PostgreSQL Sharding and HA: Theory and Practice (PGConf.ASIA 2017)
PDF
Rails DB migrate SAFE.pdf
PDF
What drives Innovation? Innovations And Technological Solutions for the Distr...
PDF
Beyond Shuffling - Effective Tips and Tricks for Scaling Spark (Vancouver Sp...
PDF
Luis Majano The Battlefield ORM
PDF
MySQL and MariaDB Backups
PPTX
Distributed System explained (with Java Microservices)
PDF
Everything You Were Taught About Java Is Wrong
PDF
Webbisauna - ClojureScript for Javascript Developers
PDF
Js basics
Sprint Boot & Kotlin - Meetup.pdf
10 things, an Oracle DBA should care about when moving to PostgreSQL
Getting big without getting fat, in perl
Scalable, good, cheap
Liquibase Integration with MuleSoft
Validating Big Data Pipelines - Big Data Spain 2018
How we use Bottle and Elasticsearch
Scala - the good, the bad and the very ugly
POUG Meetup 1st MArch 2019 - utPLSQL v3 - Testing Framework for PL/SQL
Improve the deployment process step by step
PostgreSQL Sharding and HA: Theory and Practice (PGConf.ASIA 2017)
Rails DB migrate SAFE.pdf
What drives Innovation? Innovations And Technological Solutions for the Distr...
Beyond Shuffling - Effective Tips and Tricks for Scaling Spark (Vancouver Sp...
Luis Majano The Battlefield ORM
MySQL and MariaDB Backups
Distributed System explained (with Java Microservices)
Everything You Were Taught About Java Is Wrong
Webbisauna - ClojureScript for Javascript Developers
Js basics
Ad

More from Fabrízio Mello (13)

PDF
PHP e PostgreSQL: Um é pouco, dois é bom, três é demais
PDF
Bad Smells (mal cheiros) em Bancos de Dados
PPTX
URCAMP (Jun2017) - Como o papel e atividades de DBA ficam no contexto da cult...
PDF
DBA Brasil 2.0: Como o papel e atividades de DBA ficam no contexto da cultura...
PDF
Software Delivery Like a Boss
PDF
NoSQL + SQL = PostgreSQL (PGDay Campinas 2014)
PDF
Oficina PostgreSQL Básico Latinoware 2012
ODP
Oficina postgresql avançado_consegi2010
ODP
Oficina postgresql basico_consegi2010
ODP
Database refactoring postgresql_consegi2010
ODP
Database Refactoring PostgreSQL Urcamp Alegrete 2009
ODP
Database Refactoring com PostgreSQL PGDay RS 2009
ODP
Refatoração Banco de Dados (Agileweekend2009)
PHP e PostgreSQL: Um é pouco, dois é bom, três é demais
Bad Smells (mal cheiros) em Bancos de Dados
URCAMP (Jun2017) - Como o papel e atividades de DBA ficam no contexto da cult...
DBA Brasil 2.0: Como o papel e atividades de DBA ficam no contexto da cultura...
Software Delivery Like a Boss
NoSQL + SQL = PostgreSQL (PGDay Campinas 2014)
Oficina PostgreSQL Básico Latinoware 2012
Oficina postgresql avançado_consegi2010
Oficina postgresql basico_consegi2010
Database refactoring postgresql_consegi2010
Database Refactoring PostgreSQL Urcamp Alegrete 2009
Database Refactoring com PostgreSQL PGDay RS 2009
Refatoração Banco de Dados (Agileweekend2009)

Recently uploaded (20)

PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPTX
Big Data Technologies - Introduction.pptx
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PPTX
sap open course for s4hana steps from ECC to s4
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Empathic Computing: Creating Shared Understanding
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
Building Integrated photovoltaic BIPV_UPV.pdf
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Dropbox Q2 2025 Financial Results & Investor Presentation
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Big Data Technologies - Introduction.pptx
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
sap open course for s4hana steps from ECC to s4
Mobile App Security Testing_ A Comprehensive Guide.pdf
Unlocking AI with Model Context Protocol (MCP)
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Diabetes mellitus diagnosis method based random forest with bat algorithm
Review of recent advances in non-invasive hemoglobin estimation
Empathic Computing: Creating Shared Understanding
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
MYSQL Presentation for SQL database connectivity
Encapsulation_ Review paper, used for researhc scholars
The Rise and Fall of 3GPP – Time for a Sabbatical?

GSoC2014 - PGCon2015 Presentation June, 2015

  • 3. I was born in Dom Pedrito in the South of Brazil
  • 4. But I lived in Bagé since I was 1 year old
  • 5. Bagé is 236 miles away from Porto Alegre
  • 6. Porto Alegre is the FISL city
  • 7. In my hometown Bagé is common people... ● … be born there ● … grow up there ● … build a family there ● … spend the entire life there ● … and die there.
  • 8. Until 2005 this lifestyle fitted with my “old” needs
  • 9. Then I had an opportunity to work 100% of my time with FOOS
  • 10. Background ● Bachelor in Information Systems in 2002 ● Entrepeneur at http://timbira.com ● Agile Methodologies Specialization student 2014/2015 ● PostgreSQL colaborator since 2008 (Brazilian community and now the international too)
  • 11. FOSS and me ● My first contact was using Linux in 1997 ● I fell in love with this culture since then ● In 1999 I met PostgreSQL so since then I knew this would be part of my life
  • 12. But FOSS bite me awile :-) ● Because of this decision I had a lot of troubles, including financial… ● But here I am :-)
  • 13. Is a global program that offers students stipends to write code for open source projects. We have worked with the open source community to identify and fund exciting projects for the upcoming summer.
  • 14. Connect students to open source communities
  • 15. GSoC and PostgreSQL ● Since 2006 ● Cool projects ○ Fast GiST index build ○ New phpPgAdmin Plugin Architecture (brazilian) ○ pgAdmin database designer ○ Better indexing for ranges ○ Document collection Foreign-data Wrapper
  • 16. And now my project ... PostgreSQL 9.1 introduced a new kind of table Unlogged Tables
  • 17. What means “Unlogged”? First we need to know what means “WAL” PostgreSQL is Full-ACID and to guarantee data integrity uses a standard method called WAL (Write-Ahead Logging)
  • 18. WAL (Write-Ahead Logging) “In computer science, write-ahead logging (WAL) is a family of techniques for providing atomicity and durability (two of the ACID properties) in database systems. In a system using WAL, all modifications are written to a log before they are applied. Usually both redo and undo information is stored in the log.” http://en.wikipedia.org/wiki/Write-ahead_logging
  • 19. Ok, and what means “Unlogged” ? ● Unlogged means that the data written in these tables is not written to WAL. ● So it makes written really, really fast compared to written into regular tables.
  • 20. So I’ll use it to all of my tables... ● However you won’t want to do that, because ○ They are neither crash-safe (an unlogged table is automatically truncated after a crash or unclean shutdown) ○ And they are nor replicated using SR
  • 21. But there are some cool use cases ● Speed ETL jobs ● Cache ● Session State ● Queues?! ● ...
  • 22. And now we have the power to ... ● change from UNLOGGED to LOGGED ○ ALTER TABLE name SET LOGGED; ● change from LOGGED to UNLOGGED ○ ALTER TABLE name SET UNLOGGED;
  • 23. Already committed commit: f41872d0c1239d36ab03393c39ec0b70e9ee2a3c author: Alvaro Herrera <alvherre@alvh.no-ip.org> date: Fri, 22 Aug 2014 14:27:00 -0400 Implement ALTER TABLE .. SET LOGGED / UNLOGGED This enables changing permanent (logged) tables to unlogged and vice-versa. (Docs for ALTER TABLE / SET TABLESPACE got shuffled in an order that hopefully makes more sense than the original.) Author: Fabrízio de Royes Mello Reviewed by: Christoph Berg, Andres Freund, Thom Brown Some tweaking by Álvaro Herrera
  • 24. Current implementation 1. Acquire AcessExclusiveLock 2. Check dependencies a. Cannot change temp tables b. Check Foreign Keys 3. Create new heap/toast with new relpersistence 4. Rewrite heap/toast 5. Rewrite indexes
  • 26. PostgreSQL GSoC2015 Improve the performance of ALTER TABLE SET LOGGED UNLOGGED statement
  • 27. Improvements ● Don’t rewrite datafiles when wal_level = minimal ● Create wal records for datafiles when wal_level != minimal
  • 28. Main Problems ● To change an Unlogged to Logged (or vice- versa) we need ○ Drop/Create the InitFork ○ and it is not a transactional operation
  • 29. GSoC2015 : Main Problems ● ALTER TABLE ... SET LOGGED ○ if we drop the InitFork ○ and a crash occurs we're in a inconsistent state ○ in catalog the relation is marked as unlogged and we don't have the InitFork anymore
  • 30. GSoC2015 : Main Problems ● ALTER TABLE ... SET UNLOGGED ○ if we create the InitFork and the transaction rollback or a crash occurs we're in a inconsistent state because in the catalog the relation is marked as logged and during the crash recovery we truncate the relation if the InitFork exists leading us to a inconsistent state
  • 31. Idea if “wal_level = minimal” ● Acquire AcessExclusiveLock ● Check dependencies ○ Cannot change temp tables ○ Check Foreign Keys ● Create a “TransientInitFork” to crash recovery detection ● FlushRelationBuffers and fsync relation ● Drop/Create the “InitFork” ● Change Catalog ● Drop the “TransientInitFork”
  • 32. Idea if “wal_level != minimal” ● Same of the “wal_level = minimal” ● Plus ○ xlog all pages of datafiles (heap, toast, index)
  • 34. Special thanks to ● GSoC2014 ○ Stephen Frost (mentor) ○ Josh Berkus and Thom Brown (organizers) ○ Christoph Berg (patch review) ○ Álvaro Herrera (patch review and commit) ● GSoC2015 ○ Josh Berkus and Thom Brown (organizers) ○ Ashutosh Baspat (mentor)
  • 35. PGBR2015 call for papers is open!! ● When? ○ November 18, 19 and 20 ● Where ○ Porto Alegre, Brasil ● http://pgbr.postgresql.org.br