SlideShare ist ein Scribd-Unternehmen logo
1 von 71
PostgreSQL 8.4 / Prolog




                        •   Want to play along?

                        •   PostgreSQL 8.4

                            •   git clone git://git.postgresql.org/git/postgresql.git

                            •   http://www.postgresql.org/docs/current/static/anoncvs.html

                            •   ./configure; make; make install;

                        •   Pagila Sample Database

                            •   http://pgfoundry.org/frs/?group_id=1000150&release_id=998




Sunday, April 5, 2009
No More Waiting
                  A Guide to PostgreSQL 8.4



                             / Presentation / Robert Treat



Sunday, April 5, 2009
A Little More Waiting
                  A Guide to PostgreSQL 8.4



                             / Presentation / Robert Treat



Sunday, April 5, 2009
A Little More Waiting
                  A Guide to Postgres 8.4



                              / Presentation / Robert Treat



Sunday, April 5, 2009
Postgres 8.4




                        •   Performance

                        •   Administration

                        •   PSQL

                        •   Development

                        •   Procedures




Sunday, April 5, 2009
Postgres 8.4




                        BUT FIRST!




Sunday, April 5, 2009
Postgres 8.4 / Recap




Sunday, April 5, 2009
Postgres 8.4 / Recap




                        •   8.3 Released (2008-02-04)




Sunday, April 5, 2009
Postgres 8.4 / Recap




                        •   8.3 Released (2008-02-04)

                        •   Commit Fests (March,May,July,September)




Sunday, April 5, 2009
Postgres 8.4 / Recap




                        •   8.3 Released (2008-02-04)

                        •   Commit Fests (March,May,July,September)

                        •   Feature Freeze (November)




Sunday, April 5, 2009
Postgres 8.4 / Recap




                        •   8.3 Released (2008-02-04)

                        •   Commit Fests (March,May,July,September)

                        •   Feature Freeze (November)

                        •   Exodus (December, January, February)




Sunday, April 5, 2009
Postgres 8.4 / Recap




                        •   8.3 Released (2008-02-04)

                        •   Commit Fests (March,May,July,September)

                        •   Feature Freeze (November)

                        •   Exodus (December, January, February)

                        •   Beta (April)




Sunday, April 5, 2009
Postgres 8.4 / Recap




                        •   8.3 Released (2008-02-04)

                        •   Commit Fests (March,May,July,September)

                        •   Feature Freeze (November)

                        •   Exodus (December, January, February)

                        •   Beta (April)

                        •   Release (May ? June)




Sunday, April 5, 2009
Postgres 8.4




                        •   Performance

                        •   Administration

                        •   PSQL

                        •   Development

                        •   Procedures




Sunday, April 5, 2009
Postgres 8.4 / Perf / Visibility Maps




                        •   Table = 1 or more files

                        •   File -> 8K pages

                        •   Keep track of pages that changed!

                        •   Improved Vacuum Performance

                            •   reduced cpu

                            •   reduced i/o




Sunday, April 5, 2009
Postgres 8.4 / Perf / Default Stats Target




                        •   default_statistics_target = 100

                        •   removed from tuning guide!




Sunday, April 5, 2009
Postgres 8.4 / Perf / Multi-Restore


                          •   pg_restore can spawn multiple processes

                          •   split restore amongst several workers

                          •   -j, specify number of workers




                        $ pg_dump -Fc pagila | pg_restore -d pajila -j 4
                        pg_restore: [custom archiver] cannot reopen stdin
                        pg_restore: [custom archiver] cannot reopen stdin
                        pg_restore: [archiver] worker process failed: exit code 1
                        pg_restore: [custom archiver] cannot reopen stdin
                        pg_restore: [custom archiver] cannot reopen stdin




Sunday, April 5, 2009
Postgres 8.4 / Perf / Wait, there’s more!




Sunday, April 5, 2009
Postgres 8.4 / Perf / Wait, there’s more!

                        •   improved optimizer statistics
                                                             •   i/o read-ahead for bitmap
                            calculations
                                                                 scans
                        •   improved statistics for full-
                                                             •   Hash Methods for
                            text columns
                                                                 DISTINCT / UNION /
                        •   new semi-join executor               INTERSECT / EXCEPTION
                            method
                                                             •   New GUC -
                        •   new anti-join executor               cursor_tuple_fraction
                            method
                                                             •   improved build speed for
                        •   improve performance of               hash indexes
                            text_position()
                                                             •   improved access speed for
                        •   reduced i/o frequency of stats       has indexes
                            info
                                                             •   reduced memory for trigger
                        •   constraint_exclusion =               handling
                            ‘partition’ option




Sunday, April 5, 2009
Postgres 8.4 / Perf / Wait, there’s more!




Sunday, April 5, 2009
Postgres 8.4




                        •   Performance

                        •   Administration

                        •   PSQL

                        •   Development

                        •   Procedures




Sunday, April 5, 2009
Postgres 8.4 / Admin / Free Space Map




                        •   New free-space-map implementation

                        •   No more shared memory, now kept on disk

                            •   remove GUC max_fsm_pages (former tuning guide option)

                            •   remove GUC max_fsm_relations (former tuning guide option)

                        •   add GUC vacuum_freeze_table_age

                            •   ignore visibility map, scan whole table

                                •   advanced relfrozenxid




Sunday, April 5, 2009
Postgres 8.4 / Admin / Termination




                        •   8.0 -> select pg_cancel_backend(pid)

                        •   8.4 -> select pg_terminate_backend(pid)




Sunday, April 5, 2009
Postgres 8.4 / Admin / Stats Temp File




                        •   pgstat.stat, stores statistics information

                        •   hi i/o load

                            •   very busy servers

                            •   large schema size

                        •   NEW GUC stats_temp_directory

                            •   point it at swap/memory filesystem




Sunday, April 5, 2009
Postgres 8.4 / Admin / Column Privileges
                        •   You can now grant access to specific columns

               pagila=# grant select (first_name, last_name) on actor_info to amber;
               GRANT
               pagila=# set session authorization amber;
               SET
               pagila=> select * from actor_info;
               ERROR: permission denied for relation actor_info
               STATEMENT: select * from actor_info;
               ERROR: permission denied for relation actor_info
               pagila=> select first_name, last_name from actor_info limit 2;
                first_name | last_name
               ------------+-----------
                PENELOPE   | GUINESS
                NICK       | WAHLBERG
               (2 rows)
               pagila=> z actor_info
                                             Access privileges
                Schema |    Name     | Type | Access privileges | Column access privileges
               --------+------------+------+-------------------+--------------------------
                public | actor_info | view |                    | first_name:
                                                                :   amber=r/postgres
                                                                : last_name:
                                                                :   amber=r/postgres




Sunday, April 5, 2009
Postgres 8.4 / Admin / Column Privileges
                        •   You can now grant access to specific columns

               pagila=# grant select (first_name, last_name) on actor_info to amber;
               GRANT
               pagila=# set session authorization amber;
               SET
               pagila=> select * from actor_info;
               ERROR: permission denied for relation actor_info
               STATEMENT: select * from actor_info;
               ERROR: permission denied for relation actor_info
               pagila=> select first_name, last_name from actor_info limit 2;
                first_name | last_name
               ------------+-----------
                PENELOPE   | GUINESS
                NICK       | WAHLBERG
               (2 rows)
               pagila=> z actor_info
                                             Access privileges
                Schema |    Name     | Type | Access privileges | Column access privileges
               --------+------------+------+-------------------+--------------------------
                public | actor_info | view |                    | first_name:
                                                                :   amber=r/postgres
                                                                : last_name:
                                                                :   amber=r/postgres



                             •   Stephen Frost - Saturday @ 2:30 - Column Level Privileges


Sunday, April 5, 2009
Postgres 8.4 / Admin / Add View Columns




                •       Add new columns to view

                •       Columns added to end of view

                •       Use CREATE OR REPLACE VIEW syntax

                •       bin/psql -U postgres -p 5484 pagila -s -f 84tut/01_add_view_columns.sql




Sunday, April 5, 2009
Postgres 8.4 / Admin / Track Functions

                        •   Track statistics on user functions

                        •   Controlled by GUC track_functions

                        •   none, pl, all


                 pagila=# set track_functions = 'pl';
                 SET
                 pagila=# select inventory_in_stock(2112);
                  inventory_in_stock
                 --------------------
                  t
                 (1 row)

                 pagila=# select * from pg_stat_user_functions;
                  funcid | schemaname |      funcname      | calls | total_time | self_time
                 --------+------------+--------------------+-------+------------+-----------
                   18047 | public     | inventory_in_stock |     1|          22 |        22
                 (1 row)




Sunday, April 5, 2009
Postgres 8.4 / Admin / Statement Stats


                        •   Contrib Module, track statistics

                        •   load shared library in postgresql.conf, load schema in database

                        •   tracks per user, database, query




          pagila=# select pg_stat_statements_reset();
           pg_stat_statements_reset
          --------------------------

          (1 row)

          pagila=# select * from pg_stat_statements;
           userid | dbid |                query                | calls | total_time | rows
          --------+-------+------------------------------------+-------+------------+------
               10 | 16384 | select pg_stat_statements_reset(); |     1|    0.000113 |    1
          (1 row)




Sunday, April 5, 2009
Postgres 8.4 / Admin / Auto Explain

                        •   Contrib Module, explain plan for slow queries

                        •   Can be loaded per session, or in postgresql.conf




                            pagila=# load 'auto_explain';
                            LOAD
                            pagila=# set auto_explain.log_min_duration = 2000;
                            SET
                            pagila=# select pg_sleep(3);
                            pg_sleep
                            ----------

                            (1 row)

                            ~~
                            LOG: duration: 3000.196 ms plan:
                                Result (cost=0.00..0.01 rows=1 width=0)
                            STATEMENT: select pg_sleep(3);




Sunday, April 5, 2009
Postgres 8.4 / Admin / Timed pgbench

                        •   Contrib Module, simple benchmarking tool

                        •   can now limit by time, rather than transactions

                        •   Greg Smith - Sunday @ 10:30 - Using and Abusing pgbench




                        robert$ bin/pgbench -p 5484 -T 60 pagila
                        starting vacuum...end.
                        transaction type: TPC-B (sort of)
                        scaling factor: 1
                        query mode: simple
                        number of clients: 1
                        duration: 60 s
                        number of transactions actually processed: 30774
                        tps = 512.908446 (including connections establishing)
                        tps = 512.956459 (excluding connections establishing)




Sunday, April 5, 2009
Postgres 8.4 / Admin / Explain Verbose


                        •   Now shows column output



          pagila=# explain analyze verbose select first_name, last_name, title from film_actor join actor using (actor_id) join film
          using (film_id);
                                                         QUERY PLAN
          ------------------------------------------------------------------------------------------------------------------------
           Hash Join (cost=83.00..314.83 rows=5462 width=28) (actual time=1.311..9.809 rows=5462 loops=1)
             Output: actor.first_name, actor.last_name, film.title
             Hash Cond: (film_actor.actor_id = actor.actor_id)
             -> Hash Join (cost=76.50..233.22 rows=5462 width=17) (actual time=1.065..5.818 rows=5462 loops=1)
                  Output: film_actor.actor_id, film.title
                  Hash Cond: (film_actor.film_id = film.film_id)
                  -> Seq Scan on film_actor (cost=0.00..81.62 rows=5462 width=4) (actual time=0.008..1.082 rows=5462 loops=1)
                       Output: film_actor.actor_id, film_actor.film_id, film_actor.last_update
                  -> Hash (cost=64.00..64.00 rows=1000 width=19) (actual time=1.046..1.046 rows=1000 loops=1)
                       Output: film.title, film.film_id
                       -> Seq Scan on film (cost=0.00..64.00 rows=1000 width=19) (actual time=0.003..0.488 rows=1000 loops=1)
                            Output: film.title, film.film_id
             -> Hash (cost=4.00..4.00 rows=200 width=17) (actual time=0.238..0.238 rows=200 loops=1)
                  Output: actor.first_name, actor.last_name, actor.actor_id
                  -> Seq Scan on actor (cost=0.00..4.00 rows=200 width=17) (actual time=0.011..0.072 rows=200 loops=1)
                       Output: actor.first_name, actor.last_name, actor.actor_id




Sunday, April 5, 2009
Postgres 8.4 / Admin / Explain Verbose
                        •   See, select * is evil :-)

          pagila=# explain analyze verbose select * from film_actor join actor using (actor_id) join film using (film_id);
               QUERY PLAN
          ---------------------------------------------------------------------------------------------------------------------------------------------------------
           Hash Join (cost=83.00..314.83 rows=5462 width=423) (actual time=1.974..15.409 rows=5462 loops=1)
             Output: film.film_id, actor.actor_id, film_actor.last_update, actor.first_name, actor.last_name, actor.last_update,
          film.title, film.description, film.release_year, film.language_id, film.original_language_id, film.rental_duration, film.rental_rate,
          film.length, film.replacement_cost, film.rating, film.last_update, film.special_features, film.fulltext
             Hash Cond: (film_actor.actor_id = actor.actor_id)
             -> Hash Join (cost=76.50..233.22 rows=5462 width=400) (actual time=1.806..9.730 rows=5462 loops=1)
                Output: film_actor.last_update, film_actor.actor_id, film.film_id, film.title, film.description, film.release_year,
          film.language_id, film.original_language_id, film.rental_duration, film.rental_rate, film.length, film.replacement_cost,
          film.rating, film.last_update, film.special_features, film.fulltext
                  Hash Cond: (film_actor.film_id = film.film_id)
                  -> Seq Scan on film_actor (cost=0.00..81.62 rows=5462 width=12) (actual time=0.007..1.263 rows=5462 loops=1)
                     Output: film_actor.actor_id, film_actor.film_id, film_actor.last_update
                  -> Hash (cost=64.00..64.00 rows=1000 width=390) (actual time=1.787..1.787 rows=1000 loops=1)
                     Output: film.film_id, film.title, film.description, film.release_year, film.language_id, film.original_language_id,
          film.rental_duration, film.rental_rate, film.length, film.replacement_cost, film.rating, film.last_update, film.special_features,
          film.fulltext
                        -> Seq Scan on film (cost=0.00..64.00 rows=1000 width=390) (actual time=0.003..0.429 rows=1000 loops=1)
                           Output: film.film_id, film.title, film.description, film.release_year, film.language_id, film.original_language_id,
          film.rental_duration, film.rental_rate, film.length, film.replacement_cost, film.rating, film.last_update, film.special_features,
          film.fulltext
             -> Hash (cost=4.00..4.00 rows=200 width=25) (actual time=0.157..0.157 rows=200 loops=1)
                Output: actor.actor_id, actor.first_name, actor.last_name, actor.last_update
                -> Seq Scan on actor (cost=0.00..4.00 rows=200 width=25) (actual time=0.009..0.049 rows=200 loops=1)
                    Output: actor.actor_id, actor.first_name, actor.last_name, actor.last_update




Sunday, April 5, 2009
Postgres 8.4 / Admin / Wait, there’s more!




Sunday, April 5, 2009
Postgres 8.4 / Admin / Wait, there’s more!

                                                             •   Improved support for krb5,
                        •   report all queries involved in       gssapi, sspi
                            a deadlock error
                                                             •   Read only GUC segment_size
                        •   Database Level LC_Collate/
                                                             •   Read only GUC
                            LC_Type
                                                                 wal_block_size
                        •   ALTER SEQUENCE
                                                             •   Read only GUC
                            RESTART command
                                                                 wal_segment_size
                        •   TRUNCATE TABLE
                                                             •   Allow static logfile name
                            RESTART IDENTITY

                                                             •
                        •                                        Pre-Parse pg_hba.conf before
                            multi-column GIN indexes
                                                                 reload
                        •   pg_conf_load_time()
                                                             •   improved SSL certificate
                            function
                                                                 handling
                        •   GUC
                                                             •   pg_settings now shows
                            track_activity_query_size
                                                                 available options for guc with



Sunday, April 5, 2009
Postgres 8.4 / Admin / Wait, there’s more!




Sunday, April 5, 2009
Postgres 8.4




                        •   Performance

                        •   Administration

                        •   PSQL

                        •   Development

                        •   Procedures




Sunday, April 5, 2009
Postgres 8.4 / PSQL / Function Editing

                        •   df function_name

                        •   df+ function_name

                            •   shows function definition

                        •   ef function_name

                            •   opens fully formed function definition in $editor




                                      CREATE OR REPLACE FUNCTION public.last_updated()
                                       RETURNS trigger
                                       LANGUAGE plpgsql
                                      AS $function$
                                      BEGIN
                                         NEW.last_update = CURRENT_TIMESTAMP;
                                         RETURN NEW;
                                      END $function$




Sunday, April 5, 2009
Postgres 8.4 / PSQL / List Your Objects


                        •                                  •
                            dX shows only user objects         dXS includes system objects

                        •                                  •
                            df list user functions             dfS list all functions


       pagila=# df
                                      List of functions
        Schema |            Name            | Result data type | Argument data types
       --------+----------------------------+------------------+---------------------------------------
        public | _group_concat              | text             | text, text
        public | film_in_stock              | SETOF integer    | p_film_id integer, p_store_id integer,
                                                               : OUT p_film_count integer
        public | film_not_in_stock          | SETOF integer    | p_film_id integer, p_store_id integer,
                                                               : OUT p_film_count integer
        public | get_customer_balance       | numeric          | p_customer_id integer,
                                                               : p_effective_date timestamp
        public | inventory_held_by_customer | integer          | p_inventory_id integer
        public | inventory_in_stock         | boolean          | p_inventory_id integer
        public | last_day                   | date             | timestamp without time zone
        public | last_updated               | trigger          |
        public | rewards_report             | SETOF customer   | min_monthly_purchases integer,
                                                               : min_dollar_amount_purchased numeric
       (9 rows)




Sunday, April 5, 2009
Postgres 8.4 / PSQL / Sequence Info

                        •   Sequence details more easily accessible




                        pagila=# d actor_actor_id_seq
                             Sequence quot;public.actor_actor_id_seqquot;
                            Column     | Type    |        Value
                        ---------------+---------+---------------------
                         sequence_name | name    | actor_actor_id_seq
                         last_value    | bigint | 200
                         start_value   | bigint | 1
                         increment_by | bigint | 1
                         max_value     | bigint | 9223372036854775807
                         min_value     | bigint | 1
                         cache_value   | bigint | 1
                         log_cnt       | bigint | 0
                         is_cycled     | boolean | f
                         is_called     | boolean | t




Sunday, April 5, 2009
Postgres 8.4 / PSQL / Enum Values



                                •   Display enum options when displaying enum types




                        pagila=# dT+ mpaa_rating
                                                  List of data types
                        Schema |    Name     | Internal name | Size | Elements | Description
                        -------+-------------+---------------+------+----------+-------------
                        public | mpaa_rating | mpaa_rating   |4      |G        |
                                                                     : PG
                                                                     : PG-13
                                                                     :R
                                                                     : NC-17




Sunday, April 5, 2009
Postgres 8.4 / PSQL / Table Size

                        pagila=# dt+
                                                    List of relations
                         Schema |        Name      | Type | Owner      |    Size    | Description
                        --------+------------------+-------+-----------+------------+-------------
                         public | actor            | table | postgres | 16 kB       |
                         public | address          | table | postgres | 56 kB       |
                         public | category         | table | postgres | 8192 bytes |
                         public | city             | table | postgres | 32 kB       |
                         public | country          | table | postgres | 8192 bytes |
                         public | customer         | table | postgres | 64 kB       |
                         public | film             | table | postgres | 432 kB      |
                         public | film_actor       | table | postgres | 216 kB      |
                         public | film_category    | table | postgres | 40 kB       |
                         public | inventory        | table | postgres | 200 kB      |
                         public | language         | table | postgres | 8192 bytes |
                         public | payment          | table | postgres | 0 bytes     |
                         public | payment_p2007_01 | table | postgres | 72 kB       |
                         public | payment_p2007_02 | table | postgres | 136 kB      |
                         public | payment_p2007_03 | table | postgres | 336 kB      |
                         public | payment_p2007_04 | table | postgres | 400 kB      |
                         public | payment_p2007_05 | table | postgres | 16 kB       |
                         public | payment_p2007_06 | table | postgres | 0 bytes     |
                         public | rental           | table | postgres | 1072 kB     |
                         public | staff            | table | postgres | 8192 bytes |
                         public | store            | table | postgres | 8192 bytes |




Sunday, April 5, 2009
Postgres 8.4 / PSQL / Foreign Keys

                                      •     Referencing tables now displayed in d


          pagila=# d store
                                Table quot;public.storequot;
                Column       |     Type     |            Modifiers
          -------------------+--------------+----------------------------------
           store_id          | integer      | not null default nextval('store_store_id_seq')
           manager_staff_id | smallint      | not null
           address_id        | smallint     | not null
           last_update       | timestamp    | not null default now()
          Indexes:
              quot;store_pkeyquot; PRIMARY KEY, btree (store_id)
              quot;idx_unq_manager_staff_idquot; UNIQUE, btree (manager_staff_id)
          Foreign-key constraints:
              quot;store_address_id_fkeyquot; FOREIGN KEY (address_id) REFERENCES address(address_id)
              quot;store_manager_staff_id_fkeyquot; FOREIGN KEY (manager_staff_id) REFERENCES staff(staff_id)
          Referenced by:
            quot;customer_store_id_fkeyquot; IN customer FOREIGN KEY (store_id)
               REFERENCES store(store_id) ON UPDATE CASCADE ON DELETE RESTRICT
            quot;inventory_store_id_fkeyquot; IN inventory FOREIGN KEY (store_id)
               REFERENCES store(store_id) ON UPDATE CASCADE ON DELETE RESTRICT
            quot;staff_store_id_fkeyquot; IN staff FOREIGN KEY (store_id) REFERENCES store(store_id)
          Triggers:
              last_updated BEFORE UPDATE ON store FOR EACH ROW EXECUTE PROCEDURE last_updated()




Sunday, April 5, 2009
Postgres 8.4 / PSQL / Wait, there’s more!




Sunday, April 5, 2009
Postgres 8.4 / PSQL / Wait, there’s more!




                        •   Improved handling of long lines and tab characters

                        •   Better control of timing

                        •   Improved tab completion support for tables in multiple schemas

                        •   Column storage type display

                        •   Add tablespace and database size information to l




Sunday, April 5, 2009
Postgres 8.4 / PSQL / Wait, there’s more!




Sunday, April 5, 2009
Postgres 8.4




                        •   Performance

                        •   Administration

                        •   PSQL

                        •   Development

                        •   Procedures




Sunday, April 5, 2009
Postgres 8.4 / Dev / WITH

                                     •          Common Table Expression (aka CTE, WITH queries)

                                     •          Declare WITH before query

                                     •          WITH computed once, before rest of query

          pagila=# with epic_films as (select film_id, array_agg(first_name ||' '||
          last_name) as featuring from film join film_actor using (film_id) join actor
          using (actor_id) group by film_id )
          select * from epic_films where array_upper(featuring,1) > 12 ;
            film_id |                                                                                                  featuring
          ---------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
              606 | {quot;HELEN VOIGHTquot;,quot;KEVIN BLOOMquot;,quot;TIM HACKMANquot;,quot;GOLDIE BRODYquot;,quot;ANGELINA ASTAIREquot;,quot;SPENCER PECKquot;,quot;WALTER TORNquot;,quot;SIDNEY CROWE
          quot;,quot;GINA DEGENERESquot;,quot;RUSSELL BACALLquot;,quot;DAN STREEPquot;,quot;ROCK DUKAKISquot;,quot;AUDREY BAILEYquot;}
              714 | {quot;JENNIFER DAVISquot;,quot;LUCILLE TRACYquot;,quot;BURT DUKAKISquot;,quot;REESE KILMERquot;,quot;CARMEN HUNTquot;,quot;JUDE CRUISEquot;,quot;ANGELA HUDSONquot;,quot;SPENCER DEP
          Pquot;,quot;HARRISON BALEquot;,quot;HARVEY HOPEquot;,quot;NICK DEGENERESquot;,quot;DEBBIE AKROYDquot;,quot;THORA TEMPLEquot;}
              508 | {quot;WOODY HOFFMANquot;,quot;VAL BOLGERquot;,quot;REESE KILMERquot;,quot;JULIA BARRYMOREquot;,quot;MENA TEMPLEquot;,quot;CHRISTIAN NEESONquot;,quot;BURT POSEYquot;,quot;SCARLETT D
          AMONquot;,quot;WALTER TORNquot;,quot;CAMERON ZELLWEGERquot;,quot;LUCILLE DEEquot;,quot;FAY WINSLETquot;,quot;JAYNE NOLTEquot;,quot;MENA HOPPERquot;,quot;JULIA ZELLWEGERquot;}
              146 | {quot;JOHNNY LOLLOBRIGIDAquot;,quot;LUCILLE TRACYquot;,quot;ELVIS MARXquot;,quot;SISSY SOBIESKIquot;,quot;VAL BOLGERquot;,quot;SUSAN DAVISquot;,quot;RUSSELL TEMPLEquot;,quot;AL GAR
          LANDquot;,quot;NICK DEGENERESquot;,quot;OLYMPIA PFEIFFERquot;,quot;LISA MONROEquot;,quot;HUMPHREY GARLANDquot;,quot;ROCK DUKAKISquot;}
              249 | {quot;NICK WAHLBERGquot;,quot;JODIE DEGENERESquot;,quot;CARMEN HUNTquot;,quot;CAMERON WRAYquot;,quot;MICHELLE MCCONAUGHEYquot;,quot;SEAN WILLIAMSquot;,quot;BEN WILLISquot;,quot;GRE
          G CHAPLINquot;,quot;MORGAN HOPKINSquot;,quot;DARYL CRAWFORDquot;,quot;MORGAN WILLIAMSquot;,quot;IAN TANDYquot;,quot;REESE WESTquot;}
               87 | {quot;ED CHASEquot;,quot;JENNIFER DAVISquot;,quot;UMA WOODquot;,quot;FRED COSTNERquot;,quot;KIRSTEN PALTROWquot;,quot;SANDRA PECKquot;,quot;DAN HARRISquot;,quot;RAY JOHANSSONquot;,quot;KEN
          NETH PESCIquot;,quot;CHRIS BRIDGESquot;,quot;WARREN JACKMANquot;,quot;HUMPHREY GARLANDquot;,quot;AUDREY BAILEYquot;}
              188 | {quot;SISSY SOBIESKIquot;,quot;WOODY JOLIEquot;,quot;MEG HAWKEquot;,quot;RUSSELL BACALLquot;,quot;MORGAN MCDORMANDquot;,quot;ALBERT NOLTEquot;,quot;CATE HARRISquot;,quot;RUSSELL TE
          MPLEquot;,quot;VIVIEN BASINGERquot;,quot;HARVEY HOPEquot;,quot;WILL WILSONquot;,quot;ALAN DREYFUSSquot;,quot;GENE MCKELLENquot;}
          (7 rows)




Sunday, April 5, 2009
Postgres 8.4 / Dev / WITH Recursive

                        pagila=# WITH recursive Fib (i, j) AS (
                             VALUES (0, 1)
                             UNION ALL
                             SELECT (i + j), (i + j) + j
                             FROM Fib
                             WHERE (i + j) < 1000
                        )
                        SELECT i FROM Fib
                        UNION ALL
                        SELECT j FROM Fib ORDER BY i;
                          i
                        ------
                            0
                            1
                            1
                            2
                            3
                            5
                            8
                           13
                           21
                           34
                           55
                           89
                          144
                          233
                          377
                          610
                          987
                         1597
                        (18 rows)




Sunday, April 5, 2009
Postgres 8.4 / Dev / WITH Recursive

                        pagila=# WITH recursive Fib (i, j) AS (
                             VALUES (0, 1)
                             UNION ALL
                             SELECT (i + j), (i + j) + j
                             FROM Fib
                             WHERE (i + j) < 1000
                        )
                        SELECT i FROM Fib
                        UNION ALL
                        SELECT j FROM Fib ORDER BY i;
                          i
                        ------
                            0
                            1
                            1
                            2
                            3
                            5
                            8
                           13
                           21
                           34
                           55
                           89
                          144
                          233
                          377
                          610
                          987
                         1597
                        (18 rows)




                                    •   David Fetter - Saturday @ 4:30 - Trees & More



Sunday, April 5, 2009
Postgres 8.4 / Dev / Rank / Old




Sunday, April 5, 2009
Postgres 8.4 / Dev / Rank / New

                        pagila=# select * from (
                        with cte as (
                           select first_name, last_name, store_id, sum(amount) as total
                           from payment join customer using (customer_id) group by
                           first_name, last_name, store_id
                        )
                           select first_name, last_name, store_id, total,
                           rank() over (partition by store_id order by total desc)
                           from cte ) x where rank <= 3;

                         first_name | last_name | store_id | total | rank
                        ------------+-----------+----------+--------+------
                         ELEANOR    | HUNT      |        1 | 216.54 |    1
                         CLARA      | SHAW      |        1 | 195.58 |    2
                         TOMMY      | COLLAZO   |        1 | 186.62 |    3
                         KARL       | SEAL      |        2 | 221.55 |    1
                         MARION     | SNYDER    |        2 | 194.61 |    2
                         RHONDA     | KENNEDY   |        2 | 194.61 |    2
                        (6 rows)




Sunday, April 5, 2009
Postgres 8.4 / Dev / Rank / New

                        pagila=# select * from (
                        with cte as (
                           select first_name, last_name, store_id, sum(amount) as total
                           from payment join customer using (customer_id) group by
                           first_name, last_name, store_id
                        )
                           select first_name, last_name, store_id, total,
                           rank() over (partition by store_id order by total desc)
                           from cte ) x where rank <= 3;

                         first_name | last_name | store_id | total | rank
                        ------------+-----------+----------+--------+------
                         ELEANOR    | HUNT      |        1 | 216.54 |    1
                         CLARA      | SHAW      |        1 | 195.58 |    2
                         TOMMY      | COLLAZO   |        1 | 186.62 |    3
                         KARL       | SEAL      |        2 | 221.55 |    1
                         MARION     | SNYDER    |        2 | 194.61 |    2
                         RHONDA     | KENNEDY   |        2 | 194.61 |    2
                        (6 rows)



                              •   David Fetter - Sunday @ 11:00 - Window Functions


Sunday, April 5, 2009
Postgres 8.4 / Dev / Limit

                                      •   LIMIT can be based on a subquery


                        pagila=# SELECT title FROM film ORDER BY random()
                        pagila-# LIMIT (SELECT count(*)/10 FROM film WHERE rating = 'G');
                               title
                        ---------------------
                         NONE SPIKING
                         PULP BEVERLY
                         SUPERFLY TRIP
                         LOCK REAR
                         STATE WASTELAND
                         FEUD FROGMEN
                         FEVER EMPIRE
                         LEATHERNECKS DWARFS
                         RANGE MOONWALKER
                         CHOCOLAT HARRY
                         MODERN DORADO
                         SHREK LICENSE
                         NUTS TIES
                         EMPIRE MALKOVICH
                         LOSE INCH
                         DADDY PITTSBURGH
                         DOZEN LION
                        (17 rows)



Sunday, April 5, 2009
Postgres 8.4 / Dev / FTS Partial Match


                        •   Searching partial words and word stems together




         pagila=# select title, description from film where fulltext @@ to_tsquery('dog:*')
                  except
                  select title, description from film where fulltext @@ to_tsquery('dog');

             title     |                        description
         --------------+---------------------------------------------------------------
          ARABIA DOGMA | A Touching Epistle of a Madman And a Mad Cow who must Defeat a
                       : Student in Nigeria
          DOGMA FAMILY | A Brilliant Character Study of a Database Administrator And a
                       : Monkey who must Succumb a Astronaut in New Orleans
         (2 rows)




Sunday, April 5, 2009
Postgres 8.4 / Dev / Table Command

                             •   Select all columns for output

                             •   SQL Spec Command



                 pagila=# table language;
                  language_id |     name      |     last_update
                 -------------+---------------+---------------------
                            1 | English       | 2006-02-15 10:02:19
                            2 | Italian       | 2006-02-15 10:02:19
                            3 | Japanese      | 2006-02-15 10:02:19
                            4 | Mandarin      | 2006-02-15 10:02:19
                            5 | French        | 2006-02-15 10:02:19
                            6 | German        | 2006-02-15 10:02:19




Sunday, April 5, 2009
Postgres 8.4 / Dev / Table Command

                             •       Select all columns for output

                             •       SQL Spec Command



                 pagila=# table language;
                  language_id |     name      |     last_update
                 -------------+---------------+---------------------
                            1 | English       | 2006-02-15 10:02:19
                            2 | Italian       | 2006-02-15 10:02:19
                            3 | Japanese      | 2006-02-15 10:02:19
                            4 | Mandarin      | 2006-02-15 10:02:19
                            5 | French        | 2006-02-15 10:02:19
                            6 | German        | 2006-02-15 10:02:19




                                 •     Evil, but catchy




Sunday, April 5, 2009
Postgres 8.4 / Dev / Generate Time

                            •   Time based generate_series()



                        pagila=# select * from generate_series(
                                 now() - '5 minutes'::interval,
                                 now(),
                                 '50 seconds'::interval);
                                 generate_series
                        -------------------------------
                         2009-04-03 12:49:40.209094-04
                         2009-04-03 12:50:30.209094-04
                         2009-04-03 12:51:20.209094-04
                         2009-04-03 12:52:10.209094-04
                         2009-04-03 12:53:00.209094-04
                         2009-04-03 12:53:50.209094-04
                         2009-04-03 12:54:40.209094-04
                        (7 rows)




Sunday, April 5, 2009
Postgres 8.4 / Dev / Wait, there’s more!




Sunday, April 5, 2009
Postgres 8.4 / Dev / Wait, there’s more!



                        •   make column alias keyword quot;asquot; optional (per sql spec)

                        •   sql standard interval handling

                        •   Support for statement level triggers for TRUNCATE command

                        •   suppress_redundent_updates() trigger

                        •   Case Insensitive Text module

                        •   generate_subscripts() function

                        •   array_aggregate() function

                        •   unnest() function




Sunday, April 5, 2009
Postgres 8.4 / Dev / Wait, there’s more!




Sunday, April 5, 2009
Postgres 8.4




                        •   Performance

                        •   Administration

                        •   PSQL

                        •   Development

                        •   Procedures




Sunday, April 5, 2009
Postgres 8.4 / Proc / CASE Control


                        •   CASE as a control structure

                        •   Simplify code




        pagila=# CREATE FUNCTION kidsafe(v_title text) RETURNS text
        AS $$
        BEGIN
            CASE (select rating from film where title = v_title)
               WHEN 'NC-17','R' THEN RETURN 'no';
                WHEN 'PG-13' THEN RETURN 'maybe';
                WHEN 'PG','G' THEN RETURN 'yes';
            END CASE;
        END;
        $$ LANGUAGE plpgsql;

        pagila=# select kidsafe('EVE RESURRECTION'), kidsafe('SUNRISE LEAGUE'), kidsafe('AIRPORT POLLOCK'); kidsafe |
        kidsafe | kidsafe ---------+---------+---------
         yes | maybe | no
        (1 row)




Sunday, April 5, 2009
Postgres 8.4 / Proc / Variable Args
                        •        Allows passing 1..n arguments

                        •        Declare argument “variadic”

                        •        Available for all languages (handled by parser)

          pagila=# create or replace function twist
          (variadic v_ints int[], out v_param int)
          returns setof int as $$
          declare v_i int;
          begin
                for v_i in select generate_subscripts(v_ints, 1) loop
                      v_param := v_i; return next;
                end loop;
                return;
              $$ language plpgsql;
          end;
          CREATE FUNCTION
          pagila=# select twist(1); twist
          -------
              1
          (1 row)

          pagila=# select twist(1,2,3); twist
          -------
              1
              2
              3
          (3 rows)




Sunday, April 5, 2009
Postgres 8.4 / Proc / Default Args

                        •     Function arguments can now have default values


          pagila=# create or replace function fancy_last_day
          (timestamp default current_timestamp::timestamp)
          returns date
          immutable
          language sql
          as $$
          SELECT CASE
               WHEN EXTRACT(MONTH FROM $1) = 12 THEN
                   (((EXTRACT(YEAR FROM $1) + 1) operator(pg_catalog.||) '-01-01')::date - INTERVAL '1 day')::date
              ELSE
                   ((EXTRACT(YEAR FROM $1) operator(pg_catalog.||) '-' operator(pg_catalog.||)
                   (EXTRACT(MONTH FROM $1) + 1) operator(pg_catalog.||) '-01')::date - INTERVAL '1 day')::date
              END
          $$;
          CREATE FUNCTION

          pagila=# select fancy_last_day('2112-12-21 21:12:21.12'::timestamp);
          -[ RECORD 1 ]-----+-----------
          fancy_last_day | 2112-12-31

          pagila=# select fancy_last_day();
          -[ RECORD 1 ]-----+-----------
          fancy_last_day | 2009-04-30




Sunday, April 5, 2009
Postgres 8.4 / Proc / Wait...




Sunday, April 5, 2009
Postgres 8.4 / Proc / Wait...




                        •   RETURNS TABLE for plpgsql functions

                        •   Support HINT, DETAIL, and SQLSTATE in RAISE command for
                            plpgsql

                        •   RETURN QUERY EXECUTE support in plpgsql

                        •   EXECUTE USING for plpgsql

                        •   allow srf functions to be called in select clause for plpgsql

                        •   quote_nullable()




Sunday, April 5, 2009
Postgres 8.4 / Proc / Wait...




Sunday, April 5, 2009
Postgres 8.4 / Upgrades




                        •   dump / restore required

                        •   more than two dozen incompatibilities

                            •   read the release notes!




Sunday, April 5, 2009
Postgres 8.4 / More Info




                        •   http://www.depesz.com/

                        •   http://wiki.postgresql.org/

                        •   http://www.xzilla.net

                        •   PGCon, Ottawa, Canada, May 19th - 22nd




Sunday, April 5, 2009
Thank you for listening.



                           / Presentation



Sunday, April 5, 2009

Weitere ähnliche Inhalte

Ähnlich wie Intro to Postgres 8.4 Tutorial

Profiling and optimizing go programs
Profiling and optimizing go programsProfiling and optimizing go programs
Profiling and optimizing go programsBadoo Development
 
Ryan Campbell - OpenFlux and Flex 4
Ryan Campbell - OpenFlux and Flex 4Ryan Campbell - OpenFlux and Flex 4
Ryan Campbell - OpenFlux and Flex 4360|Conferences
 
TYPO3 CMS 6.2 LTS Workshop T3DD13
TYPO3 CMS 6.2 LTS Workshop T3DD13TYPO3 CMS 6.2 LTS Workshop T3DD13
TYPO3 CMS 6.2 LTS Workshop T3DD13Ernesto Baschny
 
Enterprise class deployment for GeoServer and GeoWebcache Optimizing perform...
Enterprise class deployment  for GeoServer and GeoWebcache Optimizing perform...Enterprise class deployment  for GeoServer and GeoWebcache Optimizing perform...
Enterprise class deployment for GeoServer and GeoWebcache Optimizing perform...GeoSolutions
 
PostgreSQL Portland Performance Practice Project - Database Test 2 Series Ove...
PostgreSQL Portland Performance Practice Project - Database Test 2 Series Ove...PostgreSQL Portland Performance Practice Project - Database Test 2 Series Ove...
PostgreSQL Portland Performance Practice Project - Database Test 2 Series Ove...Mark Wong
 
Web Standards and Accessibility
Web Standards and AccessibilityWeb Standards and Accessibility
Web Standards and AccessibilityNick DeNardis
 
Joomla Template Development
Joomla Template DevelopmentJoomla Template Development
Joomla Template DevelopmentLinda Coonen
 
Ev3rt and mruby-ev3rt 2018ver
Ev3rt and mruby-ev3rt 2018verEv3rt and mruby-ev3rt 2018ver
Ev3rt and mruby-ev3rt 2018veryamanekko
 
Groovy Testing Sep2009
Groovy Testing Sep2009Groovy Testing Sep2009
Groovy Testing Sep2009Paul King
 
Drupal 6 Theming using the Zen Theme
Drupal 6 Theming using the Zen ThemeDrupal 6 Theming using the Zen Theme
Drupal 6 Theming using the Zen Themeinfowonders
 
Filesystem Performance from a Database Perspective
Filesystem Performance from a Database PerspectiveFilesystem Performance from a Database Perspective
Filesystem Performance from a Database PerspectiveMark Wong
 
Groovy Testing Aug2009
Groovy Testing Aug2009Groovy Testing Aug2009
Groovy Testing Aug2009guest4a266c
 
MacRuby - When objective-c and Ruby meet
MacRuby - When objective-c and Ruby meetMacRuby - When objective-c and Ruby meet
MacRuby - When objective-c and Ruby meetMatt Aimonetti
 
Oxente on Rails 2009
Oxente on Rails 2009Oxente on Rails 2009
Oxente on Rails 2009Fabio Akita
 
Twisted presentation & Jamendo usecases
Twisted presentation & Jamendo usecasesTwisted presentation & Jamendo usecases
Twisted presentation & Jamendo usecasesSylvain Zimmer
 

Ähnlich wie Intro to Postgres 8.4 Tutorial (20)

Profiling and optimizing go programs
Profiling and optimizing go programsProfiling and optimizing go programs
Profiling and optimizing go programs
 
PostgreSQL 8.4 Update
PostgreSQL 8.4 UpdatePostgreSQL 8.4 Update
PostgreSQL 8.4 Update
 
Ryan Campbell - OpenFlux and Flex 4
Ryan Campbell - OpenFlux and Flex 4Ryan Campbell - OpenFlux and Flex 4
Ryan Campbell - OpenFlux and Flex 4
 
TYPO3 CMS 6.2 LTS Workshop T3DD13
TYPO3 CMS 6.2 LTS Workshop T3DD13TYPO3 CMS 6.2 LTS Workshop T3DD13
TYPO3 CMS 6.2 LTS Workshop T3DD13
 
Enterprise class deployment for GeoServer and GeoWebcache Optimizing perform...
Enterprise class deployment  for GeoServer and GeoWebcache Optimizing perform...Enterprise class deployment  for GeoServer and GeoWebcache Optimizing perform...
Enterprise class deployment for GeoServer and GeoWebcache Optimizing perform...
 
PostgreSQL Portland Performance Practice Project - Database Test 2 Series Ove...
PostgreSQL Portland Performance Practice Project - Database Test 2 Series Ove...PostgreSQL Portland Performance Practice Project - Database Test 2 Series Ove...
PostgreSQL Portland Performance Practice Project - Database Test 2 Series Ove...
 
Parrot Compiler Tools
Parrot Compiler ToolsParrot Compiler Tools
Parrot Compiler Tools
 
Web Standards and Accessibility
Web Standards and AccessibilityWeb Standards and Accessibility
Web Standards and Accessibility
 
Joomla Template Development
Joomla Template DevelopmentJoomla Template Development
Joomla Template Development
 
Ev3rt and mruby-ev3rt 2018ver
Ev3rt and mruby-ev3rt 2018verEv3rt and mruby-ev3rt 2018ver
Ev3rt and mruby-ev3rt 2018ver
 
Groovy Testing Sep2009
Groovy Testing Sep2009Groovy Testing Sep2009
Groovy Testing Sep2009
 
Drupal 6 Theming using the Zen Theme
Drupal 6 Theming using the Zen ThemeDrupal 6 Theming using the Zen Theme
Drupal 6 Theming using the Zen Theme
 
Django Testing
Django TestingDjango Testing
Django Testing
 
Filesystem Performance from a Database Perspective
Filesystem Performance from a Database PerspectiveFilesystem Performance from a Database Perspective
Filesystem Performance from a Database Perspective
 
Groovy Testing Aug2009
Groovy Testing Aug2009Groovy Testing Aug2009
Groovy Testing Aug2009
 
8.4 Upcoming Features
8.4 Upcoming Features 8.4 Upcoming Features
8.4 Upcoming Features
 
Apache Solr
Apache SolrApache Solr
Apache Solr
 
MacRuby - When objective-c and Ruby meet
MacRuby - When objective-c and Ruby meetMacRuby - When objective-c and Ruby meet
MacRuby - When objective-c and Ruby meet
 
Oxente on Rails 2009
Oxente on Rails 2009Oxente on Rails 2009
Oxente on Rails 2009
 
Twisted presentation & Jamendo usecases
Twisted presentation & Jamendo usecasesTwisted presentation & Jamendo usecases
Twisted presentation & Jamendo usecases
 

Mehr von Robert Treat

Advanced Int->Bigint Conversions
Advanced Int->Bigint ConversionsAdvanced Int->Bigint Conversions
Advanced Int->Bigint ConversionsRobert Treat
 
Explaining Explain
Explaining ExplainExplaining Explain
Explaining ExplainRobert Treat
 
the-lost-art-of-plpgsql
the-lost-art-of-plpgsqlthe-lost-art-of-plpgsql
the-lost-art-of-plpgsqlRobert Treat
 
Managing Chaos In Production: Testing vs Monitoring
Managing Chaos In Production: Testing vs MonitoringManaging Chaos In Production: Testing vs Monitoring
Managing Chaos In Production: Testing vs MonitoringRobert Treat
 
Managing Databases In A DevOps Environment 2016
Managing Databases In A DevOps Environment 2016Managing Databases In A DevOps Environment 2016
Managing Databases In A DevOps Environment 2016Robert Treat
 
Less Alarming Alerts - SRECon 2016
Less Alarming Alerts - SRECon 2016 Less Alarming Alerts - SRECon 2016
Less Alarming Alerts - SRECon 2016 Robert Treat
 
What Ops Can Learn From Design
What Ops Can Learn From DesignWhat Ops Can Learn From Design
What Ops Can Learn From DesignRobert Treat
 
Postgres 9.4 First Look
Postgres 9.4 First LookPostgres 9.4 First Look
Postgres 9.4 First LookRobert Treat
 
Less Alarming Alerts!
Less Alarming Alerts!Less Alarming Alerts!
Less Alarming Alerts!Robert Treat
 
Past, Present, and Pachyderm - All Things Open - 2013
Past, Present, and Pachyderm - All Things Open - 2013Past, Present, and Pachyderm - All Things Open - 2013
Past, Present, and Pachyderm - All Things Open - 2013Robert Treat
 
Big Bad "Upgraded" Postgres
Big Bad "Upgraded" PostgresBig Bad "Upgraded" Postgres
Big Bad "Upgraded" PostgresRobert Treat
 
Managing Databases In A DevOps Environment
Managing Databases In A DevOps EnvironmentManaging Databases In A DevOps Environment
Managing Databases In A DevOps EnvironmentRobert Treat
 
The Essential PostgreSQL.conf
The Essential PostgreSQL.confThe Essential PostgreSQL.conf
The Essential PostgreSQL.confRobert Treat
 
Advanced WAL File Management With OmniPITR
Advanced WAL File Management With OmniPITRAdvanced WAL File Management With OmniPITR
Advanced WAL File Management With OmniPITRRobert Treat
 
Scaling with Postgres (Highload++ 2010)
Scaling with Postgres (Highload++ 2010)Scaling with Postgres (Highload++ 2010)
Scaling with Postgres (Highload++ 2010)Robert Treat
 
Intro to Postgres 9 Tutorial
Intro to Postgres 9 TutorialIntro to Postgres 9 Tutorial
Intro to Postgres 9 TutorialRobert Treat
 
Database Scalability Patterns
Database Scalability PatternsDatabase Scalability Patterns
Database Scalability PatternsRobert Treat
 
Scaling With Postgres
Scaling With PostgresScaling With Postgres
Scaling With PostgresRobert Treat
 

Mehr von Robert Treat (20)

Advanced Int->Bigint Conversions
Advanced Int->Bigint ConversionsAdvanced Int->Bigint Conversions
Advanced Int->Bigint Conversions
 
Explaining Explain
Explaining ExplainExplaining Explain
Explaining Explain
 
the-lost-art-of-plpgsql
the-lost-art-of-plpgsqlthe-lost-art-of-plpgsql
the-lost-art-of-plpgsql
 
Managing Chaos In Production: Testing vs Monitoring
Managing Chaos In Production: Testing vs MonitoringManaging Chaos In Production: Testing vs Monitoring
Managing Chaos In Production: Testing vs Monitoring
 
Managing Databases In A DevOps Environment 2016
Managing Databases In A DevOps Environment 2016Managing Databases In A DevOps Environment 2016
Managing Databases In A DevOps Environment 2016
 
Less Alarming Alerts - SRECon 2016
Less Alarming Alerts - SRECon 2016 Less Alarming Alerts - SRECon 2016
Less Alarming Alerts - SRECon 2016
 
What Ops Can Learn From Design
What Ops Can Learn From DesignWhat Ops Can Learn From Design
What Ops Can Learn From Design
 
Postgres 9.4 First Look
Postgres 9.4 First LookPostgres 9.4 First Look
Postgres 9.4 First Look
 
Less Alarming Alerts!
Less Alarming Alerts!Less Alarming Alerts!
Less Alarming Alerts!
 
Past, Present, and Pachyderm - All Things Open - 2013
Past, Present, and Pachyderm - All Things Open - 2013Past, Present, and Pachyderm - All Things Open - 2013
Past, Present, and Pachyderm - All Things Open - 2013
 
Big Bad "Upgraded" Postgres
Big Bad "Upgraded" PostgresBig Bad "Upgraded" Postgres
Big Bad "Upgraded" Postgres
 
Managing Databases In A DevOps Environment
Managing Databases In A DevOps EnvironmentManaging Databases In A DevOps Environment
Managing Databases In A DevOps Environment
 
The Essential PostgreSQL.conf
The Essential PostgreSQL.confThe Essential PostgreSQL.conf
The Essential PostgreSQL.conf
 
Pro Postgres 9
Pro Postgres 9Pro Postgres 9
Pro Postgres 9
 
Advanced WAL File Management With OmniPITR
Advanced WAL File Management With OmniPITRAdvanced WAL File Management With OmniPITR
Advanced WAL File Management With OmniPITR
 
Scaling with Postgres (Highload++ 2010)
Scaling with Postgres (Highload++ 2010)Scaling with Postgres (Highload++ 2010)
Scaling with Postgres (Highload++ 2010)
 
Intro to Postgres 9 Tutorial
Intro to Postgres 9 TutorialIntro to Postgres 9 Tutorial
Intro to Postgres 9 Tutorial
 
Check Please!
Check Please!Check Please!
Check Please!
 
Database Scalability Patterns
Database Scalability PatternsDatabase Scalability Patterns
Database Scalability Patterns
 
Scaling With Postgres
Scaling With PostgresScaling With Postgres
Scaling With Postgres
 

Kürzlich hochgeladen

How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 

Kürzlich hochgeladen (20)

DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 

Intro to Postgres 8.4 Tutorial

  • 1. PostgreSQL 8.4 / Prolog • Want to play along? • PostgreSQL 8.4 • git clone git://git.postgresql.org/git/postgresql.git • http://www.postgresql.org/docs/current/static/anoncvs.html • ./configure; make; make install; • Pagila Sample Database • http://pgfoundry.org/frs/?group_id=1000150&release_id=998 Sunday, April 5, 2009
  • 2. No More Waiting A Guide to PostgreSQL 8.4 / Presentation / Robert Treat Sunday, April 5, 2009
  • 3. A Little More Waiting A Guide to PostgreSQL 8.4 / Presentation / Robert Treat Sunday, April 5, 2009
  • 4. A Little More Waiting A Guide to Postgres 8.4 / Presentation / Robert Treat Sunday, April 5, 2009
  • 5. Postgres 8.4 • Performance • Administration • PSQL • Development • Procedures Sunday, April 5, 2009
  • 6. Postgres 8.4 BUT FIRST! Sunday, April 5, 2009
  • 7. Postgres 8.4 / Recap Sunday, April 5, 2009
  • 8. Postgres 8.4 / Recap • 8.3 Released (2008-02-04) Sunday, April 5, 2009
  • 9. Postgres 8.4 / Recap • 8.3 Released (2008-02-04) • Commit Fests (March,May,July,September) Sunday, April 5, 2009
  • 10. Postgres 8.4 / Recap • 8.3 Released (2008-02-04) • Commit Fests (March,May,July,September) • Feature Freeze (November) Sunday, April 5, 2009
  • 11. Postgres 8.4 / Recap • 8.3 Released (2008-02-04) • Commit Fests (March,May,July,September) • Feature Freeze (November) • Exodus (December, January, February) Sunday, April 5, 2009
  • 12. Postgres 8.4 / Recap • 8.3 Released (2008-02-04) • Commit Fests (March,May,July,September) • Feature Freeze (November) • Exodus (December, January, February) • Beta (April) Sunday, April 5, 2009
  • 13. Postgres 8.4 / Recap • 8.3 Released (2008-02-04) • Commit Fests (March,May,July,September) • Feature Freeze (November) • Exodus (December, January, February) • Beta (April) • Release (May ? June) Sunday, April 5, 2009
  • 14. Postgres 8.4 • Performance • Administration • PSQL • Development • Procedures Sunday, April 5, 2009
  • 15. Postgres 8.4 / Perf / Visibility Maps • Table = 1 or more files • File -> 8K pages • Keep track of pages that changed! • Improved Vacuum Performance • reduced cpu • reduced i/o Sunday, April 5, 2009
  • 16. Postgres 8.4 / Perf / Default Stats Target • default_statistics_target = 100 • removed from tuning guide! Sunday, April 5, 2009
  • 17. Postgres 8.4 / Perf / Multi-Restore • pg_restore can spawn multiple processes • split restore amongst several workers • -j, specify number of workers $ pg_dump -Fc pagila | pg_restore -d pajila -j 4 pg_restore: [custom archiver] cannot reopen stdin pg_restore: [custom archiver] cannot reopen stdin pg_restore: [archiver] worker process failed: exit code 1 pg_restore: [custom archiver] cannot reopen stdin pg_restore: [custom archiver] cannot reopen stdin Sunday, April 5, 2009
  • 18. Postgres 8.4 / Perf / Wait, there’s more! Sunday, April 5, 2009
  • 19. Postgres 8.4 / Perf / Wait, there’s more! • improved optimizer statistics • i/o read-ahead for bitmap calculations scans • improved statistics for full- • Hash Methods for text columns DISTINCT / UNION / • new semi-join executor INTERSECT / EXCEPTION method • New GUC - • new anti-join executor cursor_tuple_fraction method • improved build speed for • improve performance of hash indexes text_position() • improved access speed for • reduced i/o frequency of stats has indexes info • reduced memory for trigger • constraint_exclusion = handling ‘partition’ option Sunday, April 5, 2009
  • 20. Postgres 8.4 / Perf / Wait, there’s more! Sunday, April 5, 2009
  • 21. Postgres 8.4 • Performance • Administration • PSQL • Development • Procedures Sunday, April 5, 2009
  • 22. Postgres 8.4 / Admin / Free Space Map • New free-space-map implementation • No more shared memory, now kept on disk • remove GUC max_fsm_pages (former tuning guide option) • remove GUC max_fsm_relations (former tuning guide option) • add GUC vacuum_freeze_table_age • ignore visibility map, scan whole table • advanced relfrozenxid Sunday, April 5, 2009
  • 23. Postgres 8.4 / Admin / Termination • 8.0 -> select pg_cancel_backend(pid) • 8.4 -> select pg_terminate_backend(pid) Sunday, April 5, 2009
  • 24. Postgres 8.4 / Admin / Stats Temp File • pgstat.stat, stores statistics information • hi i/o load • very busy servers • large schema size • NEW GUC stats_temp_directory • point it at swap/memory filesystem Sunday, April 5, 2009
  • 25. Postgres 8.4 / Admin / Column Privileges • You can now grant access to specific columns pagila=# grant select (first_name, last_name) on actor_info to amber; GRANT pagila=# set session authorization amber; SET pagila=> select * from actor_info; ERROR: permission denied for relation actor_info STATEMENT: select * from actor_info; ERROR: permission denied for relation actor_info pagila=> select first_name, last_name from actor_info limit 2; first_name | last_name ------------+----------- PENELOPE | GUINESS NICK | WAHLBERG (2 rows) pagila=> z actor_info Access privileges Schema | Name | Type | Access privileges | Column access privileges --------+------------+------+-------------------+-------------------------- public | actor_info | view | | first_name: : amber=r/postgres : last_name: : amber=r/postgres Sunday, April 5, 2009
  • 26. Postgres 8.4 / Admin / Column Privileges • You can now grant access to specific columns pagila=# grant select (first_name, last_name) on actor_info to amber; GRANT pagila=# set session authorization amber; SET pagila=> select * from actor_info; ERROR: permission denied for relation actor_info STATEMENT: select * from actor_info; ERROR: permission denied for relation actor_info pagila=> select first_name, last_name from actor_info limit 2; first_name | last_name ------------+----------- PENELOPE | GUINESS NICK | WAHLBERG (2 rows) pagila=> z actor_info Access privileges Schema | Name | Type | Access privileges | Column access privileges --------+------------+------+-------------------+-------------------------- public | actor_info | view | | first_name: : amber=r/postgres : last_name: : amber=r/postgres • Stephen Frost - Saturday @ 2:30 - Column Level Privileges Sunday, April 5, 2009
  • 27. Postgres 8.4 / Admin / Add View Columns • Add new columns to view • Columns added to end of view • Use CREATE OR REPLACE VIEW syntax • bin/psql -U postgres -p 5484 pagila -s -f 84tut/01_add_view_columns.sql Sunday, April 5, 2009
  • 28. Postgres 8.4 / Admin / Track Functions • Track statistics on user functions • Controlled by GUC track_functions • none, pl, all pagila=# set track_functions = 'pl'; SET pagila=# select inventory_in_stock(2112); inventory_in_stock -------------------- t (1 row) pagila=# select * from pg_stat_user_functions; funcid | schemaname | funcname | calls | total_time | self_time --------+------------+--------------------+-------+------------+----------- 18047 | public | inventory_in_stock | 1| 22 | 22 (1 row) Sunday, April 5, 2009
  • 29. Postgres 8.4 / Admin / Statement Stats • Contrib Module, track statistics • load shared library in postgresql.conf, load schema in database • tracks per user, database, query pagila=# select pg_stat_statements_reset(); pg_stat_statements_reset -------------------------- (1 row) pagila=# select * from pg_stat_statements; userid | dbid | query | calls | total_time | rows --------+-------+------------------------------------+-------+------------+------ 10 | 16384 | select pg_stat_statements_reset(); | 1| 0.000113 | 1 (1 row) Sunday, April 5, 2009
  • 30. Postgres 8.4 / Admin / Auto Explain • Contrib Module, explain plan for slow queries • Can be loaded per session, or in postgresql.conf pagila=# load 'auto_explain'; LOAD pagila=# set auto_explain.log_min_duration = 2000; SET pagila=# select pg_sleep(3); pg_sleep ---------- (1 row) ~~ LOG: duration: 3000.196 ms plan: Result (cost=0.00..0.01 rows=1 width=0) STATEMENT: select pg_sleep(3); Sunday, April 5, 2009
  • 31. Postgres 8.4 / Admin / Timed pgbench • Contrib Module, simple benchmarking tool • can now limit by time, rather than transactions • Greg Smith - Sunday @ 10:30 - Using and Abusing pgbench robert$ bin/pgbench -p 5484 -T 60 pagila starting vacuum...end. transaction type: TPC-B (sort of) scaling factor: 1 query mode: simple number of clients: 1 duration: 60 s number of transactions actually processed: 30774 tps = 512.908446 (including connections establishing) tps = 512.956459 (excluding connections establishing) Sunday, April 5, 2009
  • 32. Postgres 8.4 / Admin / Explain Verbose • Now shows column output pagila=# explain analyze verbose select first_name, last_name, title from film_actor join actor using (actor_id) join film using (film_id); QUERY PLAN ------------------------------------------------------------------------------------------------------------------------ Hash Join (cost=83.00..314.83 rows=5462 width=28) (actual time=1.311..9.809 rows=5462 loops=1) Output: actor.first_name, actor.last_name, film.title Hash Cond: (film_actor.actor_id = actor.actor_id) -> Hash Join (cost=76.50..233.22 rows=5462 width=17) (actual time=1.065..5.818 rows=5462 loops=1) Output: film_actor.actor_id, film.title Hash Cond: (film_actor.film_id = film.film_id) -> Seq Scan on film_actor (cost=0.00..81.62 rows=5462 width=4) (actual time=0.008..1.082 rows=5462 loops=1) Output: film_actor.actor_id, film_actor.film_id, film_actor.last_update -> Hash (cost=64.00..64.00 rows=1000 width=19) (actual time=1.046..1.046 rows=1000 loops=1) Output: film.title, film.film_id -> Seq Scan on film (cost=0.00..64.00 rows=1000 width=19) (actual time=0.003..0.488 rows=1000 loops=1) Output: film.title, film.film_id -> Hash (cost=4.00..4.00 rows=200 width=17) (actual time=0.238..0.238 rows=200 loops=1) Output: actor.first_name, actor.last_name, actor.actor_id -> Seq Scan on actor (cost=0.00..4.00 rows=200 width=17) (actual time=0.011..0.072 rows=200 loops=1) Output: actor.first_name, actor.last_name, actor.actor_id Sunday, April 5, 2009
  • 33. Postgres 8.4 / Admin / Explain Verbose • See, select * is evil :-) pagila=# explain analyze verbose select * from film_actor join actor using (actor_id) join film using (film_id); QUERY PLAN --------------------------------------------------------------------------------------------------------------------------------------------------------- Hash Join (cost=83.00..314.83 rows=5462 width=423) (actual time=1.974..15.409 rows=5462 loops=1) Output: film.film_id, actor.actor_id, film_actor.last_update, actor.first_name, actor.last_name, actor.last_update, film.title, film.description, film.release_year, film.language_id, film.original_language_id, film.rental_duration, film.rental_rate, film.length, film.replacement_cost, film.rating, film.last_update, film.special_features, film.fulltext Hash Cond: (film_actor.actor_id = actor.actor_id) -> Hash Join (cost=76.50..233.22 rows=5462 width=400) (actual time=1.806..9.730 rows=5462 loops=1) Output: film_actor.last_update, film_actor.actor_id, film.film_id, film.title, film.description, film.release_year, film.language_id, film.original_language_id, film.rental_duration, film.rental_rate, film.length, film.replacement_cost, film.rating, film.last_update, film.special_features, film.fulltext Hash Cond: (film_actor.film_id = film.film_id) -> Seq Scan on film_actor (cost=0.00..81.62 rows=5462 width=12) (actual time=0.007..1.263 rows=5462 loops=1) Output: film_actor.actor_id, film_actor.film_id, film_actor.last_update -> Hash (cost=64.00..64.00 rows=1000 width=390) (actual time=1.787..1.787 rows=1000 loops=1) Output: film.film_id, film.title, film.description, film.release_year, film.language_id, film.original_language_id, film.rental_duration, film.rental_rate, film.length, film.replacement_cost, film.rating, film.last_update, film.special_features, film.fulltext -> Seq Scan on film (cost=0.00..64.00 rows=1000 width=390) (actual time=0.003..0.429 rows=1000 loops=1) Output: film.film_id, film.title, film.description, film.release_year, film.language_id, film.original_language_id, film.rental_duration, film.rental_rate, film.length, film.replacement_cost, film.rating, film.last_update, film.special_features, film.fulltext -> Hash (cost=4.00..4.00 rows=200 width=25) (actual time=0.157..0.157 rows=200 loops=1) Output: actor.actor_id, actor.first_name, actor.last_name, actor.last_update -> Seq Scan on actor (cost=0.00..4.00 rows=200 width=25) (actual time=0.009..0.049 rows=200 loops=1) Output: actor.actor_id, actor.first_name, actor.last_name, actor.last_update Sunday, April 5, 2009
  • 34. Postgres 8.4 / Admin / Wait, there’s more! Sunday, April 5, 2009
  • 35. Postgres 8.4 / Admin / Wait, there’s more! • Improved support for krb5, • report all queries involved in gssapi, sspi a deadlock error • Read only GUC segment_size • Database Level LC_Collate/ • Read only GUC LC_Type wal_block_size • ALTER SEQUENCE • Read only GUC RESTART command wal_segment_size • TRUNCATE TABLE • Allow static logfile name RESTART IDENTITY • • Pre-Parse pg_hba.conf before multi-column GIN indexes reload • pg_conf_load_time() • improved SSL certificate function handling • GUC • pg_settings now shows track_activity_query_size available options for guc with Sunday, April 5, 2009
  • 36. Postgres 8.4 / Admin / Wait, there’s more! Sunday, April 5, 2009
  • 37. Postgres 8.4 • Performance • Administration • PSQL • Development • Procedures Sunday, April 5, 2009
  • 38. Postgres 8.4 / PSQL / Function Editing • df function_name • df+ function_name • shows function definition • ef function_name • opens fully formed function definition in $editor CREATE OR REPLACE FUNCTION public.last_updated() RETURNS trigger LANGUAGE plpgsql AS $function$ BEGIN NEW.last_update = CURRENT_TIMESTAMP; RETURN NEW; END $function$ Sunday, April 5, 2009
  • 39. Postgres 8.4 / PSQL / List Your Objects • • dX shows only user objects dXS includes system objects • • df list user functions dfS list all functions pagila=# df List of functions Schema | Name | Result data type | Argument data types --------+----------------------------+------------------+--------------------------------------- public | _group_concat | text | text, text public | film_in_stock | SETOF integer | p_film_id integer, p_store_id integer, : OUT p_film_count integer public | film_not_in_stock | SETOF integer | p_film_id integer, p_store_id integer, : OUT p_film_count integer public | get_customer_balance | numeric | p_customer_id integer, : p_effective_date timestamp public | inventory_held_by_customer | integer | p_inventory_id integer public | inventory_in_stock | boolean | p_inventory_id integer public | last_day | date | timestamp without time zone public | last_updated | trigger | public | rewards_report | SETOF customer | min_monthly_purchases integer, : min_dollar_amount_purchased numeric (9 rows) Sunday, April 5, 2009
  • 40. Postgres 8.4 / PSQL / Sequence Info • Sequence details more easily accessible pagila=# d actor_actor_id_seq Sequence quot;public.actor_actor_id_seqquot; Column | Type | Value ---------------+---------+--------------------- sequence_name | name | actor_actor_id_seq last_value | bigint | 200 start_value | bigint | 1 increment_by | bigint | 1 max_value | bigint | 9223372036854775807 min_value | bigint | 1 cache_value | bigint | 1 log_cnt | bigint | 0 is_cycled | boolean | f is_called | boolean | t Sunday, April 5, 2009
  • 41. Postgres 8.4 / PSQL / Enum Values • Display enum options when displaying enum types pagila=# dT+ mpaa_rating List of data types Schema | Name | Internal name | Size | Elements | Description -------+-------------+---------------+------+----------+------------- public | mpaa_rating | mpaa_rating |4 |G | : PG : PG-13 :R : NC-17 Sunday, April 5, 2009
  • 42. Postgres 8.4 / PSQL / Table Size pagila=# dt+ List of relations Schema | Name | Type | Owner | Size | Description --------+------------------+-------+-----------+------------+------------- public | actor | table | postgres | 16 kB | public | address | table | postgres | 56 kB | public | category | table | postgres | 8192 bytes | public | city | table | postgres | 32 kB | public | country | table | postgres | 8192 bytes | public | customer | table | postgres | 64 kB | public | film | table | postgres | 432 kB | public | film_actor | table | postgres | 216 kB | public | film_category | table | postgres | 40 kB | public | inventory | table | postgres | 200 kB | public | language | table | postgres | 8192 bytes | public | payment | table | postgres | 0 bytes | public | payment_p2007_01 | table | postgres | 72 kB | public | payment_p2007_02 | table | postgres | 136 kB | public | payment_p2007_03 | table | postgres | 336 kB | public | payment_p2007_04 | table | postgres | 400 kB | public | payment_p2007_05 | table | postgres | 16 kB | public | payment_p2007_06 | table | postgres | 0 bytes | public | rental | table | postgres | 1072 kB | public | staff | table | postgres | 8192 bytes | public | store | table | postgres | 8192 bytes | Sunday, April 5, 2009
  • 43. Postgres 8.4 / PSQL / Foreign Keys • Referencing tables now displayed in d pagila=# d store Table quot;public.storequot; Column | Type | Modifiers -------------------+--------------+---------------------------------- store_id | integer | not null default nextval('store_store_id_seq') manager_staff_id | smallint | not null address_id | smallint | not null last_update | timestamp | not null default now() Indexes: quot;store_pkeyquot; PRIMARY KEY, btree (store_id) quot;idx_unq_manager_staff_idquot; UNIQUE, btree (manager_staff_id) Foreign-key constraints: quot;store_address_id_fkeyquot; FOREIGN KEY (address_id) REFERENCES address(address_id) quot;store_manager_staff_id_fkeyquot; FOREIGN KEY (manager_staff_id) REFERENCES staff(staff_id) Referenced by: quot;customer_store_id_fkeyquot; IN customer FOREIGN KEY (store_id) REFERENCES store(store_id) ON UPDATE CASCADE ON DELETE RESTRICT quot;inventory_store_id_fkeyquot; IN inventory FOREIGN KEY (store_id) REFERENCES store(store_id) ON UPDATE CASCADE ON DELETE RESTRICT quot;staff_store_id_fkeyquot; IN staff FOREIGN KEY (store_id) REFERENCES store(store_id) Triggers: last_updated BEFORE UPDATE ON store FOR EACH ROW EXECUTE PROCEDURE last_updated() Sunday, April 5, 2009
  • 44. Postgres 8.4 / PSQL / Wait, there’s more! Sunday, April 5, 2009
  • 45. Postgres 8.4 / PSQL / Wait, there’s more! • Improved handling of long lines and tab characters • Better control of timing • Improved tab completion support for tables in multiple schemas • Column storage type display • Add tablespace and database size information to l Sunday, April 5, 2009
  • 46. Postgres 8.4 / PSQL / Wait, there’s more! Sunday, April 5, 2009
  • 47. Postgres 8.4 • Performance • Administration • PSQL • Development • Procedures Sunday, April 5, 2009
  • 48. Postgres 8.4 / Dev / WITH • Common Table Expression (aka CTE, WITH queries) • Declare WITH before query • WITH computed once, before rest of query pagila=# with epic_films as (select film_id, array_agg(first_name ||' '|| last_name) as featuring from film join film_actor using (film_id) join actor using (actor_id) group by film_id ) select * from epic_films where array_upper(featuring,1) > 12 ; film_id | featuring ---------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 606 | {quot;HELEN VOIGHTquot;,quot;KEVIN BLOOMquot;,quot;TIM HACKMANquot;,quot;GOLDIE BRODYquot;,quot;ANGELINA ASTAIREquot;,quot;SPENCER PECKquot;,quot;WALTER TORNquot;,quot;SIDNEY CROWE quot;,quot;GINA DEGENERESquot;,quot;RUSSELL BACALLquot;,quot;DAN STREEPquot;,quot;ROCK DUKAKISquot;,quot;AUDREY BAILEYquot;} 714 | {quot;JENNIFER DAVISquot;,quot;LUCILLE TRACYquot;,quot;BURT DUKAKISquot;,quot;REESE KILMERquot;,quot;CARMEN HUNTquot;,quot;JUDE CRUISEquot;,quot;ANGELA HUDSONquot;,quot;SPENCER DEP Pquot;,quot;HARRISON BALEquot;,quot;HARVEY HOPEquot;,quot;NICK DEGENERESquot;,quot;DEBBIE AKROYDquot;,quot;THORA TEMPLEquot;} 508 | {quot;WOODY HOFFMANquot;,quot;VAL BOLGERquot;,quot;REESE KILMERquot;,quot;JULIA BARRYMOREquot;,quot;MENA TEMPLEquot;,quot;CHRISTIAN NEESONquot;,quot;BURT POSEYquot;,quot;SCARLETT D AMONquot;,quot;WALTER TORNquot;,quot;CAMERON ZELLWEGERquot;,quot;LUCILLE DEEquot;,quot;FAY WINSLETquot;,quot;JAYNE NOLTEquot;,quot;MENA HOPPERquot;,quot;JULIA ZELLWEGERquot;} 146 | {quot;JOHNNY LOLLOBRIGIDAquot;,quot;LUCILLE TRACYquot;,quot;ELVIS MARXquot;,quot;SISSY SOBIESKIquot;,quot;VAL BOLGERquot;,quot;SUSAN DAVISquot;,quot;RUSSELL TEMPLEquot;,quot;AL GAR LANDquot;,quot;NICK DEGENERESquot;,quot;OLYMPIA PFEIFFERquot;,quot;LISA MONROEquot;,quot;HUMPHREY GARLANDquot;,quot;ROCK DUKAKISquot;} 249 | {quot;NICK WAHLBERGquot;,quot;JODIE DEGENERESquot;,quot;CARMEN HUNTquot;,quot;CAMERON WRAYquot;,quot;MICHELLE MCCONAUGHEYquot;,quot;SEAN WILLIAMSquot;,quot;BEN WILLISquot;,quot;GRE G CHAPLINquot;,quot;MORGAN HOPKINSquot;,quot;DARYL CRAWFORDquot;,quot;MORGAN WILLIAMSquot;,quot;IAN TANDYquot;,quot;REESE WESTquot;} 87 | {quot;ED CHASEquot;,quot;JENNIFER DAVISquot;,quot;UMA WOODquot;,quot;FRED COSTNERquot;,quot;KIRSTEN PALTROWquot;,quot;SANDRA PECKquot;,quot;DAN HARRISquot;,quot;RAY JOHANSSONquot;,quot;KEN NETH PESCIquot;,quot;CHRIS BRIDGESquot;,quot;WARREN JACKMANquot;,quot;HUMPHREY GARLANDquot;,quot;AUDREY BAILEYquot;} 188 | {quot;SISSY SOBIESKIquot;,quot;WOODY JOLIEquot;,quot;MEG HAWKEquot;,quot;RUSSELL BACALLquot;,quot;MORGAN MCDORMANDquot;,quot;ALBERT NOLTEquot;,quot;CATE HARRISquot;,quot;RUSSELL TE MPLEquot;,quot;VIVIEN BASINGERquot;,quot;HARVEY HOPEquot;,quot;WILL WILSONquot;,quot;ALAN DREYFUSSquot;,quot;GENE MCKELLENquot;} (7 rows) Sunday, April 5, 2009
  • 49. Postgres 8.4 / Dev / WITH Recursive pagila=# WITH recursive Fib (i, j) AS ( VALUES (0, 1) UNION ALL SELECT (i + j), (i + j) + j FROM Fib WHERE (i + j) < 1000 ) SELECT i FROM Fib UNION ALL SELECT j FROM Fib ORDER BY i; i ------ 0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 (18 rows) Sunday, April 5, 2009
  • 50. Postgres 8.4 / Dev / WITH Recursive pagila=# WITH recursive Fib (i, j) AS ( VALUES (0, 1) UNION ALL SELECT (i + j), (i + j) + j FROM Fib WHERE (i + j) < 1000 ) SELECT i FROM Fib UNION ALL SELECT j FROM Fib ORDER BY i; i ------ 0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 (18 rows) • David Fetter - Saturday @ 4:30 - Trees & More Sunday, April 5, 2009
  • 51. Postgres 8.4 / Dev / Rank / Old Sunday, April 5, 2009
  • 52. Postgres 8.4 / Dev / Rank / New pagila=# select * from ( with cte as ( select first_name, last_name, store_id, sum(amount) as total from payment join customer using (customer_id) group by first_name, last_name, store_id ) select first_name, last_name, store_id, total, rank() over (partition by store_id order by total desc) from cte ) x where rank <= 3; first_name | last_name | store_id | total | rank ------------+-----------+----------+--------+------ ELEANOR | HUNT | 1 | 216.54 | 1 CLARA | SHAW | 1 | 195.58 | 2 TOMMY | COLLAZO | 1 | 186.62 | 3 KARL | SEAL | 2 | 221.55 | 1 MARION | SNYDER | 2 | 194.61 | 2 RHONDA | KENNEDY | 2 | 194.61 | 2 (6 rows) Sunday, April 5, 2009
  • 53. Postgres 8.4 / Dev / Rank / New pagila=# select * from ( with cte as ( select first_name, last_name, store_id, sum(amount) as total from payment join customer using (customer_id) group by first_name, last_name, store_id ) select first_name, last_name, store_id, total, rank() over (partition by store_id order by total desc) from cte ) x where rank <= 3; first_name | last_name | store_id | total | rank ------------+-----------+----------+--------+------ ELEANOR | HUNT | 1 | 216.54 | 1 CLARA | SHAW | 1 | 195.58 | 2 TOMMY | COLLAZO | 1 | 186.62 | 3 KARL | SEAL | 2 | 221.55 | 1 MARION | SNYDER | 2 | 194.61 | 2 RHONDA | KENNEDY | 2 | 194.61 | 2 (6 rows) • David Fetter - Sunday @ 11:00 - Window Functions Sunday, April 5, 2009
  • 54. Postgres 8.4 / Dev / Limit • LIMIT can be based on a subquery pagila=# SELECT title FROM film ORDER BY random() pagila-# LIMIT (SELECT count(*)/10 FROM film WHERE rating = 'G'); title --------------------- NONE SPIKING PULP BEVERLY SUPERFLY TRIP LOCK REAR STATE WASTELAND FEUD FROGMEN FEVER EMPIRE LEATHERNECKS DWARFS RANGE MOONWALKER CHOCOLAT HARRY MODERN DORADO SHREK LICENSE NUTS TIES EMPIRE MALKOVICH LOSE INCH DADDY PITTSBURGH DOZEN LION (17 rows) Sunday, April 5, 2009
  • 55. Postgres 8.4 / Dev / FTS Partial Match • Searching partial words and word stems together pagila=# select title, description from film where fulltext @@ to_tsquery('dog:*') except select title, description from film where fulltext @@ to_tsquery('dog'); title | description --------------+--------------------------------------------------------------- ARABIA DOGMA | A Touching Epistle of a Madman And a Mad Cow who must Defeat a : Student in Nigeria DOGMA FAMILY | A Brilliant Character Study of a Database Administrator And a : Monkey who must Succumb a Astronaut in New Orleans (2 rows) Sunday, April 5, 2009
  • 56. Postgres 8.4 / Dev / Table Command • Select all columns for output • SQL Spec Command pagila=# table language; language_id | name | last_update -------------+---------------+--------------------- 1 | English | 2006-02-15 10:02:19 2 | Italian | 2006-02-15 10:02:19 3 | Japanese | 2006-02-15 10:02:19 4 | Mandarin | 2006-02-15 10:02:19 5 | French | 2006-02-15 10:02:19 6 | German | 2006-02-15 10:02:19 Sunday, April 5, 2009
  • 57. Postgres 8.4 / Dev / Table Command • Select all columns for output • SQL Spec Command pagila=# table language; language_id | name | last_update -------------+---------------+--------------------- 1 | English | 2006-02-15 10:02:19 2 | Italian | 2006-02-15 10:02:19 3 | Japanese | 2006-02-15 10:02:19 4 | Mandarin | 2006-02-15 10:02:19 5 | French | 2006-02-15 10:02:19 6 | German | 2006-02-15 10:02:19 • Evil, but catchy Sunday, April 5, 2009
  • 58. Postgres 8.4 / Dev / Generate Time • Time based generate_series() pagila=# select * from generate_series( now() - '5 minutes'::interval, now(), '50 seconds'::interval); generate_series ------------------------------- 2009-04-03 12:49:40.209094-04 2009-04-03 12:50:30.209094-04 2009-04-03 12:51:20.209094-04 2009-04-03 12:52:10.209094-04 2009-04-03 12:53:00.209094-04 2009-04-03 12:53:50.209094-04 2009-04-03 12:54:40.209094-04 (7 rows) Sunday, April 5, 2009
  • 59. Postgres 8.4 / Dev / Wait, there’s more! Sunday, April 5, 2009
  • 60. Postgres 8.4 / Dev / Wait, there’s more! • make column alias keyword quot;asquot; optional (per sql spec) • sql standard interval handling • Support for statement level triggers for TRUNCATE command • suppress_redundent_updates() trigger • Case Insensitive Text module • generate_subscripts() function • array_aggregate() function • unnest() function Sunday, April 5, 2009
  • 61. Postgres 8.4 / Dev / Wait, there’s more! Sunday, April 5, 2009
  • 62. Postgres 8.4 • Performance • Administration • PSQL • Development • Procedures Sunday, April 5, 2009
  • 63. Postgres 8.4 / Proc / CASE Control • CASE as a control structure • Simplify code pagila=# CREATE FUNCTION kidsafe(v_title text) RETURNS text AS $$ BEGIN CASE (select rating from film where title = v_title) WHEN 'NC-17','R' THEN RETURN 'no'; WHEN 'PG-13' THEN RETURN 'maybe'; WHEN 'PG','G' THEN RETURN 'yes'; END CASE; END; $$ LANGUAGE plpgsql; pagila=# select kidsafe('EVE RESURRECTION'), kidsafe('SUNRISE LEAGUE'), kidsafe('AIRPORT POLLOCK'); kidsafe | kidsafe | kidsafe ---------+---------+--------- yes | maybe | no (1 row) Sunday, April 5, 2009
  • 64. Postgres 8.4 / Proc / Variable Args • Allows passing 1..n arguments • Declare argument “variadic” • Available for all languages (handled by parser) pagila=# create or replace function twist (variadic v_ints int[], out v_param int) returns setof int as $$ declare v_i int; begin for v_i in select generate_subscripts(v_ints, 1) loop v_param := v_i; return next; end loop; return; $$ language plpgsql; end; CREATE FUNCTION pagila=# select twist(1); twist ------- 1 (1 row) pagila=# select twist(1,2,3); twist ------- 1 2 3 (3 rows) Sunday, April 5, 2009
  • 65. Postgres 8.4 / Proc / Default Args • Function arguments can now have default values pagila=# create or replace function fancy_last_day (timestamp default current_timestamp::timestamp) returns date immutable language sql as $$ SELECT CASE WHEN EXTRACT(MONTH FROM $1) = 12 THEN (((EXTRACT(YEAR FROM $1) + 1) operator(pg_catalog.||) '-01-01')::date - INTERVAL '1 day')::date ELSE ((EXTRACT(YEAR FROM $1) operator(pg_catalog.||) '-' operator(pg_catalog.||) (EXTRACT(MONTH FROM $1) + 1) operator(pg_catalog.||) '-01')::date - INTERVAL '1 day')::date END $$; CREATE FUNCTION pagila=# select fancy_last_day('2112-12-21 21:12:21.12'::timestamp); -[ RECORD 1 ]-----+----------- fancy_last_day | 2112-12-31 pagila=# select fancy_last_day(); -[ RECORD 1 ]-----+----------- fancy_last_day | 2009-04-30 Sunday, April 5, 2009
  • 66. Postgres 8.4 / Proc / Wait... Sunday, April 5, 2009
  • 67. Postgres 8.4 / Proc / Wait... • RETURNS TABLE for plpgsql functions • Support HINT, DETAIL, and SQLSTATE in RAISE command for plpgsql • RETURN QUERY EXECUTE support in plpgsql • EXECUTE USING for plpgsql • allow srf functions to be called in select clause for plpgsql • quote_nullable() Sunday, April 5, 2009
  • 68. Postgres 8.4 / Proc / Wait... Sunday, April 5, 2009
  • 69. Postgres 8.4 / Upgrades • dump / restore required • more than two dozen incompatibilities • read the release notes! Sunday, April 5, 2009
  • 70. Postgres 8.4 / More Info • http://www.depesz.com/ • http://wiki.postgresql.org/ • http://www.xzilla.net • PGCon, Ottawa, Canada, May 19th - 22nd Sunday, April 5, 2009
  • 71. Thank you for listening. / Presentation Sunday, April 5, 2009