SlideShare uma empresa Scribd logo
1 de 17
What‘s new in PostgreSQL 9

      Dan-Claudiu DRAGOŞ
PostgreSQL 9




                             About PostgreSQL


• This presentation was inspired by the sessions I‘ve attended at
  Fosdem 2010

• PostgreSQL means:
    –   Standards followed closely
    –   A true relational database
    –   Complex, advanced features that puts it far ahead of its competition
    –   The best tool to use for advanced database-based applications!


• This comes at a cost: it can‘t compete with simpler database
  systems on poor hardware and writing „simple things“ tends to get
  harder


                                                                               2
PostgreSQL 9




                   Common Table Expressions

• Available since version 8.4
• They are about defining an in-place data structure by the result of a
  query or a query combination
• This data structure can then be queried further
• Recursive join over this data structure is also possible


• Some of this functionality was available before by using:
        • Views (named data structures stored into the database backend)
        • Subselects


• The join recursion is a brand new feature



                                                                       3
PostgreSQL 9




                Common Table Expressions

• Basic usage

      WITH [RECURSIVE] name AS
      (
        SELECT field1 FROM table WHERE field2=“abc”
      )
      SELECT * FROM name ORDER BY field;




                                                      4
PostgreSQL 9




                   Common Table Expressions

• Join recursion

   – Assume we have the following corporate structure:

       -- department structure represented here is as follows:
       --
       -- ROOT-+->A-+->B-+->C
       --      |         |
       --      |         +->D-+->F
       --      +->E-+->G


   – We want all the departments under A (or under any department, actually)




                                                                       5
PostgreSQL 9




                   Common Table Expressions

• Join recursion
       CREATE TABLE department (
           id INTEGER PRIMARY KEY,
           parent_department INTEGER REFERENCES department,
           name TEXT
       );
       INSERT INTO department (id, parent_department, "name")
       VALUES
            (0, NULL, 'ROOT'),
            (1, 0, 'A'),
            (2, 1, 'B'),
            (3, 2, 'C'),
            (4, 2, 'D'),
            (5, 0, 'E'),
            (6, 4, 'F'),
            (7, 5, 'G');


                                                                6
PostgreSQL 9




                 Common Table Expressions

• Join recursion
      WITH RECURSIVE subdepartment AS
      (
          -- non-recursive term
          SELECT * FROM department WHERE name = 'A'

         UNION ALL

         -- recursive term
         SELECT d.*
         FROM
              department AS d
         JOIN
              subdepartment AS sd
              ON (d.parent_department = sd.id)
      )
      SELECT *
      FROM subdepartment
      ORDER BY name;

                                                      7
PostgreSQL 9




                    Common Table Expressions

• Join recursion

   – The non-recursive term is optional
   – There are some restrictions when it comes to defining the
     recursive term:
           –   No subquery using the recursive term (no double recursion)
           –   No aggregate functions such as COUNT(*)
           –   No HAVING, GROUP BY
           –   No ORDER BY, no LIMIT
           –   No FULL JOIN
           –   The recursive term must be on the left hand side:
                  » JOIN reference ON (recursiveterm.field = reference.field)


• The database engine performs a brute-force, all-terms comparison
  so performance can sometimes be an issue


                                                                                8
PostgreSQL 9




          Hot Standby and Streaming Replication

• They are both about database synchronization
• Hot Standby is a „push“
• Streaming Replication is a „pull“

• The issue at hand is duplicating the contents of a Master Database
  into one or more Slaves

• Hot Standby means that every query ran on Master is also ran on
  the Slave; this also works for table locks!

• Streaming replication means that every database transaction is
  requested by the Slave and then applied on it


                                                           9
PostgreSQL 9




                   Deferrable Unique Constraints

• This query sequence always fails:

# CREATE   TABLE test (a INT PRIMARY KEY);
# INSERT   INTO test values (1), (2);
# UPDATE   test SET a = a + 1;
 ERROR:    duplicate key value violates unique constraint "test_pkey"
 DETAIL:    Key (a)=(2) already exists.


• What 9.0 version provides is that the uniqueness constraint may be
  checked after running the query, not as the query runs:

# CREATE TABLE test (a INT PRIMARY KEY DEFERRABLE);




                                                                  10
PostgreSQL 9




                      Exclusion Constraints

• Before 9.0, exclusion would be checked by using operator “=“
• Version 9.0 allows for a more complex approach

# CREATE TABLE reservation
 (
   room      TEXT,
   speaker   TEXT,
   during    PERIOD);

 ALTER TABLE reservation ADD CONSTRAINT test_exclude EXCLUDE USING gist
   (room WITH =,during WITH &&);


• The constraint is defined on 2 fields; the point is not having the
  same room reserved at the same time
• The example uses 2 modules from „contrib“ (temporal and gist)

                                                                11
PostgreSQL 9




                      Exclusion Constraints

• Example using the previous table definition:

# INSERT INTO reservation (speaker ,room, during) VALUES ( ‘Dan', ‘Flex
   Room', period('2010-12-10 12:00:00', '2010-12-10 13:00:00'));
 INSERT 0 1
# INSERT INTO reservation (speaker, room, during) VALUES ( ‘Catalin',
   ‘Presentation', period('2010-12-10 15:00:00', '2010-12-10 16:00:00'));
 INSERT 0 1
# INSERT INTO reservation (speaker ,room, during) VALUES ( ‘Andrei', ‘Flex
   Room', period('2010-12-10 12:30:00', '2010-12-10 13:00:00'));
 ERROR: conflicting key value violates exclusion constraint "test_exclude"
 DETAIL: Key (room, during)=(Flex Room, [2010-12-10 12:30:00+02, 2010-12-
   10 13:00:00+02)) conflicts with existing key (room, during)=(Flex Room,
   [2010-12-10 12:00:00+02, 2010-12-10 13:00:00+02)).


• This feature is available in PostgreSQL only


                                                               12
Smaller enhancements

• GRANT / REVOKE on Schemas
   – PostgreSQL has Databases -> Schemas -> Tables -> Fields
   – Until 9.0 you could grant (revoke) rights on Databases and Tables only
   – This functionality could be achieved before 9.0 by writing a script


• Faster VACUUM FULL
   – This is the more or less equivalent to the OPTIMIZE query in MySQL
   – This command used to be pretty slow on large databases
   – In 9.0 it works by performing a copy of the database


• Better 64bit support
   – 64bit binaries were already available on Linux
   – Windows native 64bit binary is the new thing in version 9.0



                                                                        13
PL/PgSQL enhancements

• Unnamed functions
   – In 9.0 you can run code snippets in place
   – Before 9.0 you had to define a stored procedure and then call it

    DO language plpgsql $$
    DECLARE
    vr record;

    BEGIN

    FOR vr IN SELECT tablename FROM pg_tables WHERE tableowner = ‘dan' AND schemaname
      NOT IN ('pg_catalog','information_schema')
    LOOP
      EXECUTE 'GRANT SELECT ON ' || vr.tablename || ' TO tester';
    END LOOP;
    END
    $$;




                                                                        14
PL/PgSQL enhancements

• Named parameter calls
   – Before 9.0 you had to provide all the function parameters and care for their order,
     as provided in the function definition
   – Version 8.4 added “default parameters”, allowing skipping certain parameters
     (they would be replaced with their default values)

   – Example function:

    CREATE FUNCTION test (a INT, b TEXT) RETURNS TEXT AS $$
    DECLARE
      value TEXT;
    BEGIN
      value := 'a is ' || a::text || ' and b is ' || b;
      RETURN value;
    END;
    $$ LANGUAGE plpgsql;




                                                                          15
PL/PgSQL enhancements

• Named parameter calls
   – Before 9.0 you would have called it this way:

    SELECT test(1,'foo');
    test
    -------------------------
    a is 1 and b is foo
    (1 row)



   – Version 9.0 allows this type of function call:

    SELECT test( b:='foo', a:=1);
    test
    -------------------------
    a is 1 and b is foo
    (1 row)




                                                      16
That’s it




• Questions?




                           17

Mais conteúdo relacionado

Mais procurados

Oracle Database 12.1.0.2 New Features
Oracle Database 12.1.0.2 New FeaturesOracle Database 12.1.0.2 New Features
Oracle Database 12.1.0.2 New FeaturesAlex Zaballa
 
PostgreSQL- An Introduction
PostgreSQL- An IntroductionPostgreSQL- An Introduction
PostgreSQL- An IntroductionSmita Prasad
 
PostgreSQL Performance Tuning
PostgreSQL Performance TuningPostgreSQL Performance Tuning
PostgreSQL Performance Tuningelliando dias
 
My sql with querys
My sql with querysMy sql with querys
My sql with querysNIRMAL FELIX
 
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should KnowDBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should KnowAlex Zaballa
 
Mysql Explain Explained
Mysql Explain ExplainedMysql Explain Explained
Mysql Explain ExplainedJeremy Coates
 
Database administration commands
Database administration commands Database administration commands
Database administration commands Varsha Ajith
 
Introduction into MySQL Query Tuning for Dev[Op]s
Introduction into MySQL Query Tuning for Dev[Op]sIntroduction into MySQL Query Tuning for Dev[Op]s
Introduction into MySQL Query Tuning for Dev[Op]sSveta Smirnova
 
Test Dml With Nologging
Test Dml With NologgingTest Dml With Nologging
Test Dml With NologgingN/A
 
Data Processing Inside PostgreSQL
Data Processing Inside PostgreSQLData Processing Inside PostgreSQL
Data Processing Inside PostgreSQLEDB
 
SQLMAP Tool Usage - A Heads Up
SQLMAP Tool Usage - A  Heads UpSQLMAP Tool Usage - A  Heads Up
SQLMAP Tool Usage - A Heads UpMindfire Solutions
 
PGConf.ASIA 2017 Logical Replication Internals (English)
PGConf.ASIA 2017 Logical Replication Internals (English)PGConf.ASIA 2017 Logical Replication Internals (English)
PGConf.ASIA 2017 Logical Replication Internals (English)Noriyoshi Shinoda
 

Mais procurados (20)

Oracle Database 12.1.0.2 New Features
Oracle Database 12.1.0.2 New FeaturesOracle Database 12.1.0.2 New Features
Oracle Database 12.1.0.2 New Features
 
PostgreSQL- An Introduction
PostgreSQL- An IntroductionPostgreSQL- An Introduction
PostgreSQL- An Introduction
 
PostgreSQL Performance Tuning
PostgreSQL Performance TuningPostgreSQL Performance Tuning
PostgreSQL Performance Tuning
 
My sql with querys
My sql with querysMy sql with querys
My sql with querys
 
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should KnowDBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
 
Mysql Explain Explained
Mysql Explain ExplainedMysql Explain Explained
Mysql Explain Explained
 
Oracle ORA Errors
Oracle ORA ErrorsOracle ORA Errors
Oracle ORA Errors
 
8.4 Upcoming Features
8.4 Upcoming Features 8.4 Upcoming Features
8.4 Upcoming Features
 
Database administration commands
Database administration commands Database administration commands
Database administration commands
 
Sqlmap
SqlmapSqlmap
Sqlmap
 
Introduction into MySQL Query Tuning for Dev[Op]s
Introduction into MySQL Query Tuning for Dev[Op]sIntroduction into MySQL Query Tuning for Dev[Op]s
Introduction into MySQL Query Tuning for Dev[Op]s
 
9.1 Grand Tour
9.1 Grand Tour9.1 Grand Tour
9.1 Grand Tour
 
9.1 Mystery Tour
9.1 Mystery Tour9.1 Mystery Tour
9.1 Mystery Tour
 
Sqlmap
SqlmapSqlmap
Sqlmap
 
Test Dml With Nologging
Test Dml With NologgingTest Dml With Nologging
Test Dml With Nologging
 
Data Processing Inside PostgreSQL
Data Processing Inside PostgreSQLData Processing Inside PostgreSQL
Data Processing Inside PostgreSQL
 
My sql.ppt
My sql.pptMy sql.ppt
My sql.ppt
 
SQLMAP Tool Usage - A Heads Up
SQLMAP Tool Usage - A  Heads UpSQLMAP Tool Usage - A  Heads Up
SQLMAP Tool Usage - A Heads Up
 
Postgre sql unleashed
Postgre sql unleashedPostgre sql unleashed
Postgre sql unleashed
 
PGConf.ASIA 2017 Logical Replication Internals (English)
PGConf.ASIA 2017 Logical Replication Internals (English)PGConf.ASIA 2017 Logical Replication Internals (English)
PGConf.ASIA 2017 Logical Replication Internals (English)
 

Destaque

Carmelo De Grazia Suárez: Bancamiga promoviendo el consumo eficiente
Carmelo De Grazia Suárez: Bancamiga promoviendo el consumo eficienteCarmelo De Grazia Suárez: Bancamiga promoviendo el consumo eficiente
Carmelo De Grazia Suárez: Bancamiga promoviendo el consumo eficienteCarmelo De Grazia Suárez
 
SicuroIMS Iraq Threat Assessment 3 - 16 August 2016
SicuroIMS Iraq Threat Assessment 3 - 16 August 2016SicuroIMS Iraq Threat Assessment 3 - 16 August 2016
SicuroIMS Iraq Threat Assessment 3 - 16 August 2016Polina Shulyatova
 
12 carmelo de grazia suárez bancamiga está donde tú estás
12 carmelo de grazia suárez bancamiga está donde tú estás12 carmelo de grazia suárez bancamiga está donde tú estás
12 carmelo de grazia suárez bancamiga está donde tú estásCarmelo De Grazia Suárez
 
11 carmelo de grazia suarez servicios bancamiga
11 carmelo de grazia suarez servicios bancamiga11 carmelo de grazia suarez servicios bancamiga
11 carmelo de grazia suarez servicios bancamigaCarmelo De Grazia Suárez
 
Ryno CV- December2015.
Ryno CV- December2015.Ryno CV- December2015.
Ryno CV- December2015.Ryno Laubscher
 
Livro A Marca Chamada Você é indicado na sessão livros do jornal Empresas&amp...
Livro A Marca Chamada Você é indicado na sessão livros do jornal Empresas&amp...Livro A Marca Chamada Você é indicado na sessão livros do jornal Empresas&amp...
Livro A Marca Chamada Você é indicado na sessão livros do jornal Empresas&amp...DVS Editora
 
Cómo insertar imágenes en Blogger.com
Cómo insertar imágenes en Blogger.comCómo insertar imágenes en Blogger.com
Cómo insertar imágenes en Blogger.comJuan Ruffino
 
spring bed harga 2 jutaan
spring bed harga 2 jutaanspring bed harga 2 jutaan
spring bed harga 2 jutaansurabaya spring
 
Measuring mainstreaming progress, success and impact guidance
Measuring mainstreaming progress, success and impact guidanceMeasuring mainstreaming progress, success and impact guidance
Measuring mainstreaming progress, success and impact guidanceIIED
 
Buku Garis Panduan Penulisan Disertasi/Tesis 2015
Buku Garis Panduan Penulisan Disertasi/Tesis 2015Buku Garis Panduan Penulisan Disertasi/Tesis 2015
Buku Garis Panduan Penulisan Disertasi/Tesis 2015Venessa Joseph Sagar Singh
 

Destaque (13)

Carmelo De Grazia Suárez: Bancamiga promoviendo el consumo eficiente
Carmelo De Grazia Suárez: Bancamiga promoviendo el consumo eficienteCarmelo De Grazia Suárez: Bancamiga promoviendo el consumo eficiente
Carmelo De Grazia Suárez: Bancamiga promoviendo el consumo eficiente
 
Elements_Jul07_CGU_DMGray
Elements_Jul07_CGU_DMGrayElements_Jul07_CGU_DMGray
Elements_Jul07_CGU_DMGray
 
SicuroIMS Iraq Threat Assessment 3 - 16 August 2016
SicuroIMS Iraq Threat Assessment 3 - 16 August 2016SicuroIMS Iraq Threat Assessment 3 - 16 August 2016
SicuroIMS Iraq Threat Assessment 3 - 16 August 2016
 
12 carmelo de grazia suárez bancamiga está donde tú estás
12 carmelo de grazia suárez bancamiga está donde tú estás12 carmelo de grazia suárez bancamiga está donde tú estás
12 carmelo de grazia suárez bancamiga está donde tú estás
 
11 carmelo de grazia suarez servicios bancamiga
11 carmelo de grazia suarez servicios bancamiga11 carmelo de grazia suarez servicios bancamiga
11 carmelo de grazia suarez servicios bancamiga
 
Ryno CV- December2015.
Ryno CV- December2015.Ryno CV- December2015.
Ryno CV- December2015.
 
Livro A Marca Chamada Você é indicado na sessão livros do jornal Empresas&amp...
Livro A Marca Chamada Você é indicado na sessão livros do jornal Empresas&amp...Livro A Marca Chamada Você é indicado na sessão livros do jornal Empresas&amp...
Livro A Marca Chamada Você é indicado na sessão livros do jornal Empresas&amp...
 
Cómo insertar imágenes en Blogger.com
Cómo insertar imágenes en Blogger.comCómo insertar imágenes en Blogger.com
Cómo insertar imágenes en Blogger.com
 
spring bed harga 2 jutaan
spring bed harga 2 jutaanspring bed harga 2 jutaan
spring bed harga 2 jutaan
 
Measuring mainstreaming progress, success and impact guidance
Measuring mainstreaming progress, success and impact guidanceMeasuring mainstreaming progress, success and impact guidance
Measuring mainstreaming progress, success and impact guidance
 
Друзям меншим допормагаємо, птахи
Друзям меншим допормагаємо, птахиДрузям меншим допормагаємо, птахи
Друзям меншим допормагаємо, птахи
 
Buku Garis Panduan Penulisan Disertasi/Tesis 2015
Buku Garis Panduan Penulisan Disertasi/Tesis 2015Buku Garis Panduan Penulisan Disertasi/Tesis 2015
Buku Garis Panduan Penulisan Disertasi/Tesis 2015
 
La AstronomíA
La AstronomíALa AstronomíA
La AstronomíA
 

Semelhante a Techday2010 Postgresql9

10 Reasons to Start Your Analytics Project with PostgreSQL
10 Reasons to Start Your Analytics Project with PostgreSQL10 Reasons to Start Your Analytics Project with PostgreSQL
10 Reasons to Start Your Analytics Project with PostgreSQLSatoshi Nagayasu
 
PostgreSQL 9.6 새 기능 소개
PostgreSQL 9.6 새 기능 소개PostgreSQL 9.6 새 기능 소개
PostgreSQL 9.6 새 기능 소개PgDay.Seoul
 
What's New In PostgreSQL 9.4
What's New In PostgreSQL 9.4What's New In PostgreSQL 9.4
What's New In PostgreSQL 9.4Pavan Deolasee
 
PostgreSQL 8.4 TriLUG 2009-11-12
PostgreSQL 8.4 TriLUG 2009-11-12PostgreSQL 8.4 TriLUG 2009-11-12
PostgreSQL 8.4 TriLUG 2009-11-12Andrew Dunstan
 
Postgres Vienna DB Meetup 2014
Postgres Vienna DB Meetup 2014Postgres Vienna DB Meetup 2014
Postgres Vienna DB Meetup 2014Michael Renner
 
Countdown to PostgreSQL v9.5 - Foriegn Tables can be part of Inheritance Tree
Countdown to PostgreSQL v9.5 - Foriegn Tables can be part of Inheritance Tree Countdown to PostgreSQL v9.5 - Foriegn Tables can be part of Inheritance Tree
Countdown to PostgreSQL v9.5 - Foriegn Tables can be part of Inheritance Tree Ashnikbiz
 
Postgres & Redis Sitting in a Tree- Rimas Silkaitis, Heroku
Postgres & Redis Sitting in a Tree- Rimas Silkaitis, HerokuPostgres & Redis Sitting in a Tree- Rimas Silkaitis, Heroku
Postgres & Redis Sitting in a Tree- Rimas Silkaitis, HerokuRedis Labs
 
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...Alex Zaballa
 
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...Alex Zaballa
 
SQL Server Select Topics
SQL Server Select TopicsSQL Server Select Topics
SQL Server Select TopicsJay Coskey
 
Building node.js applications with Database Jones
Building node.js applications with Database JonesBuilding node.js applications with Database Jones
Building node.js applications with Database JonesJohn David Duncan
 
Drupal II: The SQL
Drupal II: The SQLDrupal II: The SQL
Drupal II: The SQLddiers
 
Oracle Database 12c - New Features for Developers and DBAs
Oracle Database 12c - New Features for Developers and DBAsOracle Database 12c - New Features for Developers and DBAs
Oracle Database 12c - New Features for Developers and DBAsAlex Zaballa
 
Oracle Database 12c - New Features for Developers and DBAs
Oracle Database 12c  - New Features for Developers and DBAsOracle Database 12c  - New Features for Developers and DBAs
Oracle Database 12c - New Features for Developers and DBAsAlex Zaballa
 

Semelhante a Techday2010 Postgresql9 (20)

10 Reasons to Start Your Analytics Project with PostgreSQL
10 Reasons to Start Your Analytics Project with PostgreSQL10 Reasons to Start Your Analytics Project with PostgreSQL
10 Reasons to Start Your Analytics Project with PostgreSQL
 
PostgreSQL 9.6 새 기능 소개
PostgreSQL 9.6 새 기능 소개PostgreSQL 9.6 새 기능 소개
PostgreSQL 9.6 새 기능 소개
 
What's New In PostgreSQL 9.4
What's New In PostgreSQL 9.4What's New In PostgreSQL 9.4
What's New In PostgreSQL 9.4
 
Get to know PostgreSQL!
Get to know PostgreSQL!Get to know PostgreSQL!
Get to know PostgreSQL!
 
PostgreSQL and PL/Java
PostgreSQL and PL/JavaPostgreSQL and PL/Java
PostgreSQL and PL/Java
 
PostgreSQL 8.4 TriLUG 2009-11-12
PostgreSQL 8.4 TriLUG 2009-11-12PostgreSQL 8.4 TriLUG 2009-11-12
PostgreSQL 8.4 TriLUG 2009-11-12
 
Postgres Vienna DB Meetup 2014
Postgres Vienna DB Meetup 2014Postgres Vienna DB Meetup 2014
Postgres Vienna DB Meetup 2014
 
Countdown to PostgreSQL v9.5 - Foriegn Tables can be part of Inheritance Tree
Countdown to PostgreSQL v9.5 - Foriegn Tables can be part of Inheritance Tree Countdown to PostgreSQL v9.5 - Foriegn Tables can be part of Inheritance Tree
Countdown to PostgreSQL v9.5 - Foriegn Tables can be part of Inheritance Tree
 
PostgreSQL
PostgreSQLPostgreSQL
PostgreSQL
 
Postgres & Redis Sitting in a Tree- Rimas Silkaitis, Heroku
Postgres & Redis Sitting in a Tree- Rimas Silkaitis, HerokuPostgres & Redis Sitting in a Tree- Rimas Silkaitis, Heroku
Postgres & Redis Sitting in a Tree- Rimas Silkaitis, Heroku
 
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
 
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
 
SQL Server Select Topics
SQL Server Select TopicsSQL Server Select Topics
SQL Server Select Topics
 
SQL Views
SQL ViewsSQL Views
SQL Views
 
Building node.js applications with Database Jones
Building node.js applications with Database JonesBuilding node.js applications with Database Jones
Building node.js applications with Database Jones
 
DataBase Management System Lab File
DataBase Management System Lab FileDataBase Management System Lab File
DataBase Management System Lab File
 
Drupal II: The SQL
Drupal II: The SQLDrupal II: The SQL
Drupal II: The SQL
 
Oracle Database 12c - New Features for Developers and DBAs
Oracle Database 12c - New Features for Developers and DBAsOracle Database 12c - New Features for Developers and DBAs
Oracle Database 12c - New Features for Developers and DBAs
 
Oracle Database 12c - New Features for Developers and DBAs
Oracle Database 12c  - New Features for Developers and DBAsOracle Database 12c  - New Features for Developers and DBAs
Oracle Database 12c - New Features for Developers and DBAs
 
chap 9 dbms.ppt
chap 9 dbms.pptchap 9 dbms.ppt
chap 9 dbms.ppt
 

Último

Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfOverkill Security
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamUiPathCommunity
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...apidays
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusZilliz
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 

Último (20)

Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 

Techday2010 Postgresql9

  • 1. What‘s new in PostgreSQL 9 Dan-Claudiu DRAGOŞ
  • 2. PostgreSQL 9 About PostgreSQL • This presentation was inspired by the sessions I‘ve attended at Fosdem 2010 • PostgreSQL means: – Standards followed closely – A true relational database – Complex, advanced features that puts it far ahead of its competition – The best tool to use for advanced database-based applications! • This comes at a cost: it can‘t compete with simpler database systems on poor hardware and writing „simple things“ tends to get harder 2
  • 3. PostgreSQL 9 Common Table Expressions • Available since version 8.4 • They are about defining an in-place data structure by the result of a query or a query combination • This data structure can then be queried further • Recursive join over this data structure is also possible • Some of this functionality was available before by using: • Views (named data structures stored into the database backend) • Subselects • The join recursion is a brand new feature 3
  • 4. PostgreSQL 9 Common Table Expressions • Basic usage WITH [RECURSIVE] name AS ( SELECT field1 FROM table WHERE field2=“abc” ) SELECT * FROM name ORDER BY field; 4
  • 5. PostgreSQL 9 Common Table Expressions • Join recursion – Assume we have the following corporate structure: -- department structure represented here is as follows: -- -- ROOT-+->A-+->B-+->C -- | | -- | +->D-+->F -- +->E-+->G – We want all the departments under A (or under any department, actually) 5
  • 6. PostgreSQL 9 Common Table Expressions • Join recursion CREATE TABLE department ( id INTEGER PRIMARY KEY, parent_department INTEGER REFERENCES department, name TEXT ); INSERT INTO department (id, parent_department, "name") VALUES (0, NULL, 'ROOT'), (1, 0, 'A'), (2, 1, 'B'), (3, 2, 'C'), (4, 2, 'D'), (5, 0, 'E'), (6, 4, 'F'), (7, 5, 'G'); 6
  • 7. PostgreSQL 9 Common Table Expressions • Join recursion WITH RECURSIVE subdepartment AS ( -- non-recursive term SELECT * FROM department WHERE name = 'A' UNION ALL -- recursive term SELECT d.* FROM department AS d JOIN subdepartment AS sd ON (d.parent_department = sd.id) ) SELECT * FROM subdepartment ORDER BY name; 7
  • 8. PostgreSQL 9 Common Table Expressions • Join recursion – The non-recursive term is optional – There are some restrictions when it comes to defining the recursive term: – No subquery using the recursive term (no double recursion) – No aggregate functions such as COUNT(*) – No HAVING, GROUP BY – No ORDER BY, no LIMIT – No FULL JOIN – The recursive term must be on the left hand side: » JOIN reference ON (recursiveterm.field = reference.field) • The database engine performs a brute-force, all-terms comparison so performance can sometimes be an issue 8
  • 9. PostgreSQL 9 Hot Standby and Streaming Replication • They are both about database synchronization • Hot Standby is a „push“ • Streaming Replication is a „pull“ • The issue at hand is duplicating the contents of a Master Database into one or more Slaves • Hot Standby means that every query ran on Master is also ran on the Slave; this also works for table locks! • Streaming replication means that every database transaction is requested by the Slave and then applied on it 9
  • 10. PostgreSQL 9 Deferrable Unique Constraints • This query sequence always fails: # CREATE TABLE test (a INT PRIMARY KEY); # INSERT INTO test values (1), (2); # UPDATE test SET a = a + 1; ERROR: duplicate key value violates unique constraint "test_pkey" DETAIL: Key (a)=(2) already exists. • What 9.0 version provides is that the uniqueness constraint may be checked after running the query, not as the query runs: # CREATE TABLE test (a INT PRIMARY KEY DEFERRABLE); 10
  • 11. PostgreSQL 9 Exclusion Constraints • Before 9.0, exclusion would be checked by using operator “=“ • Version 9.0 allows for a more complex approach # CREATE TABLE reservation ( room TEXT, speaker TEXT, during PERIOD); ALTER TABLE reservation ADD CONSTRAINT test_exclude EXCLUDE USING gist (room WITH =,during WITH &&); • The constraint is defined on 2 fields; the point is not having the same room reserved at the same time • The example uses 2 modules from „contrib“ (temporal and gist) 11
  • 12. PostgreSQL 9 Exclusion Constraints • Example using the previous table definition: # INSERT INTO reservation (speaker ,room, during) VALUES ( ‘Dan', ‘Flex Room', period('2010-12-10 12:00:00', '2010-12-10 13:00:00')); INSERT 0 1 # INSERT INTO reservation (speaker, room, during) VALUES ( ‘Catalin', ‘Presentation', period('2010-12-10 15:00:00', '2010-12-10 16:00:00')); INSERT 0 1 # INSERT INTO reservation (speaker ,room, during) VALUES ( ‘Andrei', ‘Flex Room', period('2010-12-10 12:30:00', '2010-12-10 13:00:00')); ERROR: conflicting key value violates exclusion constraint "test_exclude" DETAIL: Key (room, during)=(Flex Room, [2010-12-10 12:30:00+02, 2010-12- 10 13:00:00+02)) conflicts with existing key (room, during)=(Flex Room, [2010-12-10 12:00:00+02, 2010-12-10 13:00:00+02)). • This feature is available in PostgreSQL only 12
  • 13. Smaller enhancements • GRANT / REVOKE on Schemas – PostgreSQL has Databases -> Schemas -> Tables -> Fields – Until 9.0 you could grant (revoke) rights on Databases and Tables only – This functionality could be achieved before 9.0 by writing a script • Faster VACUUM FULL – This is the more or less equivalent to the OPTIMIZE query in MySQL – This command used to be pretty slow on large databases – In 9.0 it works by performing a copy of the database • Better 64bit support – 64bit binaries were already available on Linux – Windows native 64bit binary is the new thing in version 9.0 13
  • 14. PL/PgSQL enhancements • Unnamed functions – In 9.0 you can run code snippets in place – Before 9.0 you had to define a stored procedure and then call it DO language plpgsql $$ DECLARE vr record; BEGIN FOR vr IN SELECT tablename FROM pg_tables WHERE tableowner = ‘dan' AND schemaname NOT IN ('pg_catalog','information_schema') LOOP EXECUTE 'GRANT SELECT ON ' || vr.tablename || ' TO tester'; END LOOP; END $$; 14
  • 15. PL/PgSQL enhancements • Named parameter calls – Before 9.0 you had to provide all the function parameters and care for their order, as provided in the function definition – Version 8.4 added “default parameters”, allowing skipping certain parameters (they would be replaced with their default values) – Example function: CREATE FUNCTION test (a INT, b TEXT) RETURNS TEXT AS $$ DECLARE value TEXT; BEGIN value := 'a is ' || a::text || ' and b is ' || b; RETURN value; END; $$ LANGUAGE plpgsql; 15
  • 16. PL/PgSQL enhancements • Named parameter calls – Before 9.0 you would have called it this way: SELECT test(1,'foo'); test ------------------------- a is 1 and b is foo (1 row) – Version 9.0 allows this type of function call: SELECT test( b:='foo', a:=1); test ------------------------- a is 1 and b is foo (1 row) 16