SlideShare uma empresa Scribd logo
1 de 13
Baixar para ler offline
Temporal Data in PostgreSQL




Scott Bailey
The Evergreen State College
PostgreSQL Conference West 2009
http://scottrbailey.wordpress.com
Agenda
✗   Provided data types
✗   Extended data types
✗   Temporal Databases
✗   What is in store for PostgreSQL
✗   Tips, tricks and questions
Thinking About Time
✗   Temporal Quiz
      ✗   How many minutes in a day?
      ✗   How many seconds in a day?
      ✗   How long does it take the Earth to complete one
           rotation?
      ✗   Actually, what is a second?
      ✗   What number should be at the top of the clock?
✗   Extremely complicated!
Basic Data Types
✗   Timestamp &Timestamp with time zone
      ✗   Granularity 1 microsecond
      ✗   Can only subtract two timestamps and
           add/subtract with intervals.
      ✗   Timestamp with out time zone is default for
            compliance with SQL specification.
      ✗   Which should you use?
✗   Date
      ✗   Granularity 1 day
      ✗   Can add/subtract dates & integers
Basic Types Cont.
✗   Interval – a duration of time
       ✗   Granularity 1 microsecond
       ✗   Add/Subtract/Multiply/Divide
✗   Time / Time with time zone
       ✗   Granularity 1 microsecond
       ✗   Acts like both time and a (small) interval
       ✗   Timezone info is useless without date
✗   Depricated types
       ✗   abstime (Unix timestamp), reltime (limited
            interval), timespan (interval), tinterval
            (period)
Period Data Type
✗   Period – defines an anchored interval or timespan
      ✗   Often what we are modeling is not an instantaneous
           event but a period over which some state is true.
      ✗   Typically implemented as a start and end timestamp.
           Could be implemented with an anchor time and an
           interval.
      ✗   Theory has been around for a while.
      ✗   Current implementations – PgTemporal, Chronos
      ✗   Write down a period representing today.
      ✗   Can be open or closed intervals but are typically half-
           open.
      ✗   [ ] indicates endpoints are contained () not contained.
Period Data Type
✗   Why a half open interval?
✗   Period functions
      ✗   Positional
             ✗   before(), after(), adjacent(), overlaps(), overleft(), over-
                  right(), starts(), ends()
      ✗   Containment
             ✗   contains(), contained_by()
      ✗   Manipulation
             ✗   shift(), grow(), shrink()
      ✗   Set functions – periods are contiguous sets
             ✗   period_union(), period_intersect(), period_minus(),
                  period_exclude()
Period Issues
✗   When one end point is unknown
       ✗   Since – period(timestamp, NULL)
       ✗   Until – period(NULL, timestamp) not as common
       ✗   Hard to do much with infinity.
✗   Referential integrity
       ✗   Primary keys – exclusion, can't be two places at
            once.
       ✗   Foreign keys – containment, lifetime of child item
            must be contained by parent's lifetime.
Non-contiguous Time Sets
✗   Why would we need non-contiguous sets?
✗   Set functions for periods can be applied to
    arrays of periods!
✗   Now we can solve (pretty easily) in SQL what
    would have taken LOTS of procedural code.
✗   Period Arrays vs Non-Contiguous Sets
           Period Array




              NCS
Bitemporal Data
✗   “Temporal Database” vs temporal data
      ✗   Both Valid Time (VT) and Transaction Time (TT).
✗   Valid Time – A period for which a fact is true.
      ✗   Employee X was in position Y from A to B.
      ✗   Store not just the current fact but a historical record.
✗   Transaction Time – Records the time a row was
    inserted and superseded
      ✗   Provides time travel or temporal rollback.
      ✗   Very much like the MVCC approach in PostgreSQL.
      ✗   Logging transaction ids with timestamp would let us
           map xmin & xmax to times.
Current Implementations
✗   Lots of theory out there, very few actual
    implementations.
✗   Oracle – Currently the best implementation in a
    general purpose database.
      ✗   Workspace Manager – version enable tables
             ✗   Automatically renames table, adds versioning
                  metadata (VT), creates view w/ original table name,
                  and defines INSTEAD OF triggers for DML.
             ✗   Handles temporal constraints.
             ✗   Provides a period data type and a subset of the
                  functions provided in pgTemporal, Chronos.
             ✗   Great implementation but solves only a single problem
                  domain and does not allow you to reuse them.
The Future for PostgreSQL
✗   Version 8.5
      ✗   Temporal keys and constraints
      ✗   Changes to the type system
      ✗   Period data type either added to core or as a
           contrib module!
✗   Version 8.6?
      ✗   Full support for periods, NCS, table versioning and
           time travel!
      ✗   Hands down the most complete temporal
           implementation of ANY general purpose
           database.
Additional Resources
✗   TSQL2 Specification -
    http://www.cs.arizona.edu/~rts/tsql2.html

✗   Developing Time-Oriented Database
    Applications – Snodgrass
    http://www.cs.arizona.edu/~rts/tdbbook.pdf

✗   Temporal Data and the Relational Model – Date,
    Darwen, Lorentzos
    http://books.google.com/books?isbn=1558608559

✗   TimeDB – For Oracle and IBM Cloudscape
    http://www.timeconsult.com/Software/Software.html

✗   Oracle Workspace Manager -
    http://www.oracle.com/technology/products/database/workspace_manager/index.html

Mais conteúdo relacionado

Mais procurados

Mais procurados (20)

Recovery system
Recovery systemRecovery system
Recovery system
 
17. Recovery System in DBMS
17. Recovery System in DBMS17. Recovery System in DBMS
17. Recovery System in DBMS
 
Multithreading
Multithreading Multithreading
Multithreading
 
Distributed Mutual exclusion algorithms
Distributed Mutual exclusion algorithmsDistributed Mutual exclusion algorithms
Distributed Mutual exclusion algorithms
 
16. Concurrency Control in DBMS
16. Concurrency Control in DBMS16. Concurrency Control in DBMS
16. Concurrency Control in DBMS
 
BACKUP & RECOVERY IN DBMS
BACKUP & RECOVERY IN DBMSBACKUP & RECOVERY IN DBMS
BACKUP & RECOVERY IN DBMS
 
Process Scheduling
Process SchedulingProcess Scheduling
Process Scheduling
 
Database , 13 Replication
Database , 13 ReplicationDatabase , 13 Replication
Database , 13 Replication
 
Clock synchronization in distributed system
Clock synchronization in distributed systemClock synchronization in distributed system
Clock synchronization in distributed system
 
Mainframe systems
Mainframe systemsMainframe systems
Mainframe systems
 
Distributed Deadlock Detection.ppt
Distributed Deadlock Detection.pptDistributed Deadlock Detection.ppt
Distributed Deadlock Detection.ppt
 
Distributed system lamport's and vector algorithm
Distributed system lamport's and vector algorithmDistributed system lamport's and vector algorithm
Distributed system lamport's and vector algorithm
 
Operating system critical section
Operating system   critical sectionOperating system   critical section
Operating system critical section
 
Cache coherence ppt
Cache coherence pptCache coherence ppt
Cache coherence ppt
 
Computer architecture multi processor
Computer architecture multi processorComputer architecture multi processor
Computer architecture multi processor
 
Transactions and Concurrency Control
Transactions and Concurrency ControlTransactions and Concurrency Control
Transactions and Concurrency Control
 
Deadlock Detection
Deadlock DetectionDeadlock Detection
Deadlock Detection
 
Distributed concurrency control
Distributed concurrency controlDistributed concurrency control
Distributed concurrency control
 
Parallel Algorithms
Parallel AlgorithmsParallel Algorithms
Parallel Algorithms
 
Aca11 bk2 ch9
Aca11 bk2 ch9Aca11 bk2 ch9
Aca11 bk2 ch9
 

Destaque

Temporal Databases: Queries
Temporal Databases: QueriesTemporal Databases: Queries
Temporal Databases: Queriestorp42
 
Temporal Databases: Data Models
Temporal Databases: Data ModelsTemporal Databases: Data Models
Temporal Databases: Data Modelstorp42
 
An Overview of Temporal Features in SQL:2011
An Overview of Temporal Features in SQL:2011An Overview of Temporal Features in SQL:2011
An Overview of Temporal Features in SQL:2011Craig Baumunk
 
The study on mining temporal patterns and related applications in dynamic soc...
The study on mining temporal patterns and related applications in dynamic soc...The study on mining temporal patterns and related applications in dynamic soc...
The study on mining temporal patterns and related applications in dynamic soc...Thanh Hieu
 
Theories and Applications of Spatial-Temporal Data Mining and Knowledge Disco...
Theories and Applications of Spatial-Temporal Data Mining and Knowledge Disco...Theories and Applications of Spatial-Temporal Data Mining and Knowledge Disco...
Theories and Applications of Spatial-Temporal Data Mining and Knowledge Disco...Beniamino Murgante
 
PostgreSQL, Extensible to the Nth Degree: Functions, Languages, Types, Rules,...
PostgreSQL, Extensible to the Nth Degree: Functions, Languages, Types, Rules,...PostgreSQL, Extensible to the Nth Degree: Functions, Languages, Types, Rules,...
PostgreSQL, Extensible to the Nth Degree: Functions, Languages, Types, Rules,...Command Prompt., Inc
 
pg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQLpg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQLCommand Prompt., Inc
 
Not Just UNIQUE: Generalized Index Constraints
Not Just UNIQUE: Generalized Index ConstraintsNot Just UNIQUE: Generalized Index Constraints
Not Just UNIQUE: Generalized Index ConstraintsCommand Prompt., Inc
 
Mastering PostgreSQL Administration
Mastering PostgreSQL AdministrationMastering PostgreSQL Administration
Mastering PostgreSQL AdministrationCommand Prompt., Inc
 
PostgreSQL High Availability via SLONY and PG POOL II
PostgreSQL High Availability via SLONY and PG POOL IIPostgreSQL High Availability via SLONY and PG POOL II
PostgreSQL High Availability via SLONY and PG POOL IICommand Prompt., Inc
 
Building tungsten-clusters-with-postgre sql-hot-standby-and-streaming-replica...
Building tungsten-clusters-with-postgre sql-hot-standby-and-streaming-replica...Building tungsten-clusters-with-postgre sql-hot-standby-and-streaming-replica...
Building tungsten-clusters-with-postgre sql-hot-standby-and-streaming-replica...Command Prompt., Inc
 
Transaction Timestamping in Temporal Databases
Transaction Timestamping in Temporal DatabasesTransaction Timestamping in Temporal Databases
Transaction Timestamping in Temporal DatabasesGera Shegalov
 

Destaque (20)

Temporal Databases: Queries
Temporal Databases: QueriesTemporal Databases: Queries
Temporal Databases: Queries
 
Temporal Databases: Data Models
Temporal Databases: Data ModelsTemporal Databases: Data Models
Temporal Databases: Data Models
 
Temporal data mining
Temporal data miningTemporal data mining
Temporal data mining
 
An Overview of Temporal Features in SQL:2011
An Overview of Temporal Features in SQL:2011An Overview of Temporal Features in SQL:2011
An Overview of Temporal Features in SQL:2011
 
Comparision
ComparisionComparision
Comparision
 
The study on mining temporal patterns and related applications in dynamic soc...
The study on mining temporal patterns and related applications in dynamic soc...The study on mining temporal patterns and related applications in dynamic soc...
The study on mining temporal patterns and related applications in dynamic soc...
 
ORDBMS
ORDBMSORDBMS
ORDBMS
 
Theories and Applications of Spatial-Temporal Data Mining and Knowledge Disco...
Theories and Applications of Spatial-Temporal Data Mining and Knowledge Disco...Theories and Applications of Spatial-Temporal Data Mining and Knowledge Disco...
Theories and Applications of Spatial-Temporal Data Mining and Knowledge Disco...
 
PostgreSQL, Extensible to the Nth Degree: Functions, Languages, Types, Rules,...
PostgreSQL, Extensible to the Nth Degree: Functions, Languages, Types, Rules,...PostgreSQL, Extensible to the Nth Degree: Functions, Languages, Types, Rules,...
PostgreSQL, Extensible to the Nth Degree: Functions, Languages, Types, Rules,...
 
Bucardo
BucardoBucardo
Bucardo
 
pg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQLpg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQL
 
Basic Query Tuning Primer
Basic Query Tuning PrimerBasic Query Tuning Primer
Basic Query Tuning Primer
 
Not Just UNIQUE: Generalized Index Constraints
Not Just UNIQUE: Generalized Index ConstraintsNot Just UNIQUE: Generalized Index Constraints
Not Just UNIQUE: Generalized Index Constraints
 
The PostgreSQL Query Planner
The PostgreSQL Query PlannerThe PostgreSQL Query Planner
The PostgreSQL Query Planner
 
Mastering PostgreSQL Administration
Mastering PostgreSQL AdministrationMastering PostgreSQL Administration
Mastering PostgreSQL Administration
 
PostgreSQL High Availability via SLONY and PG POOL II
PostgreSQL High Availability via SLONY and PG POOL IIPostgreSQL High Availability via SLONY and PG POOL II
PostgreSQL High Availability via SLONY and PG POOL II
 
Building tungsten-clusters-with-postgre sql-hot-standby-and-streaming-replica...
Building tungsten-clusters-with-postgre sql-hot-standby-and-streaming-replica...Building tungsten-clusters-with-postgre sql-hot-standby-and-streaming-replica...
Building tungsten-clusters-with-postgre sql-hot-standby-and-streaming-replica...
 
Transaction Timestamping in Temporal Databases
Transaction Timestamping in Temporal DatabasesTransaction Timestamping in Temporal Databases
Transaction Timestamping in Temporal Databases
 
Chapter24
Chapter24Chapter24
Chapter24
 
Go replicator
Go replicatorGo replicator
Go replicator
 

Semelhante a Temporal Data

Job Queues Overview
Job Queues OverviewJob Queues Overview
Job Queues Overviewjoeyrobert
 
Developer-friendly taskqueues: What you should ask yourself before choosing one
Developer-friendly taskqueues: What you should ask yourself before choosing oneDeveloper-friendly taskqueues: What you should ask yourself before choosing one
Developer-friendly taskqueues: What you should ask yourself before choosing oneSylvain Zimmer
 
Developer-friendly task queues: what we learned building MRQ, Sylvain Zimmer
Developer-friendly task queues: what we learned building MRQ, Sylvain ZimmerDeveloper-friendly task queues: what we learned building MRQ, Sylvain Zimmer
Developer-friendly task queues: what we learned building MRQ, Sylvain ZimmerPôle Systematic Paris-Region
 
introduction to data processing using Hadoop and Pig
introduction to data processing using Hadoop and Pigintroduction to data processing using Hadoop and Pig
introduction to data processing using Hadoop and PigRicardo Varela
 
CS3114_09212011.ppt
CS3114_09212011.pptCS3114_09212011.ppt
CS3114_09212011.pptArumugam90
 
Cloud spanner architecture and use cases
Cloud spanner architecture and use casesCloud spanner architecture and use cases
Cloud spanner architecture and use casesGDG Cloud Bengaluru
 
OpenTSDB: HBaseCon2017
OpenTSDB: HBaseCon2017OpenTSDB: HBaseCon2017
OpenTSDB: HBaseCon2017HBaseCon
 
Using Time Window Compaction Strategy For Time Series Workloads
Using Time Window Compaction Strategy For Time Series WorkloadsUsing Time Window Compaction Strategy For Time Series Workloads
Using Time Window Compaction Strategy For Time Series WorkloadsJeff Jirsa
 
Cassandra Data Modeling
Cassandra Data ModelingCassandra Data Modeling
Cassandra Data ModelingMatthew Dennis
 
Tracking your data across the fourth dimension
Tracking your data across the fourth dimensionTracking your data across the fourth dimension
Tracking your data across the fourth dimensionJeremy Cook
 
Cassandra NYC 2011 Data Modeling
Cassandra NYC 2011 Data ModelingCassandra NYC 2011 Data Modeling
Cassandra NYC 2011 Data ModelingMatthew Dennis
 
Accumulo14 15
Accumulo14 15Accumulo14 15
Accumulo14 15Sqrrl
 
Analyzing and Interpreting AWR
Analyzing and Interpreting AWRAnalyzing and Interpreting AWR
Analyzing and Interpreting AWRpasalapudi
 
"Working with date and time data in .NET", Jon Skeet
"Working with date and time data in .NET", Jon Skeet"Working with date and time data in .NET", Jon Skeet
"Working with date and time data in .NET", Jon SkeetFwdays
 
Re-Engineering PostgreSQL as a Time-Series Database
Re-Engineering PostgreSQL as a Time-Series DatabaseRe-Engineering PostgreSQL as a Time-Series Database
Re-Engineering PostgreSQL as a Time-Series DatabaseAll Things Open
 
Leveraging spire for complex time allocation logic
Leveraging spire for complex time allocation logicLeveraging spire for complex time allocation logic
Leveraging spire for complex time allocation logicVladimir Pavkin
 
Monitoring your Python with Prometheus (Python Ireland April 2015)
Monitoring your Python with Prometheus (Python Ireland April 2015)Monitoring your Python with Prometheus (Python Ireland April 2015)
Monitoring your Python with Prometheus (Python Ireland April 2015)Brian Brazil
 
Data all over the place! How SQL and Apache Calcite bring sanity to streaming...
Data all over the place! How SQL and Apache Calcite bring sanity to streaming...Data all over the place! How SQL and Apache Calcite bring sanity to streaming...
Data all over the place! How SQL and Apache Calcite bring sanity to streaming...Julian Hyde
 

Semelhante a Temporal Data (20)

A Brief History of Stream Processing
A Brief History of Stream ProcessingA Brief History of Stream Processing
A Brief History of Stream Processing
 
Cs 331 Data Structures
Cs 331 Data StructuresCs 331 Data Structures
Cs 331 Data Structures
 
Job Queues Overview
Job Queues OverviewJob Queues Overview
Job Queues Overview
 
Developer-friendly taskqueues: What you should ask yourself before choosing one
Developer-friendly taskqueues: What you should ask yourself before choosing oneDeveloper-friendly taskqueues: What you should ask yourself before choosing one
Developer-friendly taskqueues: What you should ask yourself before choosing one
 
Developer-friendly task queues: what we learned building MRQ, Sylvain Zimmer
Developer-friendly task queues: what we learned building MRQ, Sylvain ZimmerDeveloper-friendly task queues: what we learned building MRQ, Sylvain Zimmer
Developer-friendly task queues: what we learned building MRQ, Sylvain Zimmer
 
introduction to data processing using Hadoop and Pig
introduction to data processing using Hadoop and Pigintroduction to data processing using Hadoop and Pig
introduction to data processing using Hadoop and Pig
 
CS3114_09212011.ppt
CS3114_09212011.pptCS3114_09212011.ppt
CS3114_09212011.ppt
 
Cloud spanner architecture and use cases
Cloud spanner architecture and use casesCloud spanner architecture and use cases
Cloud spanner architecture and use cases
 
OpenTSDB: HBaseCon2017
OpenTSDB: HBaseCon2017OpenTSDB: HBaseCon2017
OpenTSDB: HBaseCon2017
 
Using Time Window Compaction Strategy For Time Series Workloads
Using Time Window Compaction Strategy For Time Series WorkloadsUsing Time Window Compaction Strategy For Time Series Workloads
Using Time Window Compaction Strategy For Time Series Workloads
 
Cassandra Data Modeling
Cassandra Data ModelingCassandra Data Modeling
Cassandra Data Modeling
 
Tracking your data across the fourth dimension
Tracking your data across the fourth dimensionTracking your data across the fourth dimension
Tracking your data across the fourth dimension
 
Cassandra NYC 2011 Data Modeling
Cassandra NYC 2011 Data ModelingCassandra NYC 2011 Data Modeling
Cassandra NYC 2011 Data Modeling
 
Accumulo14 15
Accumulo14 15Accumulo14 15
Accumulo14 15
 
Analyzing and Interpreting AWR
Analyzing and Interpreting AWRAnalyzing and Interpreting AWR
Analyzing and Interpreting AWR
 
"Working with date and time data in .NET", Jon Skeet
"Working with date and time data in .NET", Jon Skeet"Working with date and time data in .NET", Jon Skeet
"Working with date and time data in .NET", Jon Skeet
 
Re-Engineering PostgreSQL as a Time-Series Database
Re-Engineering PostgreSQL as a Time-Series DatabaseRe-Engineering PostgreSQL as a Time-Series Database
Re-Engineering PostgreSQL as a Time-Series Database
 
Leveraging spire for complex time allocation logic
Leveraging spire for complex time allocation logicLeveraging spire for complex time allocation logic
Leveraging spire for complex time allocation logic
 
Monitoring your Python with Prometheus (Python Ireland April 2015)
Monitoring your Python with Prometheus (Python Ireland April 2015)Monitoring your Python with Prometheus (Python Ireland April 2015)
Monitoring your Python with Prometheus (Python Ireland April 2015)
 
Data all over the place! How SQL and Apache Calcite bring sanity to streaming...
Data all over the place! How SQL and Apache Calcite bring sanity to streaming...Data all over the place! How SQL and Apache Calcite bring sanity to streaming...
Data all over the place! How SQL and Apache Calcite bring sanity to streaming...
 

Mais de Command Prompt., Inc

Howdah - An Application using Pylons, PostgreSQL, Simpycity and Exceptable
Howdah - An Application using Pylons, PostgreSQL, Simpycity and ExceptableHowdah - An Application using Pylons, PostgreSQL, Simpycity and Exceptable
Howdah - An Application using Pylons, PostgreSQL, Simpycity and ExceptableCommand Prompt., Inc
 
Replication using PostgreSQL Replicator
Replication using PostgreSQL ReplicatorReplication using PostgreSQL Replicator
Replication using PostgreSQL ReplicatorCommand Prompt., Inc
 
Python utilities for data presentation
Python utilities for data presentationPython utilities for data presentation
Python utilities for data presentationCommand Prompt., Inc
 
Implementing the Future of PostgreSQL Clustering with Tungsten
Implementing the Future of PostgreSQL Clustering with TungstenImplementing the Future of PostgreSQL Clustering with Tungsten
Implementing the Future of PostgreSQL Clustering with TungstenCommand Prompt., Inc
 
Elephant Roads: a tour of Postgres forks
Elephant Roads: a tour of Postgres forksElephant Roads: a tour of Postgres forks
Elephant Roads: a tour of Postgres forksCommand Prompt., Inc
 
configuring a warm standby, the easy way
configuring a warm standby, the easy wayconfiguring a warm standby, the easy way
configuring a warm standby, the easy wayCommand Prompt., Inc
 
Normalization: A Workshop for Everybody Pt. 2
Normalization: A Workshop for Everybody Pt. 2Normalization: A Workshop for Everybody Pt. 2
Normalization: A Workshop for Everybody Pt. 2Command Prompt., Inc
 
Normalization: A Workshop for Everybody Pt. 1
Normalization: A Workshop for Everybody Pt. 1Normalization: A Workshop for Everybody Pt. 1
Normalization: A Workshop for Everybody Pt. 1Command Prompt., Inc
 
Integrating PostGIS in Web Applications
Integrating PostGIS in Web ApplicationsIntegrating PostGIS in Web Applications
Integrating PostGIS in Web ApplicationsCommand Prompt., Inc
 
Postgres for MySQL (and other database) people
Postgres for MySQL (and other database) peoplePostgres for MySQL (and other database) people
Postgres for MySQL (and other database) peopleCommand Prompt., Inc
 
Building Grails applications with PostgreSQL
Building Grails applications with PostgreSQLBuilding Grails applications with PostgreSQL
Building Grails applications with PostgreSQLCommand Prompt., Inc
 
Not Just UNIQUE: Exclusion Constraints
Not Just UNIQUE: Exclusion ConstraintsNot Just UNIQUE: Exclusion Constraints
Not Just UNIQUE: Exclusion ConstraintsCommand Prompt., Inc
 
pg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQLpg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQLCommand Prompt., Inc
 

Mais de Command Prompt., Inc (20)

Howdah - An Application using Pylons, PostgreSQL, Simpycity and Exceptable
Howdah - An Application using Pylons, PostgreSQL, Simpycity and ExceptableHowdah - An Application using Pylons, PostgreSQL, Simpycity and Exceptable
Howdah - An Application using Pylons, PostgreSQL, Simpycity and Exceptable
 
Backup and-recovery2
Backup and-recovery2Backup and-recovery2
Backup and-recovery2
 
Replication using PostgreSQL Replicator
Replication using PostgreSQL ReplicatorReplication using PostgreSQL Replicator
Replication using PostgreSQL Replicator
 
Pg migrator
Pg migratorPg migrator
Pg migrator
 
Python utilities for data presentation
Python utilities for data presentationPython utilities for data presentation
Python utilities for data presentation
 
Implementing the Future of PostgreSQL Clustering with Tungsten
Implementing the Future of PostgreSQL Clustering with TungstenImplementing the Future of PostgreSQL Clustering with Tungsten
Implementing the Future of PostgreSQL Clustering with Tungsten
 
Elephant Roads: a tour of Postgres forks
Elephant Roads: a tour of Postgres forksElephant Roads: a tour of Postgres forks
Elephant Roads: a tour of Postgres forks
 
configuring a warm standby, the easy way
configuring a warm standby, the easy wayconfiguring a warm standby, the easy way
configuring a warm standby, the easy way
 
A Practical Multi-Tenant Cluster
A Practical Multi-Tenant ClusterA Practical Multi-Tenant Cluster
A Practical Multi-Tenant Cluster
 
5 Steps to PostgreSQL Performance
5 Steps to PostgreSQL Performance5 Steps to PostgreSQL Performance
5 Steps to PostgreSQL Performance
 
Normalization: A Workshop for Everybody Pt. 2
Normalization: A Workshop for Everybody Pt. 2Normalization: A Workshop for Everybody Pt. 2
Normalization: A Workshop for Everybody Pt. 2
 
Normalization: A Workshop for Everybody Pt. 1
Normalization: A Workshop for Everybody Pt. 1Normalization: A Workshop for Everybody Pt. 1
Normalization: A Workshop for Everybody Pt. 1
 
Integrating PostGIS in Web Applications
Integrating PostGIS in Web ApplicationsIntegrating PostGIS in Web Applications
Integrating PostGIS in Web Applications
 
Postgres for MySQL (and other database) people
Postgres for MySQL (and other database) peoplePostgres for MySQL (and other database) people
Postgres for MySQL (and other database) people
 
Building Grails applications with PostgreSQL
Building Grails applications with PostgreSQLBuilding Grails applications with PostgreSQL
Building Grails applications with PostgreSQL
 
Pg amqp
Pg amqpPg amqp
Pg amqp
 
Not Just UNIQUE: Exclusion Constraints
Not Just UNIQUE: Exclusion ConstraintsNot Just UNIQUE: Exclusion Constraints
Not Just UNIQUE: Exclusion Constraints
 
pg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQLpg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQL
 
Database Hardware Benchmarking
Database Hardware BenchmarkingDatabase Hardware Benchmarking
Database Hardware Benchmarking
 
Vertically Challenged
Vertically ChallengedVertically Challenged
Vertically Challenged
 

Temporal Data

  • 1. Temporal Data in PostgreSQL Scott Bailey The Evergreen State College PostgreSQL Conference West 2009 http://scottrbailey.wordpress.com
  • 2. Agenda ✗ Provided data types ✗ Extended data types ✗ Temporal Databases ✗ What is in store for PostgreSQL ✗ Tips, tricks and questions
  • 3. Thinking About Time ✗ Temporal Quiz ✗ How many minutes in a day? ✗ How many seconds in a day? ✗ How long does it take the Earth to complete one rotation? ✗ Actually, what is a second? ✗ What number should be at the top of the clock? ✗ Extremely complicated!
  • 4. Basic Data Types ✗ Timestamp &Timestamp with time zone ✗ Granularity 1 microsecond ✗ Can only subtract two timestamps and add/subtract with intervals. ✗ Timestamp with out time zone is default for compliance with SQL specification. ✗ Which should you use? ✗ Date ✗ Granularity 1 day ✗ Can add/subtract dates & integers
  • 5. Basic Types Cont. ✗ Interval – a duration of time ✗ Granularity 1 microsecond ✗ Add/Subtract/Multiply/Divide ✗ Time / Time with time zone ✗ Granularity 1 microsecond ✗ Acts like both time and a (small) interval ✗ Timezone info is useless without date ✗ Depricated types ✗ abstime (Unix timestamp), reltime (limited interval), timespan (interval), tinterval (period)
  • 6. Period Data Type ✗ Period – defines an anchored interval or timespan ✗ Often what we are modeling is not an instantaneous event but a period over which some state is true. ✗ Typically implemented as a start and end timestamp. Could be implemented with an anchor time and an interval. ✗ Theory has been around for a while. ✗ Current implementations – PgTemporal, Chronos ✗ Write down a period representing today. ✗ Can be open or closed intervals but are typically half- open. ✗ [ ] indicates endpoints are contained () not contained.
  • 7. Period Data Type ✗ Why a half open interval? ✗ Period functions ✗ Positional ✗ before(), after(), adjacent(), overlaps(), overleft(), over- right(), starts(), ends() ✗ Containment ✗ contains(), contained_by() ✗ Manipulation ✗ shift(), grow(), shrink() ✗ Set functions – periods are contiguous sets ✗ period_union(), period_intersect(), period_minus(), period_exclude()
  • 8. Period Issues ✗ When one end point is unknown ✗ Since – period(timestamp, NULL) ✗ Until – period(NULL, timestamp) not as common ✗ Hard to do much with infinity. ✗ Referential integrity ✗ Primary keys – exclusion, can't be two places at once. ✗ Foreign keys – containment, lifetime of child item must be contained by parent's lifetime.
  • 9. Non-contiguous Time Sets ✗ Why would we need non-contiguous sets? ✗ Set functions for periods can be applied to arrays of periods! ✗ Now we can solve (pretty easily) in SQL what would have taken LOTS of procedural code. ✗ Period Arrays vs Non-Contiguous Sets Period Array NCS
  • 10. Bitemporal Data ✗ “Temporal Database” vs temporal data ✗ Both Valid Time (VT) and Transaction Time (TT). ✗ Valid Time – A period for which a fact is true. ✗ Employee X was in position Y from A to B. ✗ Store not just the current fact but a historical record. ✗ Transaction Time – Records the time a row was inserted and superseded ✗ Provides time travel or temporal rollback. ✗ Very much like the MVCC approach in PostgreSQL. ✗ Logging transaction ids with timestamp would let us map xmin & xmax to times.
  • 11. Current Implementations ✗ Lots of theory out there, very few actual implementations. ✗ Oracle – Currently the best implementation in a general purpose database. ✗ Workspace Manager – version enable tables ✗ Automatically renames table, adds versioning metadata (VT), creates view w/ original table name, and defines INSTEAD OF triggers for DML. ✗ Handles temporal constraints. ✗ Provides a period data type and a subset of the functions provided in pgTemporal, Chronos. ✗ Great implementation but solves only a single problem domain and does not allow you to reuse them.
  • 12. The Future for PostgreSQL ✗ Version 8.5 ✗ Temporal keys and constraints ✗ Changes to the type system ✗ Period data type either added to core or as a contrib module! ✗ Version 8.6? ✗ Full support for periods, NCS, table versioning and time travel! ✗ Hands down the most complete temporal implementation of ANY general purpose database.
  • 13. Additional Resources ✗ TSQL2 Specification - http://www.cs.arizona.edu/~rts/tsql2.html ✗ Developing Time-Oriented Database Applications – Snodgrass http://www.cs.arizona.edu/~rts/tdbbook.pdf ✗ Temporal Data and the Relational Model – Date, Darwen, Lorentzos http://books.google.com/books?isbn=1558608559 ✗ TimeDB – For Oracle and IBM Cloudscape http://www.timeconsult.com/Software/Software.html ✗ Oracle Workspace Manager - http://www.oracle.com/technology/products/database/workspace_manager/index.html