pg 95 new capabilities
TRANSCRIPT
![Page 1: Pg 95 new capabilities](https://reader031.vdocument.in/reader031/viewer/2022022413/58ed61001a28ab02068b4627/html5/thumbnails/1.jpg)
PostgreSQL 9.5New capabilities, new features, new year
James [email protected]@yahoo.com@jamey_hanson
Freedom Consulting Grouphttp://www.freedomconsultinggroup.com
11-Feb-16
![Page 2: Pg 95 new capabilities](https://reader031.vdocument.in/reader031/viewer/2022022413/58ed61001a28ab02068b4627/html5/thumbnails/2.jpg)
PostgreSQL: mission capable database platform
PostgreSQL Migration Team 11-Feb-162
v.
PostgreSQL retains its position as the most advanced relationaldatabase platform*with unique NoSQL,text, geospatial,analytic, network,and developmentlanguage capabilities.
* For data on a single-server scale of a few TB.
![Page 3: Pg 95 new capabilities](https://reader031.vdocument.in/reader031/viewer/2022022413/58ed61001a28ab02068b4627/html5/thumbnails/3.jpg)
} JSON CRUD operations and pretty-print} Row-level security … saved for a later presentation} UPSERT “UPDATE if matching, otherwise INSERT”} Password complexity, expiration and management (EDB*)} Re-sync replication partners after failover} Foreign table constraints and inheritance} New analytics for CUBE and ROLLUP with GROUP BY} New versions of PostGIS with added geospatial tools} Lots and lots of administrative improvements
*EnterpriseDB PostgreSQL Plus Advanced Server
PostgreSQL and PPAS* new capabilities
PostgreSQL Migration Team 11-Feb-163
![Page 4: Pg 95 new capabilities](https://reader031.vdocument.in/reader031/viewer/2022022413/58ed61001a28ab02068b4627/html5/thumbnails/4.jpg)
} PostgreSQL now speaksJSON* fluently.
You have two choicesfor full JSON support:MongoDBand PostgreSQL
We are JSONic!
PostgreSQL Migration Team 11-Feb-164
* and GeoJSON too!
![Page 5: Pg 95 new capabilities](https://reader031.vdocument.in/reader031/viewer/2022022413/58ed61001a28ab02068b4627/html5/thumbnails/5.jpg)
} Why is this such a really, really big deal?} From Gartner Group’s 2015 Magic Quadrant on Operational Databases
By 2017, the “NoSQL” label will cease to distinguish DBMSs, which will reduce its value and result in it falling out of use. By 2017, all leading operational DBMSs will offer multiple data models, relational and NoSQL, in a single platform.
}* Oracle and MySQL include a read-only JSON data type, but no UPDATE functions. MS SQLServer can present SQL results as JSON, but there is no JSON data type.
JSON CRUD operations and pretty-print
PostgreSQL Migration Team 11-Feb-165
PostgreSQL is for first, best and only RDBMS* to support CRUDand pretty-print on JSON.
![Page 6: Pg 95 new capabilities](https://reader031.vdocument.in/reader031/viewer/2022022413/58ed61001a28ab02068b4627/html5/thumbnails/6.jpg)
} JSON documents in RDBMSs read-only and indexable. The model was …} Create a JSON document} Store and index it in the database} Retreive the JSON document} Make changes to the document in the application} Put the changed JSON back in the database
} PostgreSQL 9.5 adds ...} UPDATE values, included array elements and nested JSON} REMOVE nulls, which are common when converting from
RDBMS} ADD elements or UPDATE if the element already exists
JSON CRUD operations
PostgreSQL Migration Team 11-Feb-166
![Page 7: Pg 95 new capabilities](https://reader031.vdocument.in/reader031/viewer/2022022413/58ed61001a28ab02068b4627/html5/thumbnails/7.jpg)
} JSON is intended to be both machine and human readable} But a JSON document is all on one line, without returns … not
very human readable} Traditionally, JSON is “prettied” in the applicaiton code of with
MongoDB
} PostgreSQL 9.5 includes JSONB_PRETTY(), which presents JSON in human-readable form
} Example from a table of airport JSON documents:
SELECT JSONB_PRETTY(airports)FROM airports_jsonWHERE airports ->> 'ident' = 'KCGS';
JSON pretty-print
PostgreSQL Migration Team 11-Feb-167
![Page 8: Pg 95 new capabilities](https://reader031.vdocument.in/reader031/viewer/2022022413/58ed61001a28ab02068b4627/html5/thumbnails/8.jpg)
College Park Airport, KCGS
8
{"name": "College Park Airport","type": "small_airport","ident": "KCGS","region": "Maryland","country": "United States","elevation_ft": 48,"airport_keywords": [
"DC3","ADIZ"
],"location": {
"type": "Point","coordinates": [
-76.9223022461,38.9805984497
]},"airport_home_link": "http://www.collegeparkairport.aero/","runways": [
{"he_ident": "33","length_ft": 2607,"he_location": {
"type": "Point","coordinates": [
-76.9192,38.9779
![Page 9: Pg 95 new capabilities](https://reader031.vdocument.in/reader031/viewer/2022022413/58ed61001a28ab02068b4627/html5/thumbnails/9.jpg)
} Database user accounts can have a security-function applied to all of their SQL} “tables can have row security policies that restrict, on a per-user
basis, which rows can be returned by normal queries or inserted, updated, or deleted by data modification commands”
PostgreSQL 9.5 documentation, 5.7 Row Security Policies
Row-level security … for a later presentation
PostgreSQL Migration Team 11-Feb-169
![Page 10: Pg 95 new capabilities](https://reader031.vdocument.in/reader031/viewer/2022022413/58ed61001a28ab02068b4627/html5/thumbnails/10.jpg)
} INSERT operator adds optional ON CONFLICT clause} DO NOTHING
} DO UPDATE SET …COLUMN_NAME = <value_expression_or_subselect>WHERE ...
} Ex.CREATE TABLE distributors (id BIGSERIAL PRIMARY KEY,name TEXT);
INSERT INTO distributors (name) VALUES('Kirkland'),('Peapod');
UPSERT: “UPDATE if matching, otherwise INSERT”
PostgreSQL Migration Team 11-Feb-1610
![Page 11: Pg 95 new capabilities](https://reader031.vdocument.in/reader031/viewer/2022022413/58ed61001a28ab02068b4627/html5/thumbnails/11.jpg)
} Option I: if the record exists, do nothingINSERT INTO distributors (id, name) VALUES
(2, 'Nature''s Promise')ON CONFLICT (id) DO NOTHING;
} Option II: if the id exists, update the nameINSERT INTO distributors (id, name) VALUES
(2, 'Nature''s Promise')ON CONFLICT (id) DO UPDATESET name = 'Nature''s Promise';
UPSERT: “UPDATE if matching, otherwise INSERT”
PostgreSQL Migration Team 11-Feb-1611
![Page 12: Pg 95 new capabilities](https://reader031.vdocument.in/reader031/viewer/2022022413/58ed61001a28ab02068b4627/html5/thumbnails/12.jpg)
} Accounts get PROFILEs, which can define …} Failed login
attempts} Password
complexityfunction,re-use,expiration,etc.
Password PROFILES for complexity and mgmt. (EDB)
PostgreSQL Migration Team 11-Feb-1612
![Page 13: Pg 95 new capabilities](https://reader031.vdocument.in/reader031/viewer/2022022413/58ed61001a28ab02068b4627/html5/thumbnails/13.jpg)
} DEFAULT profile specifiesFAILED_LOGIN_ATTEMPTS UNLIMITEDPASSWORD_LOCK_TIME UNLIMITEDPASSWORD_LIFE_TIME UNLIMITEDPASSWEORD_GRACE_TIME UNLIMITEDPASSWORD_REUSE_TIME UNLIMITEDPASSWORD_REUSE_MAX UNLIMITEDPASSWORD_VERIFY_FUNCTION NULL
} Database superusers can ALTER PROFILE} Functional equivalent and 100% syntactically compatible
with Oracle RDBMS
Password PROFILES for complexity and mgmt. (EDB)
PostgreSQL Migration Team 11-Feb-1613
![Page 14: Pg 95 new capabilities](https://reader031.vdocument.in/reader031/viewer/2022022413/58ed61001a28ab02068b4627/html5/thumbnails/14.jpg)
} Previously, PostgreSQL audit logs only included the database username, such as JBOSS_USER} Logged the database user, not the person using the application
} edb_audit_tag allows the application to “tag” each database session with an identifier that is written to the csv or xml audit log} Similar to Oracle application_context
Audit application user (EDB)
PostgreSQL Migration Team 11-Feb-1614
vs.
![Page 15: Pg 95 new capabilities](https://reader031.vdocument.in/reader031/viewer/2022022413/58ed61001a28ab02068b4627/html5/thumbnails/15.jpg)
} UTL_RAW packageUTL_HTTP.WRITE_LINE &.WRITE_TEXT
DBMS_SESSION..SET_ROLE
} WAIT n seconds in FOR UPDATE statements} Limits statement failures caused by locks
(Even) more Oracle compatibility (EDB)
PostgreSQL Migration Team 11-Feb-1615
![Page 16: Pg 95 new capabilities](https://reader031.vdocument.in/reader031/viewer/2022022413/58ed61001a28ab02068b4627/html5/thumbnails/16.jpg)
} PostgreSQL already has simple, stable and fast replication} Automatic or manual failover in MASTER => SLAVE
partnerships
} Now, the original MASTER database can be re-synchronized after a failover without a full database copyusing pg_rewind
} Makes replication failover a much smaller deal} Suitable for testing, patches, upgrades and other new business
cases
Re-sync replication partners after failover
PostgreSQL Migration Team 11-Feb-1616
![Page 17: Pg 95 new capabilities](https://reader031.vdocument.in/reader031/viewer/2022022413/58ed61001a28ab02068b4627/html5/thumbnails/17.jpg)
} External data sources can appear as PostgreSQL tables, including constraints and inheritance} OS files, including JSON!} Other RDBMSs (Oracle, MySQL, etc.) via O/JDBC} Anything you have a connector for (pgbson for MongoDB)
} Constraints are not enforced, but it means that a foreign table can be part of a foreign key
Foreign table constraints and inheritance
PostgreSQL Migration Team 11-Feb-1617
![Page 18: Pg 95 new capabilities](https://reader031.vdocument.in/reader031/viewer/2022022413/58ed61001a28ab02068b4627/html5/thumbnails/18.jpg)
} GROUP BY multiple columns …SELECT * FROM items_sold; brand | size | salesFoo | L | 10 Foo | M | 20 Bar | M | 15Bar | L | 5
SELECT brand, size, sum(sales)FROM items_soldGROUP BY GROUPING SETS ((brand), (size), ());brand | size | sumFoo | | 30Bar | | 20
| L | 15| M | 35| | 50
New analytics for CUBE & ROLLUP with GROUP BY
PostgreSQL Migration Team 11-Feb-1618
![Page 19: Pg 95 new capabilities](https://reader031.vdocument.in/reader031/viewer/2022022413/58ed61001a28ab02068b4627/html5/thumbnails/19.jpg)
1`
} More capabilities for aggregate functions using all sorts of combinations of columns and values …
} Plus native support for many languages ...
New analytics for CUBE & ROLLUP with GROUP BY
PostgreSQL Migration Team 11-Feb-1619
![Page 20: Pg 95 new capabilities](https://reader031.vdocument.in/reader031/viewer/2022022413/58ed61001a28ab02068b4627/html5/thumbnails/20.jpg)
} PostGIS 2.2 installed with PostgreSQL and PPAS 9.5 included with PostgreSQL. Simpler &cheaper the Oracle and ESRI
} ST_SubDivide divides large shapes
} 3D operators for Known NearestNeighbor (KNN)
} Compressed output to TinyWell Known Text (TWKB)
} GeoJSON generator} More & faster functions for geometry data type
New PostGIS with added geospatial tools
PostgreSQL Migration Team 11-Feb-1620
![Page 21: Pg 95 new capabilities](https://reader031.vdocument.in/reader031/viewer/2022022413/58ed61001a28ab02068b4627/html5/thumbnails/21.jpg)
} New index type for sorted ranges of data (like timestamps) BRIN
} Select sample data fromlarge tables
} Speed up CREATE INDEX} SSL diagnostic view} View into progress of
replication} Hint suggestions for
mistyped column names} SELECTwith skip locked option
Lots and lots of administrative improvements
PostgreSQL Migration Team 11-Feb-1621
![Page 22: Pg 95 new capabilities](https://reader031.vdocument.in/reader031/viewer/2022022413/58ed61001a28ab02068b4627/html5/thumbnails/22.jpg)
} ExampleSELECT elevationFROM airportsLIMIT 10;
… but the actual column is airports.elevation_ft
ERROR: column "elevation" does not exist
HINT: Perhaps you meant to reference the column "airports.location" or the column "airports.elevation_ft".
Hint suggestions for mistyped column names
PostgreSQL Migration Team 11-Feb-1622
![Page 23: Pg 95 new capabilities](https://reader031.vdocument.in/reader031/viewer/2022022413/58ed61001a28ab02068b4627/html5/thumbnails/23.jpg)
} JSON CRUD operations and pretty-print} Row-level security … saved for a later presentation} UPSERT “UPDATE if matching, otherwise INSERT”} Password complexity, expiration and management (EDB*)} Re-sync replication partners after failover} Foreign table constraints and inheritance} New analytics for CUBE and ROLLUPwith GROUP BY} New versions of PostGIS with added geospatial tools} Lots and lots of administrative improvements
*EnterpriseDB PostgreSQL Plus Advanced Server
PostgreSQL and PPAS new capabilities
PostgreSQL Migration Team 11-Feb-1623
![Page 24: Pg 95 new capabilities](https://reader031.vdocument.in/reader031/viewer/2022022413/58ed61001a28ab02068b4627/html5/thumbnails/24.jpg)
Arethereany questions orfollow up?
24