Are there any difference between data integrity and data consistency?

They are not only different, they are orthogonal. Inconsistency: A DB that reported employee Joe Shmoe’s department as Sales but that didn’t list Joe Shmoe among the employees in the Sales department would be inconsistent. It’s a logical property of the DB, independent of the actual data. Integrity: A DB that reported jOe SaleS to … Read more

What is the differences between the term SSTable and LSM Tree

Probably one of the best explanations of SSTables and LSM-Trees for mortals is given by Martin Kleppmann in his “Designing Data-Intensive Applications” book. These data structures are explained in chapter 3, “Storage and Retrieval”, pages 69 through 79. It’s a really great read, I would recommend the whole book! Impatient ones could find my synopsis … Read more

Keep PostgreSQL from sometimes choosing a bad query plan

If the query planner makes bad decisions it’s mostly one of two things: 1. The statistics are inaccurate. Do you run ANALYZE enough? Also popular in its combined form VACUUM ANALYZE. If autovacuum is on (which is the default in modern-day Postgres), ANALYZE is run automatically. But consider: Are regular VACUUM ANALYZE still recommended under … Read more

FOR EACH STATEMENT trigger example in PostgreSQL

OLD and NEW are null or not defined in a statement-level trigger. Per documentation: NEW Data type RECORD; variable holding the new database row for INSERT/UPDATE operations in row-level triggers. This variable is null in statement-level triggers and for DELETE operations. OLD Data type RECORD; variable holding the old database row for UPDATE/DELETE operations in … Read more

How to get the OID of a Postgres table?

To get a table OID, cast to the object identifier type regclass (while connected to the same DB!). This finds the first table (or view etc.) with the given (unqualified) name along the search_path or raises an exception if not found: SELECT ‘mytbl’::regclass::oid; Schema-qualify the table name to remove the dependency on the search path: … Read more

How to stop a Postgres script when it encounters an error?

I think the solution to add following to .psqlrc is far from perfection \set ON_ERROR_STOP on there exists much more simple and convenient way – use psql with parameter: psql -v ON_ERROR_STOP=1 better to use also -X parameter turning off .psqlrc file usage. Works perfectly for me p.s. the solution found in great post from … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)