postgres for mysql (and other database) people
DESCRIPTION
Greg MullaneUpgrading from MySQL or other database to Postgres? While Postgres strives to be SQL standard compliant as much as possible, there are plenty of quirks and features you should know about. We'll also talk about some of the ways in which the Postgres community, infrastructure, and development differs from other database projects.TRANSCRIPT
![Page 2: Postgres for MySQL (and other database) people](https://reader033.vdocument.in/reader033/viewer/2022051613/54c6ac464a7959375f8b4577/html5/thumbnails/2.jpg)
SELECT SUM(info) FROM talk;
• Postgres philosophy and history • Conversion advice • Postgres gotchas • Postgres limitaCons and features
• OrganizaCon and community
• Development and infrastructure
![Page 3: Postgres for MySQL (and other database) people](https://reader033.vdocument.in/reader033/viewer/2022051613/54c6ac464a7959375f8b4577/html5/thumbnails/3.jpg)
The Part of Whys
• Why MySQL? • Why Postgres?
• Why me?
• Why you?
![Page 4: Postgres for MySQL (and other database) people](https://reader033.vdocument.in/reader033/viewer/2022051613/54c6ac464a7959375f8b4577/html5/thumbnails/4.jpg)
• Postgres? PostgreSQL? Postgre? PostgresSQL? • Philosphy • Mercifully quick history lesson
![Page 5: Postgres for MySQL (and other database) people](https://reader033.vdocument.in/reader033/viewer/2022051613/54c6ac464a7959375f8b4577/html5/thumbnails/5.jpg)
MigraCng Your App
• Schema • Data • ApplicaCon • Support
![Page 6: Postgres for MySQL (and other database) people](https://reader033.vdocument.in/reader033/viewer/2022051613/54c6ac464a7959375f8b4577/html5/thumbnails/6.jpg)
MigraCon : Schema
• Mysqldump? • --compatible=postgresql --no-data • Redesign • Conversion tools
![Page 7: Postgres for MySQL (and other database) people](https://reader033.vdocument.in/reader033/viewer/2022051613/54c6ac464a7959375f8b4577/html5/thumbnails/7.jpg)
MigraCon : SQL Spec
• Who cares? • Postgres vs. the spec • MySQL vs. the spec
• Oracle vs. the spec • DB2 vs. the spec • MSSQL vs. the spec
![Page 8: Postgres for MySQL (and other database) people](https://reader033.vdocument.in/reader033/viewer/2022051613/54c6ac464a7959375f8b4577/html5/thumbnails/8.jpg)
MigraCon : Schema
• Tables • Engines and plugins • CustomizaCon
![Page 9: Postgres for MySQL (and other database) people](https://reader033.vdocument.in/reader033/viewer/2022051613/54c6ac464a7959375f8b4577/html5/thumbnails/9.jpg)
MigraCon : Schema : Data Types : Numbers
• INTEGER (smallint, bigint, serial) • NUMERIC (double precision, money)
• REAL
![Page 10: Postgres for MySQL (and other database) people](https://reader033.vdocument.in/reader033/viewer/2022051613/54c6ac464a7959375f8b4577/html5/thumbnails/10.jpg)
MigraCon : Schema : Data Types : Text
• TEXT • VARCHAR(n) • CHAR(n)
![Page 11: Postgres for MySQL (and other database) people](https://reader033.vdocument.in/reader033/viewer/2022051613/54c6ac464a7959375f8b4577/html5/thumbnails/11.jpg)
MigraCon : Schema : Data Types : Dates
• DATE • TIMESTAMPTZ
• TIME
• INTERVAL
![Page 12: Postgres for MySQL (and other database) people](https://reader033.vdocument.in/reader033/viewer/2022051613/54c6ac464a7959375f8b4577/html5/thumbnails/12.jpg)
MigraCon : Schema : Data Types : Boolean
• BOOL • TRUE, ‘t’, ‘y’, ‘yes’, ‘on’, 1 • FALSE, ‘f’, ‘n’, ‘no’, ‘off’, 0
![Page 13: Postgres for MySQL (and other database) people](https://reader033.vdocument.in/reader033/viewer/2022051613/54c6ac464a7959375f8b4577/html5/thumbnails/13.jpg)
MigraCon : Schema : Data Types : Binary
• BYTEA • Internal or external?
![Page 14: Postgres for MySQL (and other database) people](https://reader033.vdocument.in/reader033/viewer/2022051613/54c6ac464a7959375f8b4577/html5/thumbnails/14.jpg)
MigraCon : Schema : Data Types : Others
• Geometric (line, path, box, circle, polygon) • Arrays • ENUM
• CIDR, INET, MACADDR
• UUID • XML
![Page 15: Postgres for MySQL (and other database) people](https://reader033.vdocument.in/reader033/viewer/2022051613/54c6ac464a7959375f8b4577/html5/thumbnails/15.jpg)
MigraCon : Schema : Sequence
• Auto‐increment • SEQUENCE • SERIAL • INTEGER NOT NULL DEFAULT nextval(‘foo’)
![Page 16: Postgres for MySQL (and other database) people](https://reader033.vdocument.in/reader033/viewer/2022051613/54c6ac464a7959375f8b4577/html5/thumbnails/16.jpg)
MigraCon : Schema : DEFAULT
• cdate TIMESTAMPTZ NOT NULL DEFAULT now() • (almost) anything at all
• No magic
![Page 17: Postgres for MySQL (and other database) people](https://reader033.vdocument.in/reader033/viewer/2022051613/54c6ac464a7959375f8b4577/html5/thumbnails/17.jpg)
MigraCon : Schema : FOREIGN KEYS
• Fully supported • ON DELETE CASCADE • ON DELETE RESTRICT • ON DELETE SET NULL • ON DELETE SET DEFAULT • DEFERRED INITIALLY DEFERRED
![Page 18: Postgres for MySQL (and other database) people](https://reader033.vdocument.in/reader033/viewer/2022051613/54c6ac464a7959375f8b4577/html5/thumbnails/18.jpg)
MigraCon : Schema : Indexes
• CREATE INDEX foo ON mytab(mycol); • CREATE INDEX foo2 ON mytab(mycol) WHERE size = ‘grande’;
• CREATE INDEX foo3 ON mytab(LOWER(blurb));
• CREATE INDEX foo4 ON mytab(LOWER(blurb)) WHERE size = ‘grande’;
![Page 19: Postgres for MySQL (and other database) people](https://reader033.vdocument.in/reader033/viewer/2022051613/54c6ac464a7959375f8b4577/html5/thumbnails/19.jpg)
MigraCon : Schema : Indexes
• CREATE INDEX CONCURENTLY foo ON mytab(mycol);
• No rebuilding of tables • Reverse scan, bitmap
![Page 20: Postgres for MySQL (and other database) people](https://reader033.vdocument.in/reader033/viewer/2022051613/54c6ac464a7959375f8b4577/html5/thumbnails/20.jpg)
MigraCon : Schema : Triggers
• CREATE TRIGGER mytrig BEFORE INSERT OR DELETE OR UPDATE ON mytab FOR EACH ROW EXECUTE PROCEDURE somefunc();
• Aside: funcCons and languages
![Page 21: Postgres for MySQL (and other database) people](https://reader033.vdocument.in/reader033/viewer/2022051613/54c6ac464a7959375f8b4577/html5/thumbnails/21.jpg)
MigraCon : Schema : FuncCons
• Very custom • Pl/PGSQL == Pl/SQL • Very powerful
![Page 22: Postgres for MySQL (and other database) people](https://reader033.vdocument.in/reader033/viewer/2022051613/54c6ac464a7959375f8b4577/html5/thumbnails/22.jpg)
MigraCon : Data
• No autocommit, fsync off, no autovacuum • COPY vs. INSERT • Turn off indexes and triggers (FK) • ANALYZE
![Page 23: Postgres for MySQL (and other database) people](https://reader033.vdocument.in/reader033/viewer/2022051613/54c6ac464a7959375f8b4577/html5/thumbnails/23.jpg)
ANALYZE
• Cost‐based planner • Autovacuum
• IniCal load • Default_staCsCcs_target
– 10 – 100 – 1000 – More?
![Page 24: Postgres for MySQL (and other database) people](https://reader033.vdocument.in/reader033/viewer/2022051613/54c6ac464a7959375f8b4577/html5/thumbnails/24.jpg)
VACUUM
• MVCC – Oracle vs. Pg • Rollback segment
• Concurrency and locking • Table bloat • VACUUM FULL, CLUSTER, REINDEX
![Page 25: Postgres for MySQL (and other database) people](https://reader033.vdocument.in/reader033/viewer/2022051613/54c6ac464a7959375f8b4577/html5/thumbnails/25.jpg)
MigraCon : ApplicaCon
• aka SQL • Clients (PHP excepCon) • SQL modes
– TradiConal – Postgresql
• “Any client can change its own session sql_mode value at any Cme.”
![Page 26: Postgres for MySQL (and other database) people](https://reader033.vdocument.in/reader033/viewer/2022051613/54c6ac464a7959375f8b4577/html5/thumbnails/26.jpg)
MigraCon : SQL : NULL
• NULL is NULL
![Page 27: Postgres for MySQL (and other database) people](https://reader033.vdocument.in/reader033/viewer/2022051613/54c6ac464a7959375f8b4577/html5/thumbnails/27.jpg)
MigraCon : SQL : SELECT
• Query planner • JOINS • Subselects
![Page 28: Postgres for MySQL (and other database) people](https://reader033.vdocument.in/reader033/viewer/2022051613/54c6ac464a7959375f8b4577/html5/thumbnails/28.jpg)
MigraCon : SQL : GROUP BY
• SELECT a,b,c FROM mytab GROUP BY a,b • Standard or not?
DISTINCT ON
![Page 29: Postgres for MySQL (and other database) people](https://reader033.vdocument.in/reader033/viewer/2022051613/54c6ac464a7959375f8b4577/html5/thumbnails/29.jpg)
MigraCon : SQL : Text match
• CHAR / VARCHAR / TEXT case sensiCve • SELECT count(*) FROM mytab WHERE mycol = ‘Fred’;
• …WHERE LOWER(mycol) = ‘fred’;
![Page 30: Postgres for MySQL (and other database) people](https://reader033.vdocument.in/reader033/viewer/2022051613/54c6ac464a7959375f8b4577/html5/thumbnails/30.jpg)
MigraCon : SQL : full text search
• Tsearch2: contrib vs. core • Powerful, complex
• TransacConal!
![Page 31: Postgres for MySQL (and other database) people](https://reader033.vdocument.in/reader033/viewer/2022051613/54c6ac464a7959375f8b4577/html5/thumbnails/31.jpg)
MigraCon : SQL : DELETE
• One table only • No LIMIT, no ORDER BY
• No QUICK, LOW PRIORITY, IGNORE
• DELETE FROM ONLY mytab WHERE…
• DELETE FROM mytab USING otab WHERE mycol = otab.id AND otab.size = 'foo';
• DELETE FROM mytab WHERE mycol IN (SELECT id FROM otab WHERE size = ‘foo’);
![Page 32: Postgres for MySQL (and other database) people](https://reader033.vdocument.in/reader033/viewer/2022051613/54c6ac464a7959375f8b4577/html5/thumbnails/32.jpg)
MigraCon : SQL : UPDATE
• Only one table • No ORDER BY, LIMIT, etc.
• UPDATE mytab SET mycol=123 FROM otab WHERE mycol = otab.id AND otab.size = ‘foo’;
![Page 33: Postgres for MySQL (and other database) people](https://reader033.vdocument.in/reader033/viewer/2022051613/54c6ac464a7959375f8b4577/html5/thumbnails/33.jpg)
MigraCon : SQL : INSERT
• Only one table • No REPLACE or ON DUPLICATE KEY UPDATE • UPSERT via plpgsql or app logic • DEFAULT • INSERT INTO mytab DEFAULT VALUES
![Page 34: Postgres for MySQL (and other database) people](https://reader033.vdocument.in/reader033/viewer/2022051613/54c6ac464a7959375f8b4577/html5/thumbnails/34.jpg)
MigraCon : SQL : ||
• Ugh • CONCAT • Wrapper funcCons
• NULL an empty string
![Page 35: Postgres for MySQL (and other database) people](https://reader033.vdocument.in/reader033/viewer/2022051613/54c6ac464a7959375f8b4577/html5/thumbnails/35.jpg)
MigraCon : SQL: GRANT
• ..and REVOKE • Almost any object
• Immediate effect
![Page 36: Postgres for MySQL (and other database) people](https://reader033.vdocument.in/reader033/viewer/2022051613/54c6ac464a7959375f8b4577/html5/thumbnails/36.jpg)
MigraCon : SQL : locking
• Use sparingly • Share, exclusive • Advisory • ALTER TABLE, REINDEX, VACUUM FULL
![Page 37: Postgres for MySQL (and other database) people](https://reader033.vdocument.in/reader033/viewer/2022051613/54c6ac464a7959375f8b4577/html5/thumbnails/37.jpg)
MigraCon : SQL : Aliases
• AS opConal but recommended • SELECT SUM(mycol) AS mysum
• SELECT * FROM pg_class c, mytab t…
![Page 38: Postgres for MySQL (and other database) people](https://reader033.vdocument.in/reader033/viewer/2022051613/54c6ac464a7959375f8b4577/html5/thumbnails/38.jpg)
MigraCon : SQL : Advanced
• WITH • Windowing
• Recursive funcCons
![Page 39: Postgres for MySQL (and other database) people](https://reader033.vdocument.in/reader033/viewer/2022051613/54c6ac464a7959375f8b4577/html5/thumbnails/39.jpg)
MigraCon : Support
• RouCne stuff: autovacuum • Monitoring (check_postgres)
• Backups (MVCC based)
![Page 40: Postgres for MySQL (and other database) people](https://reader033.vdocument.in/reader033/viewer/2022051613/54c6ac464a7959375f8b4577/html5/thumbnails/40.jpg)
Postgres : Quirks : lowercase
• Implicit case folding • CREATE TABLE abc (A int); • CREATE TABLE ABC (a int); • CREATE TABLE “abc” (“a” int); • CREATE TABLE “ABC” (“A” int); • SELECT * FROM “ABC” WHERE “A”=123;
![Page 41: Postgres for MySQL (and other database) people](https://reader033.vdocument.in/reader033/viewer/2022051613/54c6ac464a7959375f8b4577/html5/thumbnails/41.jpg)
Postgres : Quirks : CasCng
• 8.3 removed some implicit casts • SELECT 1 = ‘1’::text; • ERROR: operator does not exist: integer=text • 1. Fix the app • 2. Add the casts back in
![Page 42: Postgres for MySQL (and other database) people](https://reader033.vdocument.in/reader033/viewer/2022051613/54c6ac464a7959375f8b4577/html5/thumbnails/42.jpg)
Postgres : Quirks : COUNT(*)
• MyISAM vs INNODB • Use an index • Triggers • SELECT reltuples FROM pg_class WHERE relname = ‘foo’;
![Page 43: Postgres for MySQL (and other database) people](https://reader033.vdocument.in/reader033/viewer/2022051613/54c6ac464a7959375f8b4577/html5/thumbnails/43.jpg)
Postgres : Quirks : Schemas
• Database versus schemas versus cluster • Changes are cheap • No name‐based schemas
• The ‘public’ schema
• contrib/dblink
![Page 44: Postgres for MySQL (and other database) people](https://reader033.vdocument.in/reader033/viewer/2022051613/54c6ac464a7959375f8b4577/html5/thumbnails/44.jpg)
Postgres : Quirks : vacuum
• Newer the berer • autovacuum
![Page 45: Postgres for MySQL (and other database) people](https://reader033.vdocument.in/reader033/viewer/2022051613/54c6ac464a7959375f8b4577/html5/thumbnails/45.jpg)
Postgres : Quirks : i18n
• SQL_ASCII vs UTF‐8 • Per database only
![Page 46: Postgres for MySQL (and other database) people](https://reader033.vdocument.in/reader033/viewer/2022051613/54c6ac464a7959375f8b4577/html5/thumbnails/46.jpg)
Postgres : Quirks : Hints
• No hints per se • Smart planner
• SET enable_* EXPLAIN • Few other knobs – per cluster
![Page 47: Postgres for MySQL (and other database) people](https://reader033.vdocument.in/reader033/viewer/2022051613/54c6ac464a7959375f8b4577/html5/thumbnails/47.jpg)
Postgres : Quirks : Rules
• Last resort. ‘nuff
![Page 48: Postgres for MySQL (and other database) people](https://reader033.vdocument.in/reader033/viewer/2022051613/54c6ac464a7959375f8b4577/html5/thumbnails/48.jpg)
Postgres : Drawbacks
• ReplicaCon • In‐place upgrade (pg_migrator, Bucardo)
• Tuned for a toaster • Name
• Publicity and markeCng
pg_upgradepg_upgrade
![Page 49: Postgres for MySQL (and other database) people](https://reader033.vdocument.in/reader033/viewer/2022051613/54c6ac464a7959375f8b4577/html5/thumbnails/49.jpg)
Postgres : Strengths
• Custom everything • TransacConal DDL • PostGIS • Query planner • Support • AuthenCcaCon: pg_hba.conf
– PAM, ident, Kerberos, LDAP, …
![Page 50: Postgres for MySQL (and other database) people](https://reader033.vdocument.in/reader033/viewer/2022051613/54c6ac464a7959375f8b4577/html5/thumbnails/50.jpg)
Postgres : OrganizaCon
• Who? • Transparent meritocracy • “core” • Commirers • Mailing list, IRC, wiki • Company roles • Spread the risk • Cannot be bought (assets or people)
![Page 51: Postgres for MySQL (and other database) people](https://reader033.vdocument.in/reader033/viewer/2022051613/54c6ac464a7959375f8b4577/html5/thumbnails/51.jpg)
Postgres : Community
• Core vs. “core” • Pgfoundry, github, bucardo.org, … • PostGIS • Mailing list? Bug report? User? • InteracCon! • Wiki, advocacy, sysadmin, docs, packagers • Clients, tools, replicaCon systems • Volunteers (IRC)
![Page 52: Postgres for MySQL (and other database) people](https://reader033.vdocument.in/reader033/viewer/2022051613/54c6ac464a7959375f8b4577/html5/thumbnails/52.jpg)
Postgres : Infrastructure
• See Dave’s talk later today • Servers, companies
• Build farm
• Wiki
• Commisest
![Page 53: Postgres for MySQL (and other database) people](https://reader033.vdocument.in/reader033/viewer/2022051613/54c6ac464a7959375f8b4577/html5/thumbnails/53.jpg)
Postgres : Development
• Show me the money! • Individual developers vs. companies
• CVS vs. git • Commirers vs. patchers vs. reviewers
git wins! :)git wins!
![Page 54: Postgres for MySQL (and other database) people](https://reader033.vdocument.in/reader033/viewer/2022051613/54c6ac464a7959375f8b4577/html5/thumbnails/54.jpg)
Postgres : Version
• Roughly every year • 8.3 8.3.10 • Major version, minor version, revision
• Naming a version
![Page 55: Postgres for MySQL (and other database) people](https://reader033.vdocument.in/reader033/viewer/2022051613/54c6ac464a7959375f8b4577/html5/thumbnails/55.jpg)
Postgres : Patches
• Bug report, mailing list post, TODO list • Run up the flagpole (Tom Lane test)
– Stable? – Useful? – Spec compliant? – Side effects? – Best approach to problem?
• Diff format, formaung, docs • Added to patch queue, commisest • Patch reviewer • Commit (20 vs 300)
![Page 56: Postgres for MySQL (and other database) people](https://reader033.vdocument.in/reader033/viewer/2022051613/54c6ac464a7959375f8b4577/html5/thumbnails/56.jpg)
Postgres : Patches
• About that flagpole… • High standards • \Cming
• \dfS
![Page 57: Postgres for MySQL (and other database) people](https://reader033.vdocument.in/reader033/viewer/2022051613/54c6ac464a7959375f8b4577/html5/thumbnails/57.jpg)
Postgres : Licensing
• BSD (or MIT) • Free as in speech • Free as in beer • Plays well with others (PostGIS)
PostgreSQL license
![Page 58: Postgres for MySQL (and other database) people](https://reader033.vdocument.in/reader033/viewer/2022051613/54c6ac464a7959375f8b4577/html5/thumbnails/58.jpg)
SELECT questions FROM audience;