diff --git a/20220104155310-postgres.org b/20220104155310-postgres.org index 74e10a4..1e3603d 100644 --- a/20220104155310-postgres.org +++ b/20220104155310-postgres.org @@ -1,6 +1,6 @@ :PROPERTIES: :ID: 171ce2f7-4028-47b0-b4e0-5a4a6ccb74ac -:mtime: 20220527114623 +:mtime: 20221229103915 :ctime: 20220104155310 :END: #+title: Postgres @@ -12,7 +12,11 @@ * Fonctionne sur Solaris, SunOS, Mac OS X, HP-UX, AIX, Linux, IRIX, Digital Unix, BSD, NetBSD, FreeBSD, OpenBSD, SCO unix, NeXTSTEP, UnixWare et toutes sortes d'Unix. Depuis la version 8.0, PostgreSQL fonctionne également nativement sur Windows. * Interfaces utilisateur -** [[id:0455921f-3ac0-437e-ba76-1afb3f6f85ea][Psql]] +** CLI + * [[id:0455921f-3ac0-437e-ba76-1afb3f6f85ea][Psql]] +** Graphique + * [[https://arctype.com/][ArcType]] + * [[https://github.com/dbeaver/dbeaver][DBeaver]] * Howto ** Pour lister les utilisateurs @@ -33,5 +37,55 @@ sudo -u postgres dropdb \password #+END_SRC +* Profiling de requêtes (query plan) +** Depuis [[id:0455921f-3ac0-437e-ba76-1afb3f6f85ea][Psql]] +#+BEGIN_SRC sql +EXPLAIN (ANALYZE, COSTS, VERBOSE, BUFFERS) SELECT _stops.kind, _stops.id, _stops.name, _stops.town_name, _stops.postal_region, _stops.xepsg2154, _stops.yepsg2154, _stops.version, _stops.created_ts, _stops.changed_ts, stops.id AS id_1, stops.latitude, stops.longitude, stops.transport_mode, stops.accessibility, stops.visual_signs_available, stops.audible_signs_available, stops.record_id, stops.record_ts, stop_areas.id AS id_2, stop_areas.type +FROM _stops LEFT OUTER JOIN stops ON _stops.id = stops.id LEFT OUTER JOIN stop_areas ON _stops.id = stop_areas.id +WHERE _stops.name ILIKE '%Chaville rive droite%' +#+END_SRC + +#+BEGIN_SRC + Nested Loop Left Join (cost=148.62..250.06 rows=5 width=194) (actual time=1.213..1.346 rows=12 loops=1) + Output: _stops.kind, _stops.id, _stops.name, _stops.town_name, _stops.postal_region, _stops.xepsg2154, _stops.yepsg2154, _stops.version, _stops.created_ts, _stops.changed_ts, stops.id, stops.latitude, stops.longitude, stops.transport_mode, stops.accessibility, stops.visual_signs_available, stops.audible_signs_available, stops.record_id, stops.record_ts, stop_areas.id, stop_areas.type + Inner Unique: true + Buffers: shared hit=123 + -> Nested Loop Left Join (cost=148.33..208.53 rows=5 width=182) (actual time=1.196..1.296 rows=12 loops=1) + Output: _stops.kind, _stops.id, _stops.name, _stops.town_name, _stops.postal_region, _stops.xepsg2154, _stops.yepsg2154, _stops.version, _stops.created_ts, _stops.changed_ts, stops.id, stops.latitude, stops.longitude, stops.transport_mode, stops.accessibility, stops.visual_signs_available, stops.audible_signs_available, stops.record_id, stops.record_ts + Inner Unique: true + Buffers: shared hit=97 + -> Bitmap Heap Scan on public._stops (cost=148.04..166.99 rows=5 width=93) (actual time=1.172..1.219 rows=12 loops=1) + Output: _stops.kind, _stops.id, _stops.name, _stops.town_name, _stops.postal_region, _stops.xepsg2154, _stops.yepsg2154, _stops.version, _stops.created_ts, _stops.changed_ts + Recheck Cond: ((_stops.name)::text ~~* '%Chaville rive droite%'::text) + Heap Blocks: exact=11 + Buffers: shared hit=63 + -> Bitmap Index Scan on name_idx_gin (cost=0.00..148.04 rows=5 width=0) (actual time=1.155..1.155 rows=12 loops=1) + Index Cond: ((_stops.name)::text ~~* '%Chaville rive droite%'::text) + Buffers: shared hit=52 + -> Index Scan using stops_pkey on public.stops (cost=0.29..8.31 rows=1 width=89) (actual time=0.005..0.005 rows=1 loops=12) + Output: stops.id, stops.latitude, stops.longitude, stops.transport_mode, stops.accessibility, stops.visual_signs_available, stops.audible_signs_available, stops.record_id, stops.record_ts + Index Cond: (stops.id = _stops.id) + Buffers: shared hit=34 + -> Index Scan using stop_areas_pkey on public.stop_areas (cost=0.29..8.30 rows=1 width=12) (actual time=0.003..0.003 rows=0 loops=12) + Output: stop_areas.id, stop_areas.type + Index Cond: (stop_areas.id = _stops.id) + Buffers: shared hit=26 + Planning: + Buffers: shared hit=22 + Planning Time: 1.015 ms + Execution Time: 1.521 ms +(28 rows) + +Time: 3.503 ms +#+END_SRC + +** Visualisation de Query plan +Différents sites permettent de visualiser graphiquement les query plans: + * Gratuits: + * [[https://explain.dalibo.com/][PEV2 - Dalibo]] + * Payants: + * [[https://app.pgmustard.com/login][PgMustard]] + * Références * [[https://stackoverflow.com/questions/45395538/postgres-md5-password-plain-password][Postgres: MD5 Password / Plain password - Github]] + * [[https://www.postgresql.org/docs/current/sql-explain.html][Sql-explain - PostgreSQL]] diff --git a/20220104155517-psql.org b/20220104155517-psql.org index 51864d9..b62c5b6 100644 --- a/20220104155517-psql.org +++ b/20220104155517-psql.org @@ -1,12 +1,12 @@ :PROPERTIES: :ID: 0455921f-3ac0-437e-ba76-1afb3f6f85ea -:mtime: 20220104160506 +:mtime: 20221229101120 :ctime: 20220104155517 :END: #+title: Psql #+filetags: :postgre:database: -Interface en ligne de commande permettant la saisie de requêtes SQL, directement ou par l'utilisation de procédures +Interface en ligne de commande permettant la saisie de requêtes PostgreSQL, directement ou par l'utilisation de procédures stockées. * Commandes