SlideShare una empresa de Scribd logo
1 de 28
Powering Rails 
Application with 
PostgreSQL 
Nidhi Sarvaiya
Who am I? 
➢ Developer at Icicle technologies from last 7 
years. 
➢ Ruby/Ruby on Rails developer since 2009 
➢ Official Handle @ice_on_rails 
➢ Personal Handle @sarvaiya_nidhi
What Are We Covering Today? 
➢ Why PostgreSQL 
➢ Advance Inbuilt Data Types 
➢ UUID 
➢ Full Text Search 
➢ Indexes 
➢ Third Party Gems
Why PostgreSQL? 
➢ First stable version was 6.0 
released in 1996 
➢ Latest stable version 9.3.5 
➢ Fast and reliable 
➢ Free, community support
Rails 4 Handshakes with PostgreSQL 
➢ As of Rails 4, many 
PostgreSQL features 
are supported out of box 
by Active Record
Built In Data Types 
➢ JSON 
➢ Arrays 
➢ hstore 
➢ Range Types 
➢ PostGis 
➢ Network Types
JSON 
Scenario 
Storing different social media information in your Rails 
Application. 
Traditional Approach 
Each social media sites returns different type of information 
so we usually go for NoSQL database 
Alternative 
Store data in JSON format in PostgreSQL
JSON Implementation 
Migration 
create_table :socials do |t| 
t.json 'profile' 
end 
Querying 
Social.first.profile['name'] => nidhi 
Social.select(“profile”) 
Sample Twitter JSON 
{ 
“username” :“sarvaiya_nidhi”, 
“name”:”nidhi”, 
“followers”:80 
}
Array 
Scenario 
Need to add multiple tags and ratings for Book 
Traditional Approach 
Add Separate table and map it with Book 
Alternative 
Add array field in Book table to map multiple tags and 
ratings
Array Implementation 
Migration 
create_table :books do |t| 
t.string :title 
t.string :tags, array: true 
end 
Querying 
Get Books with specific tag 
Book.where("’fiction’ = ANY (tags)") 
Get Books with all tags or multiple tags 
Book.where("’fiction’ = ALL (tags)") 
Book.where("tags @> ARRAY[?]::varchar[]", 
["fantasy", "fiction"]) 
Sampe Book Data 
Book 1 
<Book id: 1, title: "Brave New World", tags: 
["fantasy", "fiction"] > 
Book 2 
<Book id: 2, title: "The Hit", tags: 
["suspense", "thriller"] >
Hstore 
HStore is a key value store within Postgres. 
Scenario 
Need to apply different configuration for different clients 
Traditional Approach 
Maintain multiple entries in settings table by adding 
Key/Value details for each client 
Alternative 
Use Hstore to maintain all setting for client in single record
HStore Implementation 
Migration 
def self.up 
execute "CREATE EXTENSION hstore" 
end 
create_table :clients do |t| 
t.hstore 'settings' 
end 
Querying 
client = Client.first 
client.settings # => { "background-color" => "blue", 
“font-size”:”14px" } 
Get Specific value - client.settings["-background-color"] 
= "blue" 
Sample Hstore Data 
settings: { "background-color" => 
"blue", 
“font-size”:”14px" }
Range Types 
➢ daterange 
➢ int4range 
➢ int8range 
➢numrange 
➢ tsrange 
➢ tstzrange 
Let’s look at some of the them with example ->
Range Type - daterange 
Scenario 
Implement functionality of booking hotels room for specific 
duration 
Traditional Approach 
Need to maintain two different fields capturing start date 
and end date for booking duration 
Alternative 
Use daterange data type to store duration details
daterange Implementation 
Migration 
create_table :rooms do |t| 
t.daterange 'duration' 
end 
Querying 
All Events on a given date: 
Room.where("duration @> ?::date", 
Date.new(2014, 8, 14)) 
Sample Data 
Room1 
10/08/2014 - 14/08/2014 
Room1 
16/08/2014 - 21/08/2014
Range Type - int4range 
Scenario 
Implement functionality of capturing weather forecast 
Traditional Approach 
Need to maintain two different fields capturing high and low 
temperature details 
Alternative 
Use int4range data type to store temperature details
int4range Implementation 
Migration 
create_table :forecasts do |t| 
t.string :city 
t.int4range :hi_lo 
end 
Querying 
Forecast.create!(city: “mumbai”, hi_lo: 
29..32) 
Forecast.first.hi..lo => 29..32 
Sample Data 
Mumbai: 29..32 
Delhi: 31..24
PostGis 
➢ Geospatial extension to Postgres 
➢Support for Geographic objects 
➢New data types 
➢Functions to work with those data types 
➢ Spatial Index Support
Setup & Configuration 
➢ Installing Postgis 
➢ Add gems to support postgis with Active Record 
○ activerecord-postgis-adaptor 
○ rgeo 
➢ Add postgis adaptor in database.yml 
Reference 
http://daniel-azuma.com/articles/georails
Postgis Data Types 
➢ geometry - Any geometric type 
➢ point - Point data 
➢ line_string - LineString data 
➢ polygon - Polygon data 
➢ geometry_collection - Any collection type 
➢ multi_point - A collection of Points 
➢ multi_line_string - A collection of LineStrings 
➢ multi_polygon - A collection of Polygons
Network DataType 
➢ PostgreSQL comes with column types exclusively for IPv4, IPv6, 
and MAC addresses. 
➢ Active Record datatypes - inet, cidr and macaddre 
Migration 
create_table :network_addresses do |t| 
t.inet :inet_address 
t.cidr :cidr_address 
t.macaddr :mac_address 
end
UUID (Universally Unique Identifier) 
➢ Most of the applications now have API, so use UUID rather than 
integer for the ids 
➢ The uuid column type represents a universally unique identifier 
(UUID), a 128-bit value that is generated by an algorithm that 
makes it highly unlikely that the same value can be generated 
twice. 
➢ Sharding would be easier. Even re-merging all the data into a 
single database, if that's something you need at some point.
UUID ImplementaTion 
Enabling UUID Support 
def change 
enable_extension 'uuid-ossp' 
end 
Migration 
create_table :users, id: false do |t| 
t.primary_key :id, :uuid 
end 
or 
create_table :revisions do |t| 
t.column :identifier, :uuid 
end
Full Text Search 
➢ Since PostgreSQL 8.3 
➢ TSVECTOR to represent text data 
➢ TSQUERY to represent search predicates 
➢ Use pg_search gem for Rails application
Indexes Support in PostgreSQL 
➢B-Tree Indexes 
○ Unique Index 
○ Sorted Index 
○ Partial Indexes 
➢ Functional Indexes 
➢ Multi Column Indexes 
➢ GIST & GIN indexes
Gems 
➢ Full Text Search Gem 
○ pg_search - https://github.com/Casecommons/pg_search 
➢Database Insight 
○ pghero - https://github.com/ankane/pghero 
➢ Postgres Extensions 
○ postgres_ext - https://github.com/dockyard/postgres_ext
References 
http://edgeguides.rubyonrails.org/active_record 
_postgresql.html 
http://www.informit.com/articles/article.aspx?p= 
2220311&seqNum=13
THANK 
YOU

Más contenido relacionado

La actualidad más candente

Qtp training session II
Qtp training session IIQtp training session II
Qtp training session II
Aisha Mazhar
 
Mongodb in-anger-boston-rb-2011
Mongodb in-anger-boston-rb-2011Mongodb in-anger-boston-rb-2011
Mongodb in-anger-boston-rb-2011
bostonrb
 

La actualidad más candente (20)

Apache Cassandra Lunch #70: Basics of Apache Cassandra
Apache Cassandra Lunch #70: Basics of Apache CassandraApache Cassandra Lunch #70: Basics of Apache Cassandra
Apache Cassandra Lunch #70: Basics of Apache Cassandra
 
2011 mongo FR - scaling with mongodb
2011 mongo FR - scaling with mongodb2011 mongo FR - scaling with mongodb
2011 mongo FR - scaling with mongodb
 
Handle 08
Handle 08Handle 08
Handle 08
 
Data Binding in Grails
Data Binding in GrailsData Binding in Grails
Data Binding in Grails
 
Probabilistic Data Structures (Edmonton Data Science Meetup, March 2018)
Probabilistic Data Structures (Edmonton Data Science Meetup, March 2018)Probabilistic Data Structures (Edmonton Data Science Meetup, March 2018)
Probabilistic Data Structures (Edmonton Data Science Meetup, March 2018)
 
Андрей Козлов (Altoros): Оптимизация производительности Cassandra
Андрей Козлов (Altoros): Оптимизация производительности CassandraАндрей Козлов (Altoros): Оптимизация производительности Cassandra
Андрей Козлов (Altoros): Оптимизация производительности Cassandra
 
GAAD Database presentation
GAAD Database presentationGAAD Database presentation
GAAD Database presentation
 
Qtp training session II
Qtp training session IIQtp training session II
Qtp training session II
 
What’s new in Alluxio 2: from seamless operations to structured data management
What’s new in Alluxio 2: from seamless operations to structured data managementWhat’s new in Alluxio 2: from seamless operations to structured data management
What’s new in Alluxio 2: from seamless operations to structured data management
 
MongoDB World 2016: The Best IoT Analytics with MongoDB
MongoDB World 2016: The Best IoT Analytics with MongoDBMongoDB World 2016: The Best IoT Analytics with MongoDB
MongoDB World 2016: The Best IoT Analytics with MongoDB
 
Mongodb in-anger-boston-rb-2011
Mongodb in-anger-boston-rb-2011Mongodb in-anger-boston-rb-2011
Mongodb in-anger-boston-rb-2011
 
Need for Time series Database
Need for Time series DatabaseNeed for Time series Database
Need for Time series Database
 
ADO.net control
ADO.net controlADO.net control
ADO.net control
 
ElasticSearch Basics
ElasticSearch BasicsElasticSearch Basics
ElasticSearch Basics
 
Time Series Data in a Time Series World
Time Series Data in a Time Series WorldTime Series Data in a Time Series World
Time Series Data in a Time Series World
 
Elastic Search
Elastic SearchElastic Search
Elastic Search
 
Whirlwind tour of Hadoop and HIve
Whirlwind tour of Hadoop and HIveWhirlwind tour of Hadoop and HIve
Whirlwind tour of Hadoop and HIve
 
How to leverage MongoDB for Big Data Analysis and Operations with MongoDB's A...
How to leverage MongoDB for Big Data Analysis and Operations with MongoDB's A...How to leverage MongoDB for Big Data Analysis and Operations with MongoDB's A...
How to leverage MongoDB for Big Data Analysis and Operations with MongoDB's A...
 
Trivadis TechEvent 2016 Polybase challenges Hive relational access to non-rel...
Trivadis TechEvent 2016 Polybase challenges Hive relational access to non-rel...Trivadis TechEvent 2016 Polybase challenges Hive relational access to non-rel...
Trivadis TechEvent 2016 Polybase challenges Hive relational access to non-rel...
 
A New MongoDB Sharding Architecture for Higher Availability and Better Resour...
A New MongoDB Sharding Architecture for Higher Availability and Better Resour...A New MongoDB Sharding Architecture for Higher Availability and Better Resour...
A New MongoDB Sharding Architecture for Higher Availability and Better Resour...
 

Similar a Powering Rails Application With PostgreSQL

AI與大數據數據處理 Spark實戰(20171216)
AI與大數據數據處理 Spark實戰(20171216)AI與大數據數據處理 Spark實戰(20171216)
AI與大數據數據處理 Spark實戰(20171216)
Paul Chao
 
Elephant in the room: A DBA's Guide to Hadoop
Elephant in the room: A DBA's Guide to HadoopElephant in the room: A DBA's Guide to Hadoop
Elephant in the room: A DBA's Guide to Hadoop
Stuart Ainsworth
 

Similar a Powering Rails Application With PostgreSQL (20)

Siddhi - cloud-native stream processor
Siddhi - cloud-native stream processorSiddhi - cloud-native stream processor
Siddhi - cloud-native stream processor
 
Cascading introduction
Cascading introductionCascading introduction
Cascading introduction
 
Big data week presentation
Big data week presentationBig data week presentation
Big data week presentation
 
Real-time Big Data Processing with Storm
Real-time Big Data Processing with StormReal-time Big Data Processing with Storm
Real-time Big Data Processing with Storm
 
Rails israel 2013
Rails israel 2013Rails israel 2013
Rails israel 2013
 
Java/Scala Lab: Борис Трофимов - Обжигающая Big Data.
Java/Scala Lab: Борис Трофимов - Обжигающая Big Data.Java/Scala Lab: Борис Трофимов - Обжигающая Big Data.
Java/Scala Lab: Борис Трофимов - Обжигающая Big Data.
 
Johnny Miller – Cassandra + Spark = Awesome- NoSQL matters Barcelona 2014
Johnny Miller – Cassandra + Spark = Awesome- NoSQL matters Barcelona 2014Johnny Miller – Cassandra + Spark = Awesome- NoSQL matters Barcelona 2014
Johnny Miller – Cassandra + Spark = Awesome- NoSQL matters Barcelona 2014
 
WSO2Con ASIA 2016: WSO2 Analytics Platform: The One Stop Shop for All Your Da...
WSO2Con ASIA 2016: WSO2 Analytics Platform: The One Stop Shop for All Your Da...WSO2Con ASIA 2016: WSO2 Analytics Platform: The One Stop Shop for All Your Da...
WSO2Con ASIA 2016: WSO2 Analytics Platform: The One Stop Shop for All Your Da...
 
WSO2 Analytics Platform: The one stop shop for all your data needs
WSO2 Analytics Platform: The one stop shop for all your data needsWSO2 Analytics Platform: The one stop shop for all your data needs
WSO2 Analytics Platform: The one stop shop for all your data needs
 
Big Data Technologies - Hadoop
Big Data Technologies - HadoopBig Data Technologies - Hadoop
Big Data Technologies - Hadoop
 
Coding serbia
Coding serbiaCoding serbia
Coding serbia
 
Elasticsearch an overview
Elasticsearch   an overviewElasticsearch   an overview
Elasticsearch an overview
 
Big Data, Data Lake, Fast Data - Dataserialiation-Formats
Big Data, Data Lake, Fast Data - Dataserialiation-FormatsBig Data, Data Lake, Fast Data - Dataserialiation-Formats
Big Data, Data Lake, Fast Data - Dataserialiation-Formats
 
Microsoft Azure Big Data Analytics
Microsoft Azure Big Data AnalyticsMicrosoft Azure Big Data Analytics
Microsoft Azure Big Data Analytics
 
Dicoding Developer Coaching #19: Android | Menyimpan Database Secara Local di...
Dicoding Developer Coaching #19: Android | Menyimpan Database Secara Local di...Dicoding Developer Coaching #19: Android | Menyimpan Database Secara Local di...
Dicoding Developer Coaching #19: Android | Menyimpan Database Secara Local di...
 
AI與大數據數據處理 Spark實戰(20171216)
AI與大數據數據處理 Spark實戰(20171216)AI與大數據數據處理 Spark實戰(20171216)
AI與大數據數據處理 Spark實戰(20171216)
 
Storm real-time processing
Storm real-time processingStorm real-time processing
Storm real-time processing
 
WSO2Con USA 2015: WSO2 Analytics Platform - The One Stop Shop for All Your Da...
WSO2Con USA 2015: WSO2 Analytics Platform - The One Stop Shop for All Your Da...WSO2Con USA 2015: WSO2 Analytics Platform - The One Stop Shop for All Your Da...
WSO2Con USA 2015: WSO2 Analytics Platform - The One Stop Shop for All Your Da...
 
Modeling with Document Database: 5 Key Patterns
Modeling with Document Database: 5 Key PatternsModeling with Document Database: 5 Key Patterns
Modeling with Document Database: 5 Key Patterns
 
Elephant in the room: A DBA's Guide to Hadoop
Elephant in the room: A DBA's Guide to HadoopElephant in the room: A DBA's Guide to Hadoop
Elephant in the room: A DBA's Guide to Hadoop
 

Último

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Último (20)

Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 

Powering Rails Application With PostgreSQL

  • 1. Powering Rails Application with PostgreSQL Nidhi Sarvaiya
  • 2. Who am I? ➢ Developer at Icicle technologies from last 7 years. ➢ Ruby/Ruby on Rails developer since 2009 ➢ Official Handle @ice_on_rails ➢ Personal Handle @sarvaiya_nidhi
  • 3. What Are We Covering Today? ➢ Why PostgreSQL ➢ Advance Inbuilt Data Types ➢ UUID ➢ Full Text Search ➢ Indexes ➢ Third Party Gems
  • 4. Why PostgreSQL? ➢ First stable version was 6.0 released in 1996 ➢ Latest stable version 9.3.5 ➢ Fast and reliable ➢ Free, community support
  • 5. Rails 4 Handshakes with PostgreSQL ➢ As of Rails 4, many PostgreSQL features are supported out of box by Active Record
  • 6. Built In Data Types ➢ JSON ➢ Arrays ➢ hstore ➢ Range Types ➢ PostGis ➢ Network Types
  • 7. JSON Scenario Storing different social media information in your Rails Application. Traditional Approach Each social media sites returns different type of information so we usually go for NoSQL database Alternative Store data in JSON format in PostgreSQL
  • 8. JSON Implementation Migration create_table :socials do |t| t.json 'profile' end Querying Social.first.profile['name'] => nidhi Social.select(“profile”) Sample Twitter JSON { “username” :“sarvaiya_nidhi”, “name”:”nidhi”, “followers”:80 }
  • 9. Array Scenario Need to add multiple tags and ratings for Book Traditional Approach Add Separate table and map it with Book Alternative Add array field in Book table to map multiple tags and ratings
  • 10. Array Implementation Migration create_table :books do |t| t.string :title t.string :tags, array: true end Querying Get Books with specific tag Book.where("’fiction’ = ANY (tags)") Get Books with all tags or multiple tags Book.where("’fiction’ = ALL (tags)") Book.where("tags @> ARRAY[?]::varchar[]", ["fantasy", "fiction"]) Sampe Book Data Book 1 <Book id: 1, title: "Brave New World", tags: ["fantasy", "fiction"] > Book 2 <Book id: 2, title: "The Hit", tags: ["suspense", "thriller"] >
  • 11. Hstore HStore is a key value store within Postgres. Scenario Need to apply different configuration for different clients Traditional Approach Maintain multiple entries in settings table by adding Key/Value details for each client Alternative Use Hstore to maintain all setting for client in single record
  • 12. HStore Implementation Migration def self.up execute "CREATE EXTENSION hstore" end create_table :clients do |t| t.hstore 'settings' end Querying client = Client.first client.settings # => { "background-color" => "blue", “font-size”:”14px" } Get Specific value - client.settings["-background-color"] = "blue" Sample Hstore Data settings: { "background-color" => "blue", “font-size”:”14px" }
  • 13. Range Types ➢ daterange ➢ int4range ➢ int8range ➢numrange ➢ tsrange ➢ tstzrange Let’s look at some of the them with example ->
  • 14. Range Type - daterange Scenario Implement functionality of booking hotels room for specific duration Traditional Approach Need to maintain two different fields capturing start date and end date for booking duration Alternative Use daterange data type to store duration details
  • 15. daterange Implementation Migration create_table :rooms do |t| t.daterange 'duration' end Querying All Events on a given date: Room.where("duration @> ?::date", Date.new(2014, 8, 14)) Sample Data Room1 10/08/2014 - 14/08/2014 Room1 16/08/2014 - 21/08/2014
  • 16. Range Type - int4range Scenario Implement functionality of capturing weather forecast Traditional Approach Need to maintain two different fields capturing high and low temperature details Alternative Use int4range data type to store temperature details
  • 17. int4range Implementation Migration create_table :forecasts do |t| t.string :city t.int4range :hi_lo end Querying Forecast.create!(city: “mumbai”, hi_lo: 29..32) Forecast.first.hi..lo => 29..32 Sample Data Mumbai: 29..32 Delhi: 31..24
  • 18. PostGis ➢ Geospatial extension to Postgres ➢Support for Geographic objects ➢New data types ➢Functions to work with those data types ➢ Spatial Index Support
  • 19. Setup & Configuration ➢ Installing Postgis ➢ Add gems to support postgis with Active Record ○ activerecord-postgis-adaptor ○ rgeo ➢ Add postgis adaptor in database.yml Reference http://daniel-azuma.com/articles/georails
  • 20. Postgis Data Types ➢ geometry - Any geometric type ➢ point - Point data ➢ line_string - LineString data ➢ polygon - Polygon data ➢ geometry_collection - Any collection type ➢ multi_point - A collection of Points ➢ multi_line_string - A collection of LineStrings ➢ multi_polygon - A collection of Polygons
  • 21. Network DataType ➢ PostgreSQL comes with column types exclusively for IPv4, IPv6, and MAC addresses. ➢ Active Record datatypes - inet, cidr and macaddre Migration create_table :network_addresses do |t| t.inet :inet_address t.cidr :cidr_address t.macaddr :mac_address end
  • 22. UUID (Universally Unique Identifier) ➢ Most of the applications now have API, so use UUID rather than integer for the ids ➢ The uuid column type represents a universally unique identifier (UUID), a 128-bit value that is generated by an algorithm that makes it highly unlikely that the same value can be generated twice. ➢ Sharding would be easier. Even re-merging all the data into a single database, if that's something you need at some point.
  • 23. UUID ImplementaTion Enabling UUID Support def change enable_extension 'uuid-ossp' end Migration create_table :users, id: false do |t| t.primary_key :id, :uuid end or create_table :revisions do |t| t.column :identifier, :uuid end
  • 24. Full Text Search ➢ Since PostgreSQL 8.3 ➢ TSVECTOR to represent text data ➢ TSQUERY to represent search predicates ➢ Use pg_search gem for Rails application
  • 25. Indexes Support in PostgreSQL ➢B-Tree Indexes ○ Unique Index ○ Sorted Index ○ Partial Indexes ➢ Functional Indexes ➢ Multi Column Indexes ➢ GIST & GIN indexes
  • 26. Gems ➢ Full Text Search Gem ○ pg_search - https://github.com/Casecommons/pg_search ➢Database Insight ○ pghero - https://github.com/ankane/pghero ➢ Postgres Extensions ○ postgres_ext - https://github.com/dockyard/postgres_ext
  • 27. References http://edgeguides.rubyonrails.org/active_record _postgresql.html http://www.informit.com/articles/article.aspx?p= 2220311&seqNum=13