SlideShare ist ein Scribd-Unternehmen logo
1 von 39
Downloaden Sie, um offline zu lesen
Introduction to Databases with PostgreSQL
Gabrielle Roth
PDXPUG & FreeGeek
Nov 9, 2010
Outline
Intro to Databases (discussion)
PostgreSQL (discussion)
psql (hands-on)
SQL (hands-on)
...break somewhere in here, 7:30...
Practice db + more SQL (hands-on)
Basic Admin + GUI Tools (discussion)
Questions
Gabrielle Roth (PDXPUG & FreeGeek) Introduction to Databases with PostgreSQL Nov 9, 2010 2 / 1
Introductions
__ __
/ ~~~/  . o O ( Hi! )
,----( oo )
/ __ __/
/| ( |(
^  /___ / |
|__| |__|-"
Thanks to Hayley J Wakenshaw for the Elephant
Gabrielle Roth (PDXPUG & FreeGeek) Introduction to Databases with PostgreSQL Nov 9, 2010 3 / 1
Databases!
A place to keep your data!
Gabrielle Roth (PDXPUG & FreeGeek) Introduction to Databases with PostgreSQL Nov 9, 2010 4 / 1
Relational databases
Based on Relational Calculus
Data is stored in ”relations”
”Normalized”
Gabrielle Roth (PDXPUG & FreeGeek) Introduction to Databases with PostgreSQL Nov 9, 2010 5 / 1
PostgreSQL
- How do you say that?
- It’s the database *server*
- We think it’s the best.
Gabrielle Roth (PDXPUG & FreeGeek) Introduction to Databases with PostgreSQL Nov 9, 2010 6 / 1
Get connected.
chmod 600 /path/to/id_pdxpug
ssh -i /path/to/id_pdxpug pdxpug@207.173.203.228
Gabrielle Roth (PDXPUG & FreeGeek) Introduction to Databases with PostgreSQL Nov 9, 2010 7 / 1
Pg command-line interface
- psql
- - -help
- psql -U [username] -d pdxpug
- h
- ?
- other useful commands
Gabrielle Roth (PDXPUG & FreeGeek) Introduction to Databases with PostgreSQL Nov 9, 2010 8 / 1
SQL
- Declarative programming language
- ...let’s do ”Hello World”.
Gabrielle Roth (PDXPUG & FreeGeek) Introduction to Databases with PostgreSQL Nov 9, 2010 9 / 1
Hello, World.
SELECT ’Hello, World.’;
...oh yeah, and there’s command-completion, too.
Gabrielle Roth (PDXPUG & FreeGeek) Introduction to Databases with PostgreSQL Nov 9, 2010 10 / 1
CREATE TABLE
CREATE TABLE animals
(name varchar(32) primary key,
skin varchar(32),
legs int);
Gabrielle Roth (PDXPUG & FreeGeek) Introduction to Databases with PostgreSQL Nov 9, 2010 11 / 1
INSERT
INSERT INTO animals
VALUES (’cat’, ’fur’, ’4’);
Gabrielle Roth (PDXPUG & FreeGeek) Introduction to Databases with PostgreSQL Nov 9, 2010 12 / 1
multi-valued INSERT
insert into animals
values
(’dog’, ’fur’, ’4’),
(’bird’, ’feathers’, ’2’),
(’snake’, ’scales’, ’0’);
Gabrielle Roth (PDXPUG & FreeGeek) Introduction to Databases with PostgreSQL Nov 9, 2010 13 / 1
SELECT
SELECT * FROM animals;
SELECT name, legs FROM animals;
SELECT * FROM animals
ORDER BY name;
SELECT count(*) FROM animals;
SELECT SUM(legs) FROM animals;
Gabrielle Roth (PDXPUG & FreeGeek) Introduction to Databases with PostgreSQL Nov 9, 2010 14 / 1
UPDATE
UPDATE animals
SET name = ’kitty’ WHERE name = ’cat’;
SELECT * FROM animals;
Gabrielle Roth (PDXPUG & FreeGeek) Introduction to Databases with PostgreSQL Nov 9, 2010 15 / 1
Transactions
BEGIN;
...your stuff...
...check your stuff with a SELECT...
ROLLBACK or COMMIT as desired
Gabrielle Roth (PDXPUG & FreeGeek) Introduction to Databases with PostgreSQL Nov 9, 2010 16 / 1
DELETE
BEGIN;
DELETE FROM animals WHERE legs=2;
SELECT * FROM animals;
[ROLLBACK or COMMIT]
SELECT * FROM animals;
Gabrielle Roth (PDXPUG & FreeGeek) Introduction to Databases with PostgreSQL Nov 9, 2010 17 / 1
Exercises
- add an animal of your choice
- update its name
- delete all animals with four legs
Gabrielle Roth (PDXPUG & FreeGeek) Introduction to Databases with PostgreSQL Nov 9, 2010 18 / 1
MOAR TABLEZ
www.postgresqlguide.com/postgresql-sample-database.aspx
Gabrielle Roth (PDXPUG & FreeGeek) Introduction to Databases with PostgreSQL Nov 9, 2010 19 / 1
ERDs
- Entity-Relationship Diagrams
- Graphical representation of the relations
- ...and how they’re connected (JOINed)
Gabrielle Roth (PDXPUG & FreeGeek) Introduction to Databases with PostgreSQL Nov 9, 2010 20 / 1
The time has come, the walrus said, to talk of many things.
Gabrielle Roth (PDXPUG & FreeGeek) Introduction to Databases with PostgreSQL Nov 9, 2010 21 / 1
Load ’er up!
i /home/pdxpug/create_tables.sql
i /home/pdxpug/populate_tables.sql
Gabrielle Roth (PDXPUG & FreeGeek) Introduction to Databases with PostgreSQL Nov 9, 2010 22 / 1
Working with the sample db
- d
- what are these seq relations?
- d item
- s
- e
Gabrielle Roth (PDXPUG & FreeGeek) Introduction to Databases with PostgreSQL Nov 9, 2010 23 / 1
DISTINCT
SELECT fname, lname FROM customer
SELECT count(lname) FROM customer;
SELECT DISTINCT lname FROM customer;
SELECT count(DISTINCT(lname)) FROM customer;
Gabrielle Roth (PDXPUG & FreeGeek) Introduction to Databases with PostgreSQL Nov 9, 2010 24 / 1
- PRIMARY vs FOREIGN keys
- Natural vs Surrogate keys
- JOINs
- pset null ’[null]’
Gabrielle Roth (PDXPUG & FreeGeek) Introduction to Databases with PostgreSQL Nov 9, 2010 25 / 1
JOINs
SELECT * FROM item;
SELECT * FROM stock;
SELECT i.description, i.cost_price, i.sell_price, s.quantity
FROM item i
JOIN stock s ON i.item_id = s.item_id;
SELECT i.description, i.cost_price, i.sell_price, s.quantity
FROM item i
LEFT JOIN stock s ON i.item_id = s.item_id;
SELECT i.description, i.cost_price, i.sell_price, s.quantity
FROM item i
RIGHT JOIN stock s ON i.item_id = s.item_id;Gabrielle Roth (PDXPUG & FreeGeek) Introduction to Databases with PostgreSQL Nov 9, 2010 26 / 1
...and the dreaded Cartesian JOIN
SELECT * FROM item;
SELECT * FROM stock;
SELECT i.description, i.cost_price, i.sell_price, s.quantity
FROM item i, stock s;
SELECT i.description, i.cost_price, i.sell_price, s.quantity
FROM item i
CROSS JOIN stock s;
Gabrielle Roth (PDXPUG & FreeGeek) Introduction to Databases with PostgreSQL Nov 9, 2010 27 / 1
VIEWs and TEMP TABLEs
CREATE VIEW my_view AS SELECT field FROM table;
vs.
CREATE TEMP TABLE my_temp_table AS SELECT field FROM table;
Gabrielle Roth (PDXPUG & FreeGeek) Introduction to Databases with PostgreSQL Nov 9, 2010 28 / 1
VIEWs and TEMP TABLEs
CREATE VIEW view_in_stock AS
SELECT i.item_id, i.description, s.quantity
FROM item i
LEFT JOIN stock s ON i.item_id=s.item_id;
SELECT * FROM view_in_stock;
try:
pset null ’0’
Gabrielle Roth (PDXPUG & FreeGeek) Introduction to Databases with PostgreSQL Nov 9, 2010 29 / 1
subSELECTs
SELECT date_placed FROM orderinfo
WHERE customer_id IN
(SELECT customer_id FROM customer
WHERE lname = ’Matthew’);
SELECT date_placed FROM orderinfo
WHERE customer_id IN
(SELECT customer_id FROM customer
WHERE (fname, lname) = (’Alex’,’Matthew’));
Gabrielle Roth (PDXPUG & FreeGeek) Introduction to Databases with PostgreSQL Nov 9, 2010 30 / 1
Exercises
1 How many items are currently in stock?
2 In which towns do we have customers?
3 Experiment with RIGHT JOIN with the original sample queries.
4 What are the barcodes for each item?
5 What is the name + total ”our cost” value of each item currently in stock?
6 What is the name + total ”selling cost” value of each item currently in stock?
7 What are the total ”our cost” and ”sell cost” values of all items in stock?
8 How much was shipping on each order?
9 What items were ordered by people with the last name ”Stones”?
10 How much was the total shipping per person?
Gabrielle Roth (PDXPUG & FreeGeek) Introduction to Databases with PostgreSQL Nov 9, 2010 31 / 1
Basic Admin
- initdb
- PGDATA
- postgresql.conf
- pg hba.conf
- stop/start/restart/reload
Gabrielle Roth (PDXPUG & FreeGeek) Introduction to Databases with PostgreSQL Nov 9, 2010 32 / 1
Basic Admin
- SELECT version();
- CREATE ROLE
- backups and upgrades
- pg dump, pg dumpall, pg upgrade
- logs
Gabrielle Roth (PDXPUG & FreeGeek) Introduction to Databases with PostgreSQL Nov 9, 2010 33 / 1
GUI Tools
- pHpPgAdmin
- pgAdminIII
Gabrielle Roth (PDXPUG & FreeGeek) Introduction to Databases with PostgreSQL Nov 9, 2010 34 / 1
Extras
- Natural keys vs Surrogate keys
- indexes
GRANT USAGE ON SCHEMA [schema] TO [otheruser];
GRANT SELECT ON [table] TO [otheruser];
Gabrielle Roth (PDXPUG & FreeGeek) Introduction to Databases with PostgreSQL Nov 9, 2010 35 / 1
Book giveaway!
SELECT (random() * 100);
Gabrielle Roth (PDXPUG & FreeGeek) Introduction to Databases with PostgreSQL Nov 9, 2010 36 / 1
Where to get help
- www.postgresql.org/community/lists/
- #postgresql
- PDXPUG
Gabrielle Roth (PDXPUG & FreeGeek) Introduction to Databases with PostgreSQL Nov 9, 2010 37 / 1
Reading List
www.postgresql.org/docs
Manga Guide to Databases Takahashi, Mana
Database Design for Mere Mortals Hernandez, Michael J
SQL for Smarties Celko, Joe
Introduction to Database Systems Date, CJ
Relational Model for Database Management Codd, EF
Gabrielle Roth (PDXPUG & FreeGeek) Introduction to Databases with PostgreSQL Nov 9, 2010 38 / 1
__ __
/ ~~~/  . o O ( Thank you! )
,----( oo )
/ __ __/
/| ( |(
^  /___ / |
|__| |__|-"
Gabrielle Roth (PDXPUG & FreeGeek) Introduction to Databases with PostgreSQL Nov 9, 2010 39 / 1

Weitere ähnliche Inhalte

Was ist angesagt?

Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDBMike Dirolf
 
Oracle db performance tuning
Oracle db performance tuningOracle db performance tuning
Oracle db performance tuningSimon Huang
 
Table Partitioning in SQL Server: A Magic Solution for Better Performance? (P...
Table Partitioning in SQL Server: A Magic Solution for Better Performance? (P...Table Partitioning in SQL Server: A Magic Solution for Better Performance? (P...
Table Partitioning in SQL Server: A Magic Solution for Better Performance? (P...Cathrine Wilhelmsen
 
Getting started with postgresql
Getting started with postgresqlGetting started with postgresql
Getting started with postgresqlbotsplash.com
 
Inside PostgreSQL Shared Memory
Inside PostgreSQL Shared MemoryInside PostgreSQL Shared Memory
Inside PostgreSQL Shared MemoryEDB
 
Introduction to PySpark
Introduction to PySparkIntroduction to PySpark
Introduction to PySparkRussell Jurney
 
PostgreSQL Tutorial For Beginners | Edureka
PostgreSQL Tutorial For Beginners | EdurekaPostgreSQL Tutorial For Beginners | Edureka
PostgreSQL Tutorial For Beginners | EdurekaEdureka!
 
PostGIS and Spatial SQL
PostGIS and Spatial SQLPostGIS and Spatial SQL
PostGIS and Spatial SQLTodd Barr
 
Redefining tables online without surprises
Redefining tables online without surprisesRedefining tables online without surprises
Redefining tables online without surprisesNelson Calero
 
Spark SQL Tutorial | Spark Tutorial for Beginners | Apache Spark Training | E...
Spark SQL Tutorial | Spark Tutorial for Beginners | Apache Spark Training | E...Spark SQL Tutorial | Spark Tutorial for Beginners | Apache Spark Training | E...
Spark SQL Tutorial | Spark Tutorial for Beginners | Apache Spark Training | E...Edureka!
 
Oracle database performance tuning
Oracle database performance tuningOracle database performance tuning
Oracle database performance tuningYogiji Creations
 
[Meetup] a successful migration from elastic search to clickhouse
[Meetup] a successful migration from elastic search to clickhouse[Meetup] a successful migration from elastic search to clickhouse
[Meetup] a successful migration from elastic search to clickhouseVianney FOUCAULT
 
PostgreSQL WAL for DBAs
PostgreSQL WAL for DBAs PostgreSQL WAL for DBAs
PostgreSQL WAL for DBAs PGConf APAC
 
patroni-based citrus high availability environment deployment
patroni-based citrus high availability environment deploymentpatroni-based citrus high availability environment deployment
patroni-based citrus high availability environment deploymenthyeongchae lee
 
Logical Replication in PostgreSQL
Logical Replication in PostgreSQLLogical Replication in PostgreSQL
Logical Replication in PostgreSQLEDB
 
Postgresql database administration volume 1
Postgresql database administration volume 1Postgresql database administration volume 1
Postgresql database administration volume 1Federico Campoli
 
[Foss4 g2013 korea]postgis와 geoserver를 이용한 대용량 공간데이터 기반 일기도 서비스 구축 사례
[Foss4 g2013 korea]postgis와 geoserver를 이용한 대용량 공간데이터 기반 일기도 서비스 구축 사례[Foss4 g2013 korea]postgis와 geoserver를 이용한 대용량 공간데이터 기반 일기도 서비스 구축 사례
[Foss4 g2013 korea]postgis와 geoserver를 이용한 대용량 공간데이터 기반 일기도 서비스 구축 사례BJ Jang
 

Was ist angesagt? (20)

Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
Oracle db performance tuning
Oracle db performance tuningOracle db performance tuning
Oracle db performance tuning
 
Table Partitioning in SQL Server: A Magic Solution for Better Performance? (P...
Table Partitioning in SQL Server: A Magic Solution for Better Performance? (P...Table Partitioning in SQL Server: A Magic Solution for Better Performance? (P...
Table Partitioning in SQL Server: A Magic Solution for Better Performance? (P...
 
Getting started with postgresql
Getting started with postgresqlGetting started with postgresql
Getting started with postgresql
 
One PDB to go, please!
One PDB to go, please!One PDB to go, please!
One PDB to go, please!
 
Inside PostgreSQL Shared Memory
Inside PostgreSQL Shared MemoryInside PostgreSQL Shared Memory
Inside PostgreSQL Shared Memory
 
Introduction to PySpark
Introduction to PySparkIntroduction to PySpark
Introduction to PySpark
 
PostgreSQL Tutorial For Beginners | Edureka
PostgreSQL Tutorial For Beginners | EdurekaPostgreSQL Tutorial For Beginners | Edureka
PostgreSQL Tutorial For Beginners | Edureka
 
Postgresql
PostgresqlPostgresql
Postgresql
 
PostGIS and Spatial SQL
PostGIS and Spatial SQLPostGIS and Spatial SQL
PostGIS and Spatial SQL
 
Redefining tables online without surprises
Redefining tables online without surprisesRedefining tables online without surprises
Redefining tables online without surprises
 
PostgreSQL.pptx
PostgreSQL.pptxPostgreSQL.pptx
PostgreSQL.pptx
 
Spark SQL Tutorial | Spark Tutorial for Beginners | Apache Spark Training | E...
Spark SQL Tutorial | Spark Tutorial for Beginners | Apache Spark Training | E...Spark SQL Tutorial | Spark Tutorial for Beginners | Apache Spark Training | E...
Spark SQL Tutorial | Spark Tutorial for Beginners | Apache Spark Training | E...
 
Oracle database performance tuning
Oracle database performance tuningOracle database performance tuning
Oracle database performance tuning
 
[Meetup] a successful migration from elastic search to clickhouse
[Meetup] a successful migration from elastic search to clickhouse[Meetup] a successful migration from elastic search to clickhouse
[Meetup] a successful migration from elastic search to clickhouse
 
PostgreSQL WAL for DBAs
PostgreSQL WAL for DBAs PostgreSQL WAL for DBAs
PostgreSQL WAL for DBAs
 
patroni-based citrus high availability environment deployment
patroni-based citrus high availability environment deploymentpatroni-based citrus high availability environment deployment
patroni-based citrus high availability environment deployment
 
Logical Replication in PostgreSQL
Logical Replication in PostgreSQLLogical Replication in PostgreSQL
Logical Replication in PostgreSQL
 
Postgresql database administration volume 1
Postgresql database administration volume 1Postgresql database administration volume 1
Postgresql database administration volume 1
 
[Foss4 g2013 korea]postgis와 geoserver를 이용한 대용량 공간데이터 기반 일기도 서비스 구축 사례
[Foss4 g2013 korea]postgis와 geoserver를 이용한 대용량 공간데이터 기반 일기도 서비스 구축 사례[Foss4 g2013 korea]postgis와 geoserver를 이용한 대용량 공간데이터 기반 일기도 서비스 구축 사례
[Foss4 g2013 korea]postgis와 geoserver를 이용한 대용량 공간데이터 기반 일기도 서비스 구축 사례
 

Andere mochten auch

A brief introduction to PostgreSQL
A brief introduction to PostgreSQLA brief introduction to PostgreSQL
A brief introduction to PostgreSQLVu Hung Nguyen
 
Postgres Presentation
Postgres PresentationPostgres Presentation
Postgres Presentationgisborne
 
PostgreSQL Deep Internal
PostgreSQL Deep InternalPostgreSQL Deep Internal
PostgreSQL Deep InternalEXEM
 

Andere mochten auch (6)

A brief introduction to PostgreSQL
A brief introduction to PostgreSQLA brief introduction to PostgreSQL
A brief introduction to PostgreSQL
 
Get to know PostgreSQL!
Get to know PostgreSQL!Get to know PostgreSQL!
Get to know PostgreSQL!
 
Postgres Presentation
Postgres PresentationPostgres Presentation
Postgres Presentation
 
PostgreSQL and PL/Java
PostgreSQL and PL/JavaPostgreSQL and PL/Java
PostgreSQL and PL/Java
 
PostgreSQL and RAM usage
PostgreSQL and RAM usagePostgreSQL and RAM usage
PostgreSQL and RAM usage
 
PostgreSQL Deep Internal
PostgreSQL Deep InternalPostgreSQL Deep Internal
PostgreSQL Deep Internal
 

Ähnlich wie Introduction to PostgreSQL

Old Oracle Versions
Old Oracle VersionsOld Oracle Versions
Old Oracle VersionsJeffrey Kemp
 
Don't panic! - Postgres introduction
Don't panic! - Postgres introductionDon't panic! - Postgres introduction
Don't panic! - Postgres introductionFederico Campoli
 
Massively Parallel Process with Prodedural Python by Ian Huston
Massively Parallel Process with Prodedural Python by Ian HustonMassively Parallel Process with Prodedural Python by Ian Huston
Massively Parallel Process with Prodedural Python by Ian HustonPyData
 
(1)Objective Binary Search Tree traversal (2 points)Use traversal.pdf
(1)Objective Binary Search Tree traversal (2 points)Use traversal.pdf(1)Objective Binary Search Tree traversal (2 points)Use traversal.pdf
(1)Objective Binary Search Tree traversal (2 points)Use traversal.pdfarihantmobileselepun
 
Rails in the enterprise
Rails in the enterpriseRails in the enterprise
Rails in the enterprisealexrothenberg
 
Strata Conference + Hadoop World San Jose 2015: Data Discovery on Hadoop
Strata Conference + Hadoop World San Jose 2015: Data Discovery on Hadoop Strata Conference + Hadoop World San Jose 2015: Data Discovery on Hadoop
Strata Conference + Hadoop World San Jose 2015: Data Discovery on Hadoop Sumeet Singh
 
Getting Started with Hadoop
Getting Started with HadoopGetting Started with Hadoop
Getting Started with HadoopJosh Devins
 
Storm - As deep into real-time data processing as you can get in 30 minutes.
Storm - As deep into real-time data processing as you can get in 30 minutes.Storm - As deep into real-time data processing as you can get in 30 minutes.
Storm - As deep into real-time data processing as you can get in 30 minutes.Dan Lynn
 
Stratosphere System Overview Big Data Beers Berlin. 20.11.2013
Stratosphere System Overview Big Data Beers Berlin. 20.11.2013Stratosphere System Overview Big Data Beers Berlin. 20.11.2013
Stratosphere System Overview Big Data Beers Berlin. 20.11.2013Robert Metzger
 
How to write better code: in-depth best practices for writing readable, simpl...
How to write better code: in-depth best practices for writing readable, simpl...How to write better code: in-depth best practices for writing readable, simpl...
How to write better code: in-depth best practices for writing readable, simpl...Oursky
 
How to write better code: in-depth best practices for writing readable, simpl...
How to write better code: in-depth best practices for writing readable, simpl...How to write better code: in-depth best practices for writing readable, simpl...
How to write better code: in-depth best practices for writing readable, simpl...Jane Chung
 
Tree Traversals A tree traversal is the process of visiting.pdf
Tree Traversals A tree traversal is the process of visiting.pdfTree Traversals A tree traversal is the process of visiting.pdf
Tree Traversals A tree traversal is the process of visiting.pdfajayadinathcomputers
 
Planning with Polyalgebra: Bringing Together Relational, Complex and Machine ...
Planning with Polyalgebra: Bringing Together Relational, Complex and Machine ...Planning with Polyalgebra: Bringing Together Relational, Complex and Machine ...
Planning with Polyalgebra: Bringing Together Relational, Complex and Machine ...Julian Hyde
 

Ähnlich wie Introduction to PostgreSQL (20)

Pig workshop
Pig workshopPig workshop
Pig workshop
 
Old Oracle Versions
Old Oracle VersionsOld Oracle Versions
Old Oracle Versions
 
Pg big fast ugly acid
Pg big fast ugly acidPg big fast ugly acid
Pg big fast ugly acid
 
Don't panic! - Postgres introduction
Don't panic! - Postgres introductionDon't panic! - Postgres introduction
Don't panic! - Postgres introduction
 
Massively Parallel Process with Prodedural Python by Ian Huston
Massively Parallel Process with Prodedural Python by Ian HustonMassively Parallel Process with Prodedural Python by Ian Huston
Massively Parallel Process with Prodedural Python by Ian Huston
 
(1)Objective Binary Search Tree traversal (2 points)Use traversal.pdf
(1)Objective Binary Search Tree traversal (2 points)Use traversal.pdf(1)Objective Binary Search Tree traversal (2 points)Use traversal.pdf
(1)Objective Binary Search Tree traversal (2 points)Use traversal.pdf
 
Hitchikers guide handout
Hitchikers guide handoutHitchikers guide handout
Hitchikers guide handout
 
Hadoop
HadoopHadoop
Hadoop
 
Kill the DBA
Kill the DBAKill the DBA
Kill the DBA
 
Rails in the enterprise
Rails in the enterpriseRails in the enterprise
Rails in the enterprise
 
Strata Conference + Hadoop World San Jose 2015: Data Discovery on Hadoop
Strata Conference + Hadoop World San Jose 2015: Data Discovery on Hadoop Strata Conference + Hadoop World San Jose 2015: Data Discovery on Hadoop
Strata Conference + Hadoop World San Jose 2015: Data Discovery on Hadoop
 
Getting Started with Hadoop
Getting Started with HadoopGetting Started with Hadoop
Getting Started with Hadoop
 
Storm - As deep into real-time data processing as you can get in 30 minutes.
Storm - As deep into real-time data processing as you can get in 30 minutes.Storm - As deep into real-time data processing as you can get in 30 minutes.
Storm - As deep into real-time data processing as you can get in 30 minutes.
 
Data-Intensive Scalable Science
Data-Intensive Scalable ScienceData-Intensive Scalable Science
Data-Intensive Scalable Science
 
Stratosphere System Overview Big Data Beers Berlin. 20.11.2013
Stratosphere System Overview Big Data Beers Berlin. 20.11.2013Stratosphere System Overview Big Data Beers Berlin. 20.11.2013
Stratosphere System Overview Big Data Beers Berlin. 20.11.2013
 
How to write better code: in-depth best practices for writing readable, simpl...
How to write better code: in-depth best practices for writing readable, simpl...How to write better code: in-depth best practices for writing readable, simpl...
How to write better code: in-depth best practices for writing readable, simpl...
 
How to write better code: in-depth best practices for writing readable, simpl...
How to write better code: in-depth best practices for writing readable, simpl...How to write better code: in-depth best practices for writing readable, simpl...
How to write better code: in-depth best practices for writing readable, simpl...
 
Tree Traversals A tree traversal is the process of visiting.pdf
Tree Traversals A tree traversal is the process of visiting.pdfTree Traversals A tree traversal is the process of visiting.pdf
Tree Traversals A tree traversal is the process of visiting.pdf
 
Planning with Polyalgebra: Bringing Together Relational, Complex and Machine ...
Planning with Polyalgebra: Bringing Together Relational, Complex and Machine ...Planning with Polyalgebra: Bringing Together Relational, Complex and Machine ...
Planning with Polyalgebra: Bringing Together Relational, Complex and Machine ...
 
Polyalgebra
PolyalgebraPolyalgebra
Polyalgebra
 

Mehr von Mark Wong

OHAI, my name is Chelnik! PGCon 2014 Mockumentary
OHAI, my name is Chelnik! PGCon 2014 MockumentaryOHAI, my name is Chelnik! PGCon 2014 Mockumentary
OHAI, my name is Chelnik! PGCon 2014 MockumentaryMark Wong
 
OHAI, my name is Chelnik! Postgres Open 2013 Report
OHAI, my name is Chelnik! Postgres Open 2013 ReportOHAI, my name is Chelnik! Postgres Open 2013 Report
OHAI, my name is Chelnik! Postgres Open 2013 ReportMark Wong
 
collectd & PostgreSQL
collectd & PostgreSQLcollectd & PostgreSQL
collectd & PostgreSQLMark Wong
 
Android & PostgreSQL
Android & PostgreSQLAndroid & PostgreSQL
Android & PostgreSQLMark Wong
 
PGTop for Android: Things I learned making this app
PGTop for Android: Things I learned making this appPGTop for Android: Things I learned making this app
PGTop for Android: Things I learned making this appMark Wong
 
Developing PGTop for Android
Developing PGTop for AndroidDeveloping PGTop for Android
Developing PGTop for AndroidMark Wong
 
Pg in-the-brazilian-armed-forces-presentation
Pg in-the-brazilian-armed-forces-presentationPg in-the-brazilian-armed-forces-presentation
Pg in-the-brazilian-armed-forces-presentationMark Wong
 
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 PostgreSQLMark Wong
 
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 PostgreSQLMark Wong
 
PostgreSQL Portland Performance Practice Project - Database Test 2 Tuning
PostgreSQL Portland Performance Practice Project - Database Test 2 TuningPostgreSQL Portland Performance Practice Project - Database Test 2 Tuning
PostgreSQL Portland Performance Practice Project - Database Test 2 TuningMark Wong
 
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 PostgreSQLMark Wong
 
Filesystem Performance from a Database Perspective
Filesystem Performance from a Database PerspectiveFilesystem Performance from a Database Perspective
Filesystem Performance from a Database PerspectiveMark Wong
 
PostgreSQL Portland Performance Practice Project - Database Test 2 Filesystem...
PostgreSQL Portland Performance Practice Project - Database Test 2 Filesystem...PostgreSQL Portland Performance Practice Project - Database Test 2 Filesystem...
PostgreSQL Portland Performance Practice Project - Database Test 2 Filesystem...Mark Wong
 
PostgreSQL Portland Performance Practice Project - Database Test 2 Howto
PostgreSQL Portland Performance Practice Project - Database Test 2 HowtoPostgreSQL Portland Performance Practice Project - Database Test 2 Howto
PostgreSQL Portland Performance Practice Project - Database Test 2 HowtoMark Wong
 
PostgreSQL Portland Performance Practice Project - Database Test 2 Workload D...
PostgreSQL Portland Performance Practice Project - Database Test 2 Workload D...PostgreSQL Portland Performance Practice Project - Database Test 2 Workload D...
PostgreSQL Portland Performance Practice Project - Database Test 2 Workload D...Mark Wong
 
PostgreSQL Portland Performance Practice Project - Database Test 2 Background
PostgreSQL Portland Performance Practice Project - Database Test 2 BackgroundPostgreSQL Portland Performance Practice Project - Database Test 2 Background
PostgreSQL Portland Performance Practice Project - Database Test 2 BackgroundMark Wong
 
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
 
pg_top is 'top' for PostgreSQL: pg_top + pg_proctab
pg_top is 'top' for PostgreSQL: pg_top + pg_proctabpg_top is 'top' for PostgreSQL: pg_top + pg_proctab
pg_top is 'top' for PostgreSQL: pg_top + pg_proctabMark Wong
 
Linux Filesystems, RAID, and more
Linux Filesystems, RAID, and moreLinux Filesystems, RAID, and more
Linux Filesystems, RAID, and moreMark Wong
 
pg_top is 'top' for PostgreSQL
pg_top is 'top' for PostgreSQLpg_top is 'top' for PostgreSQL
pg_top is 'top' for PostgreSQLMark Wong
 

Mehr von Mark Wong (20)

OHAI, my name is Chelnik! PGCon 2014 Mockumentary
OHAI, my name is Chelnik! PGCon 2014 MockumentaryOHAI, my name is Chelnik! PGCon 2014 Mockumentary
OHAI, my name is Chelnik! PGCon 2014 Mockumentary
 
OHAI, my name is Chelnik! Postgres Open 2013 Report
OHAI, my name is Chelnik! Postgres Open 2013 ReportOHAI, my name is Chelnik! Postgres Open 2013 Report
OHAI, my name is Chelnik! Postgres Open 2013 Report
 
collectd & PostgreSQL
collectd & PostgreSQLcollectd & PostgreSQL
collectd & PostgreSQL
 
Android & PostgreSQL
Android & PostgreSQLAndroid & PostgreSQL
Android & PostgreSQL
 
PGTop for Android: Things I learned making this app
PGTop for Android: Things I learned making this appPGTop for Android: Things I learned making this app
PGTop for Android: Things I learned making this app
 
Developing PGTop for Android
Developing PGTop for AndroidDeveloping PGTop for Android
Developing PGTop for Android
 
Pg in-the-brazilian-armed-forces-presentation
Pg in-the-brazilian-armed-forces-presentationPg in-the-brazilian-armed-forces-presentation
Pg in-the-brazilian-armed-forces-presentation
 
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
 
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
 
PostgreSQL Portland Performance Practice Project - Database Test 2 Tuning
PostgreSQL Portland Performance Practice Project - Database Test 2 TuningPostgreSQL Portland Performance Practice Project - Database Test 2 Tuning
PostgreSQL Portland Performance Practice Project - Database Test 2 Tuning
 
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
 
Filesystem Performance from a Database Perspective
Filesystem Performance from a Database PerspectiveFilesystem Performance from a Database Perspective
Filesystem Performance from a Database Perspective
 
PostgreSQL Portland Performance Practice Project - Database Test 2 Filesystem...
PostgreSQL Portland Performance Practice Project - Database Test 2 Filesystem...PostgreSQL Portland Performance Practice Project - Database Test 2 Filesystem...
PostgreSQL Portland Performance Practice Project - Database Test 2 Filesystem...
 
PostgreSQL Portland Performance Practice Project - Database Test 2 Howto
PostgreSQL Portland Performance Practice Project - Database Test 2 HowtoPostgreSQL Portland Performance Practice Project - Database Test 2 Howto
PostgreSQL Portland Performance Practice Project - Database Test 2 Howto
 
PostgreSQL Portland Performance Practice Project - Database Test 2 Workload D...
PostgreSQL Portland Performance Practice Project - Database Test 2 Workload D...PostgreSQL Portland Performance Practice Project - Database Test 2 Workload D...
PostgreSQL Portland Performance Practice Project - Database Test 2 Workload D...
 
PostgreSQL Portland Performance Practice Project - Database Test 2 Background
PostgreSQL Portland Performance Practice Project - Database Test 2 BackgroundPostgreSQL Portland Performance Practice Project - Database Test 2 Background
PostgreSQL Portland Performance Practice Project - Database Test 2 Background
 
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...
 
pg_top is 'top' for PostgreSQL: pg_top + pg_proctab
pg_top is 'top' for PostgreSQL: pg_top + pg_proctabpg_top is 'top' for PostgreSQL: pg_top + pg_proctab
pg_top is 'top' for PostgreSQL: pg_top + pg_proctab
 
Linux Filesystems, RAID, and more
Linux Filesystems, RAID, and moreLinux Filesystems, RAID, and more
Linux Filesystems, RAID, and more
 
pg_top is 'top' for PostgreSQL
pg_top is 'top' for PostgreSQLpg_top is 'top' for PostgreSQL
pg_top is 'top' for PostgreSQL
 

Introduction to PostgreSQL

  • 1. Introduction to Databases with PostgreSQL Gabrielle Roth PDXPUG & FreeGeek Nov 9, 2010
  • 2. Outline Intro to Databases (discussion) PostgreSQL (discussion) psql (hands-on) SQL (hands-on) ...break somewhere in here, 7:30... Practice db + more SQL (hands-on) Basic Admin + GUI Tools (discussion) Questions Gabrielle Roth (PDXPUG & FreeGeek) Introduction to Databases with PostgreSQL Nov 9, 2010 2 / 1
  • 3. Introductions __ __ / ~~~/ . o O ( Hi! ) ,----( oo ) / __ __/ /| ( |( ^ /___ / | |__| |__|-" Thanks to Hayley J Wakenshaw for the Elephant Gabrielle Roth (PDXPUG & FreeGeek) Introduction to Databases with PostgreSQL Nov 9, 2010 3 / 1
  • 4. Databases! A place to keep your data! Gabrielle Roth (PDXPUG & FreeGeek) Introduction to Databases with PostgreSQL Nov 9, 2010 4 / 1
  • 5. Relational databases Based on Relational Calculus Data is stored in ”relations” ”Normalized” Gabrielle Roth (PDXPUG & FreeGeek) Introduction to Databases with PostgreSQL Nov 9, 2010 5 / 1
  • 6. PostgreSQL - How do you say that? - It’s the database *server* - We think it’s the best. Gabrielle Roth (PDXPUG & FreeGeek) Introduction to Databases with PostgreSQL Nov 9, 2010 6 / 1
  • 7. Get connected. chmod 600 /path/to/id_pdxpug ssh -i /path/to/id_pdxpug pdxpug@207.173.203.228 Gabrielle Roth (PDXPUG & FreeGeek) Introduction to Databases with PostgreSQL Nov 9, 2010 7 / 1
  • 8. Pg command-line interface - psql - - -help - psql -U [username] -d pdxpug - h - ? - other useful commands Gabrielle Roth (PDXPUG & FreeGeek) Introduction to Databases with PostgreSQL Nov 9, 2010 8 / 1
  • 9. SQL - Declarative programming language - ...let’s do ”Hello World”. Gabrielle Roth (PDXPUG & FreeGeek) Introduction to Databases with PostgreSQL Nov 9, 2010 9 / 1
  • 10. Hello, World. SELECT ’Hello, World.’; ...oh yeah, and there’s command-completion, too. Gabrielle Roth (PDXPUG & FreeGeek) Introduction to Databases with PostgreSQL Nov 9, 2010 10 / 1
  • 11. CREATE TABLE CREATE TABLE animals (name varchar(32) primary key, skin varchar(32), legs int); Gabrielle Roth (PDXPUG & FreeGeek) Introduction to Databases with PostgreSQL Nov 9, 2010 11 / 1
  • 12. INSERT INSERT INTO animals VALUES (’cat’, ’fur’, ’4’); Gabrielle Roth (PDXPUG & FreeGeek) Introduction to Databases with PostgreSQL Nov 9, 2010 12 / 1
  • 13. multi-valued INSERT insert into animals values (’dog’, ’fur’, ’4’), (’bird’, ’feathers’, ’2’), (’snake’, ’scales’, ’0’); Gabrielle Roth (PDXPUG & FreeGeek) Introduction to Databases with PostgreSQL Nov 9, 2010 13 / 1
  • 14. SELECT SELECT * FROM animals; SELECT name, legs FROM animals; SELECT * FROM animals ORDER BY name; SELECT count(*) FROM animals; SELECT SUM(legs) FROM animals; Gabrielle Roth (PDXPUG & FreeGeek) Introduction to Databases with PostgreSQL Nov 9, 2010 14 / 1
  • 15. UPDATE UPDATE animals SET name = ’kitty’ WHERE name = ’cat’; SELECT * FROM animals; Gabrielle Roth (PDXPUG & FreeGeek) Introduction to Databases with PostgreSQL Nov 9, 2010 15 / 1
  • 16. Transactions BEGIN; ...your stuff... ...check your stuff with a SELECT... ROLLBACK or COMMIT as desired Gabrielle Roth (PDXPUG & FreeGeek) Introduction to Databases with PostgreSQL Nov 9, 2010 16 / 1
  • 17. DELETE BEGIN; DELETE FROM animals WHERE legs=2; SELECT * FROM animals; [ROLLBACK or COMMIT] SELECT * FROM animals; Gabrielle Roth (PDXPUG & FreeGeek) Introduction to Databases with PostgreSQL Nov 9, 2010 17 / 1
  • 18. Exercises - add an animal of your choice - update its name - delete all animals with four legs Gabrielle Roth (PDXPUG & FreeGeek) Introduction to Databases with PostgreSQL Nov 9, 2010 18 / 1
  • 19. MOAR TABLEZ www.postgresqlguide.com/postgresql-sample-database.aspx Gabrielle Roth (PDXPUG & FreeGeek) Introduction to Databases with PostgreSQL Nov 9, 2010 19 / 1
  • 20. ERDs - Entity-Relationship Diagrams - Graphical representation of the relations - ...and how they’re connected (JOINed) Gabrielle Roth (PDXPUG & FreeGeek) Introduction to Databases with PostgreSQL Nov 9, 2010 20 / 1
  • 21. The time has come, the walrus said, to talk of many things. Gabrielle Roth (PDXPUG & FreeGeek) Introduction to Databases with PostgreSQL Nov 9, 2010 21 / 1
  • 22. Load ’er up! i /home/pdxpug/create_tables.sql i /home/pdxpug/populate_tables.sql Gabrielle Roth (PDXPUG & FreeGeek) Introduction to Databases with PostgreSQL Nov 9, 2010 22 / 1
  • 23. Working with the sample db - d - what are these seq relations? - d item - s - e Gabrielle Roth (PDXPUG & FreeGeek) Introduction to Databases with PostgreSQL Nov 9, 2010 23 / 1
  • 24. DISTINCT SELECT fname, lname FROM customer SELECT count(lname) FROM customer; SELECT DISTINCT lname FROM customer; SELECT count(DISTINCT(lname)) FROM customer; Gabrielle Roth (PDXPUG & FreeGeek) Introduction to Databases with PostgreSQL Nov 9, 2010 24 / 1
  • 25. - PRIMARY vs FOREIGN keys - Natural vs Surrogate keys - JOINs - pset null ’[null]’ Gabrielle Roth (PDXPUG & FreeGeek) Introduction to Databases with PostgreSQL Nov 9, 2010 25 / 1
  • 26. JOINs SELECT * FROM item; SELECT * FROM stock; SELECT i.description, i.cost_price, i.sell_price, s.quantity FROM item i JOIN stock s ON i.item_id = s.item_id; SELECT i.description, i.cost_price, i.sell_price, s.quantity FROM item i LEFT JOIN stock s ON i.item_id = s.item_id; SELECT i.description, i.cost_price, i.sell_price, s.quantity FROM item i RIGHT JOIN stock s ON i.item_id = s.item_id;Gabrielle Roth (PDXPUG & FreeGeek) Introduction to Databases with PostgreSQL Nov 9, 2010 26 / 1
  • 27. ...and the dreaded Cartesian JOIN SELECT * FROM item; SELECT * FROM stock; SELECT i.description, i.cost_price, i.sell_price, s.quantity FROM item i, stock s; SELECT i.description, i.cost_price, i.sell_price, s.quantity FROM item i CROSS JOIN stock s; Gabrielle Roth (PDXPUG & FreeGeek) Introduction to Databases with PostgreSQL Nov 9, 2010 27 / 1
  • 28. VIEWs and TEMP TABLEs CREATE VIEW my_view AS SELECT field FROM table; vs. CREATE TEMP TABLE my_temp_table AS SELECT field FROM table; Gabrielle Roth (PDXPUG & FreeGeek) Introduction to Databases with PostgreSQL Nov 9, 2010 28 / 1
  • 29. VIEWs and TEMP TABLEs CREATE VIEW view_in_stock AS SELECT i.item_id, i.description, s.quantity FROM item i LEFT JOIN stock s ON i.item_id=s.item_id; SELECT * FROM view_in_stock; try: pset null ’0’ Gabrielle Roth (PDXPUG & FreeGeek) Introduction to Databases with PostgreSQL Nov 9, 2010 29 / 1
  • 30. subSELECTs SELECT date_placed FROM orderinfo WHERE customer_id IN (SELECT customer_id FROM customer WHERE lname = ’Matthew’); SELECT date_placed FROM orderinfo WHERE customer_id IN (SELECT customer_id FROM customer WHERE (fname, lname) = (’Alex’,’Matthew’)); Gabrielle Roth (PDXPUG & FreeGeek) Introduction to Databases with PostgreSQL Nov 9, 2010 30 / 1
  • 31. Exercises 1 How many items are currently in stock? 2 In which towns do we have customers? 3 Experiment with RIGHT JOIN with the original sample queries. 4 What are the barcodes for each item? 5 What is the name + total ”our cost” value of each item currently in stock? 6 What is the name + total ”selling cost” value of each item currently in stock? 7 What are the total ”our cost” and ”sell cost” values of all items in stock? 8 How much was shipping on each order? 9 What items were ordered by people with the last name ”Stones”? 10 How much was the total shipping per person? Gabrielle Roth (PDXPUG & FreeGeek) Introduction to Databases with PostgreSQL Nov 9, 2010 31 / 1
  • 32. Basic Admin - initdb - PGDATA - postgresql.conf - pg hba.conf - stop/start/restart/reload Gabrielle Roth (PDXPUG & FreeGeek) Introduction to Databases with PostgreSQL Nov 9, 2010 32 / 1
  • 33. Basic Admin - SELECT version(); - CREATE ROLE - backups and upgrades - pg dump, pg dumpall, pg upgrade - logs Gabrielle Roth (PDXPUG & FreeGeek) Introduction to Databases with PostgreSQL Nov 9, 2010 33 / 1
  • 34. GUI Tools - pHpPgAdmin - pgAdminIII Gabrielle Roth (PDXPUG & FreeGeek) Introduction to Databases with PostgreSQL Nov 9, 2010 34 / 1
  • 35. Extras - Natural keys vs Surrogate keys - indexes GRANT USAGE ON SCHEMA [schema] TO [otheruser]; GRANT SELECT ON [table] TO [otheruser]; Gabrielle Roth (PDXPUG & FreeGeek) Introduction to Databases with PostgreSQL Nov 9, 2010 35 / 1
  • 36. Book giveaway! SELECT (random() * 100); Gabrielle Roth (PDXPUG & FreeGeek) Introduction to Databases with PostgreSQL Nov 9, 2010 36 / 1
  • 37. Where to get help - www.postgresql.org/community/lists/ - #postgresql - PDXPUG Gabrielle Roth (PDXPUG & FreeGeek) Introduction to Databases with PostgreSQL Nov 9, 2010 37 / 1
  • 38. Reading List www.postgresql.org/docs Manga Guide to Databases Takahashi, Mana Database Design for Mere Mortals Hernandez, Michael J SQL for Smarties Celko, Joe Introduction to Database Systems Date, CJ Relational Model for Database Management Codd, EF Gabrielle Roth (PDXPUG & FreeGeek) Introduction to Databases with PostgreSQL Nov 9, 2010 38 / 1
  • 39. __ __ / ~~~/ . o O ( Thank you! ) ,----( oo ) / __ __/ /| ( |( ^ /___ / | |__| |__|-" Gabrielle Roth (PDXPUG & FreeGeek) Introduction to Databases with PostgreSQL Nov 9, 2010 39 / 1