Skip to content

Instantly share code, notes, and snippets.

View danypr92's full-sized avatar

Daniel Palomar Rodríguez danypr92

View GitHub Profile
@danypr92
danypr92 / explore_slow_db_query.md
Last active January 28, 2018 13:33
Explore slow database queries

Find slow query

  • First find the PID of the main process:
$ps faux
postgres 10980 35.3  6.9 297584 141476 ?       Ss   14:45   5:17  \_ postgres: 9.6/main: danypr92 staging [local] idle in transaction
  • We can use the table pg_stat_activity searching by the PID:
@danypr92
danypr92 / posgresql_findings.md
Last active August 16, 2018 10:06
Aprendizaje recopilado sobre Postgresql al investigar las unas queries lentas.

Introduccion

Comenzamos a investigar las queries que se realizaban al investigar un importador de CSVs que se utilizaba en una instancia de tryton 3.8.

Este importador cargaba en base de datos una serie de registros de consumo. Para ello se necesitaba conocer el contrato al que iban asociados, el tipo de producto al que pertenecía el consumo y la linea de factura a la que se enlazaría.

Podemos aprovechar para estudiar el modelo de datos que utilizamos, ya que la linea de factura ya contiene el tipo de producto y el contrato relacionadas. No se aprovecha el modelo relacional de Postgresql. este proceso, con todas sus comprobaciones, era muy costoso.

@danypr92
danypr92 / explain_analyze_materialized_view.out
Last active March 21, 2018 10:54
Difference between `VIEW` or `MATERIALIZED VIEW` performance cost in PostgreSQL 9.5.
test-readonly=# EXPLAIN ANALYZE(select * from party_materialized_view);
QUERY PLAN
---------------------------------------------------------------------------------------------------------------------------
Seq Scan on party_materialized_view (cost=0.00..138.04 rows=1904 width=473) (actual time=0.018..1.022 rows=5235 loops=1)
Planning time: 0.131 ms
Execution time: 1.271 ms
(3 rows)
test-readonly=# EXPLAIN ANALYZE(select * from party_materialized_view where identifier_code = 'ESX640B');
QUERY PLAN
@danypr92
danypr92 / known_tryton_trigger_condition_eval.md
Last active April 4, 2018 16:34
Problema con la evaluación de condiciones de los triggers de Tryton 3.8

Queremos un trigger que al cambiar un contrato de estado activation_scheduled a requested ejecute una acción determinada.

Se define el triguer con los siguientes parametros:

id                 | 10
create_uid         | 34
on_create          | f
create_date        | 2018-03-28 09:29:31.938303
name               | Trigger A
on_delete | f
@danypr92
danypr92 / product_template.md
Created April 19, 2018 11:14
Product Template
                                                                       Table "public.product_template"
         Column         |              Type              |                           Modifiers                           | Storage  | Stats target |       Description       
------------------------+--------------------------------+---------------------------------------------------------------+----------+--------------+-------------------------
 id                     | integer                        | not null default nextval('product_template_id_seq'::regclass) | plain    |              | 
 category               | integer                        |                                                               | plain    |              | Category
 create_uid             | integer                        |                                                               | plain    |              | Create User
 create_date            | timestamp(6) without time zone |                                          
class Contract:
"""
This overwrite of class Contract extend functionality of Contract
vanilla model.
Add the necessary functions to represent a ISP Contract.
"""
__metaclass__ = PoolMeta
__name__ = 'contract'
@danypr92
danypr92 / tryton_required_in_transaction_workflow.md
Last active May 10, 2018 09:44
Descripción del problema de validacion de campos en las transiciones de un workflow.

Trabajamos con la versión 3.8 de Tryton (sabemos que ya no tiene soporte, pero no podemos hacer la migracion a una versión más reciente en estos momentos.)

Tenemos el modelo Contract con los siguientes atributos:

class Contract:                                                                                                                                                                     

__metaclass__ = PoolMeta                                                                                                                                                        
__name__ = 'contract'
# Then copy this service in the `/etc/systemd/system/ara.local.service`
# Run your service with:
# # systemctl start ara.local.service
# Visit your ARA app in http://127.0.0.1:9191/
# -----------------------------------
# ARA systemd service
[Unit]
Description=ARA server
@danypr92
danypr92 / ara-installation.md
Last active May 21, 2018 12:10
Installation and use instruction to work with ARA - https://github.com/openstack/ara

Requirements

You can use this instructions without virtualenvwrapper making changes in service unit.

@danypr92
danypr92 / somconnexio_pull_request_template.md
Created July 5, 2018 10:30
SomConnexió Pull Request Template

Title

Trello Card:

Error or Feature to implement

Problem solved or Process to cover with new feature

Changes done

--