Comparing Postgres's JSONB with Couchbase — Can Postgres really take the place of a ‘NoSQL’ document-oriented database? It’s interesting to see something like this from a document-oriented database vendor, especially as it’s reasonably fair to Postgres (while still focusing on Couchbase’s strengths, naturally).
Denis Rosa (Couchbase)
|
How Postgres Can Not Be 'Bought Out' — While MySQL was an open source database, Oracle still essentially managed to take the project over by acquiring its parent company. This can’t happen with Postgres.
Umair Shahid
|
supported by
💡 Tip of the Week
Using pgstattuple to look at dead rows and free space
pgstattuple is a built-in Postgres extension that provides a variety of functions for looking at statistics of various objects within your database. One use is for checking how many dead rows (often caused when data is deleted from a table) there are or how much free space there is within a table.
Let's create a table with 1000 rows of data and see what info pgstattuple can give us:
|
CREATE TABLE numbers (id int);
INSERT INTO numbers SELECT * FROM generate_series(1,1000);
|
Now let's get pgstattuple running and query our new table with it:
|
CREATE EXTENSION pgstattuple;
SELECT * FROM public.pgstattuple('numbers');
|
These stats show us how many tuples (i.e. rows) are in our table (1000), how many dead tuples there are (0) and any free space remaining within the table.
Let's delete half the rows to get some dead rows:
|
DELETE FROM numbers WHERE id < 500;
SELECT * FROM public.pgstattuple('numbers');
|
Now we get a dead_tuple_count of 499 — the number of rows we deleted! But the overall table_len is the same.. because of those dead rows. This can be resolved by running:
|
Re-running pgstattuple at this stage will show no dead rows, but the free_space will jump up.. with table_len remaining the same! The reason for this is that VACUUM will clean up dead rows and convert them into free space (which can be re-used for new rows), but you need to go one step further and use VACUUM FULL if you really want Postgres to rewrite the table and free up that space (though you need to take care of doing that on a production table as it can be very slow and locks the table for the entire time).
This week's tip is sponsored by GitPrime. Get your copy of their new field guide '20 Patterns to Watch for in Engineering Teams', filled with actionable insights to help debug your development process with data.
|
|
🗓 Upcoming Postgres Events
|
|
|