Category: PostgreSQL

  • entity-attribute-value design in PostgreSQL – don’t do it! – CYBERTEC

    Customers have often asked me what I think of “Entity-attribute-value” (EAV) design. So I thought it would be a good idea to lay down my opinion in writing. What is entity-attribute-value design? Customers have often asked me what I think of “Entity-attribute-value” (EAV) design. So I thought it would be a good idea to lay…

  • Paranoid SQL Execution on Postgres

    Suppose that you want to be completely over-the-top paranoid about making sure that when you execute some particular SQL statement on your Postgres database, you’re doing it in the safest and least risky way? For example, suppose it’s the production database behind your successful startup’s main commercial website. If anything even causes queries to block/pause…

  • Primary Key Index is a Space Hog

    Tables in PostgreSQL have an index for the primary key and separate row storage called the heap. Other databases integrate these together or support “index-organized tables”. In this arrangement, the primary key lookup process leads directly to the row data without a secondary fetch to get the full row and the requisite additional CPU and…

  • How To Install PostgreSQL With Docker Quickly

    Many developers still install a database on their computer and work on it. It may be a preferable method, but using Docker takes only seconds to set up a database. I used PostgreSQL and Docker in my latest project. As a result, I have achieved efficiency and convenience. I will give you my experience with…

  • Copiar usaurio de un postgres a otro:

    /usr/pgsql-11/bin/pg_dumpall -p 5432 -U postgres -r | /usr/pgsql-11/bin/psql -p 5433

  • PostgreSQL Readonly User

    Rational When you create a user in postgresql, even with only select only permission, your user has a lot more privileges. Solution Connect with root user to the desired database you will be giving permissions for: mydb=# psql -h 10.10.10.10 -U postgres mydb Now lets create the user: mydb=# create user readonly with encrypted password…

  • DELETE con LIMIT en Postgres

    Sucio y desprolijo: WITH cte AS ( SELECT my_rowid /* your PK */ FROM batch WHERE bat_close_time_stamp <= 1507381943.93144 /* your condition */ /* ORDER BY ??? */ /* optional */ LIMIT 500 FOR UPDATE /* SKIP LOCKED */ ) DELETE FROM batch tbl USING cte WHERE tbl.my_rowid = cte.my_rowid; Fuente: stackoverflow.com/questions/52950430/batch-delete-in-postgres-using-a-cursor

  • Foreign data wrappers en Postgres

    Quien no se encontro alguna vez con la necesidad de traer algun dato desde un SQL Server a un Postgres…??? Bien, tenia esto: Un postgres 9.6.5 y un SQL Server 2014 SP2 (12.0.5207.0) todo en 64bits. Y supongamos que tambien tienen un usaurio y clave del SQL Server, asi como el nombre de la tabla,…

  • pgAdmin 4 v1.1, pros y contras.

    pgAdmin 4 v1.1, pros y contras.

    El pgAdmin III, tiene sucesor, un completamente nuevo pgAdmin 4 que por desgracia esta muuuuuuuuy verde. Lo pueden encontrar en su sitio: pgadmin.org Pros: Soporta v9.6 Una vez conectado el arbol carga rapido. Contras: No tiene buscar (ctrl+F), reemplazar, nuevo (ctrl+N; (ctrl+E)) No podes importar los servidores registrados en el PGAdmin 3 No podes cambiar…

  • Datazo V

    Datazo V

    SELECT unnest(string_to_array(‘1,2,3,4’, ‘,’)) un string lo transformas a un array y el unnest te lo pone en filitas… bien tecnico Saludos,

  • Copiar una base de datos en Postgres

    Copiar una base de datos en Postgres

    Para copiar una base, primero hay que tenerla sin usuarios conectados… los sacamos: SELECT pg_terminate_backend(pid) –* FROM pg_stat_activity WHERE pid <> pg_backend_pid() –and query = ‘COMMIT’ ; Luego, simplemente, creamos una nueva base con plantilla en la de origen: CREATE DATABASE base_nueva WITH TEMPLATE base_vieja OWNER postgres; Esto, la crea copiando base, estructura y datos.…

  • DATAZO IV – Modulo PG_TRGM

    DATAZO IV – Modulo PG_TRGM

    La única función que analice de acá fue la “similarity”. En XXXX la estamos usando para buscar PABLO PEREZ o PEREZ PABLO, independientemente como lo escriban te lo trae… https://www.postgresql.org/docs/current/static/pgtrgm.html Muy útil, y resuelve bastante rápido.- Saludos,

  • Como ver el estado del servidor postgressql sin ser superuser

    Como ver el estado del servidor postgressql sin ser superuser

    CREATE FUNCTION get_sa() RETURNS SETOF pg_stat_activity AS $$ SELECT * FROM pg_catalog.pg_stat_activity; $$ LANGUAGE sql VOLATILE SECURITY DEFINER; CREATE VIEW pg_stat_activity_allusers AS SELECT * FROM get_sa(); GRANT SELECT ON pg_stat_activity_allusers TO public; select * from pg_stat_activity_allusers;

  • DATAZO III – Funciones de string en Postgres, conocidas y desconocidas

    DATAZO III – Funciones de string en Postgres, conocidas y desconocidas

    n buen resumen de muchisimas funciones de strings, conocidas y desconocidas: http://postgresql-backup.com/postgresql-blog/postgres-string-functions/ Todo en un PDF: http://postgresql-backup.com/postgresql-blog/wp-content/uploads/2016/06/PostgreSQL-Cheat-Sheet_-String-Functions.pdf Por ejemplo, cómo parsear un string separado por comas: SPLIT_PART (‘1,2,3’, ‘,’, 2) = ‘2’ cómo rellenar con ceros: LPAD (‘123’, 6, ‘0’) = ‘000123’ cómo escribir con iniciales mayusculas: INITCAP (‘hi thomas’) = ‘Hi Thomas’ etc, etc…

  • Postgres Datazo II

    Postgres Datazo II

    Ayer Leo necesitaba corregir un sp de XXXX en Produccion. Me pidio por mantis corregirlo una vez, lo ejecutó y tuvo otro error. Me pidio por mantis corregirlo otra vez, lo ejecutó y tuvo otro error. A la tercera me pide permiso para alterar el sp. Puse el sp como propiedad ya no del usuario…

  • Datazo

    Datazo

    Recién tuve que hacer un insert masivo de registros borrados por error (desde Chaco) sobre una tabla de Prevencion PROD que tiene TRIGGGERS. Tomé los registros de un backup y los inserté pero NO QUIERO QUE SE DISPARE EL TRIGGER yaa que los registros “siempre estuvieron alli y no cambiaron”. Deshabilitar el trigger de la…

  • CAMBIAR ENCODING DE UTF-8 A LATIN1 EN POSTGRESQL

    CAMBIAR ENCODING DE UTF-8 A LATIN1 EN POSTGRESQL

    El cambio es muy simple, primero ingresamos al terminal toot linux y ejecutamos su – postgres Ya estamos como usuario postgres Entramos al Postgresql ejecutando psql template1 postgres Ahora veamos cual es la codificación actual de las base de datos que tenemos un nuestro servidor digitando lo siguiente: \l Debe salir algo similar a lo…

  • Esto es Hibernate

    Esto es Hibernate

    La peor consulta que me han pedido que revise en mi vida, por lejos. Esto se debe al uso de la herramienta Hibernate total, que son 1600 campos y 185 tablas en un join ;P select this_.id as id140_139_, this_.aplica_tutela as aplica2_140_139_, this_.autorizacion_id as autoriza7_140_139_, this_.cantidad_solicitada as cantidad3_140_139_, this_.copago_estimado as copago4_140_139_, this_.diagnostico_id as diagnost8_140_139_, this_.saldo_a_consumir…