Using Postgres Row-Level Security in Python and Django

13 August, 2020

Postgres introduced row-level security in 2016 to give database administrators a way to limit the rows a user can access, adding an extra layer of data protection. What's nice about RLS is that if a user tries to select or alter a row they don't have access to, their query will return 0 rows, rather than throwing a permissions error. This way, a user can use , and they will only receive the rows they have access to with no knowledge of rows they don't. Most examples of RLS limit row access by…

Continue reading

Using Postgres JSONB Fields in Django

30 July, 2020

I remember the first time I built user preferences into an app. At first, users just needed to be able to opt in or out of our weekly emails. "No big deal," I thought, "I'll just add a new field on the Users table." For a while, that was fine. A few weeks later, my boss asked me if we could let users opt into push notifications. Fine, that's just one more column on the database. Can't hurt, right? You probably see where this is going. Within months, my user table had 40 columns, and while…

Continue reading

Building SVG Components in React

09 July, 2020

React is well known as a great tool for building complex applications from HTML and CSS, but that same approach can also be used with SVG to build sophisticated custom UI elements. In this article, we'll give a brief overview of SVG, when to use it (and when not to), and how to use it effectively in a React application. We'll also briefly touch on how to integrate with d3 (which comes in very useful when working with SVG). We relied heavily on SVG to build the charting updates we launched…

Continue reading

Advanced Active Record: Using Subqueries in Rails

24 June, 2020

Active Record provides a great balance between the ability to perform simple queries simply, and also the ability to access the raw SQL sometimes required to get our jobs done. In this article, we will see a number of real-life examples of business needs that may arise at our jobs. They will come in the form of a request for data from someone else at the company, where we will first translate the request into SQL, and then into the Rails code necessary to find those records. We will be covering…

Continue reading

Introducing New Charts & Date Picker in pganalyze

29 April, 2020

Clear and flexible presentation of data is the bread and butter of a monitoring service. A good one will display the right data, but a great one can guide you toward meaningful insights. Visual representation of data in a clear and concise way can help you make decisions quickly. Today we're releasing multiple updates to pganalyze that will help you get to insights more effectively, and keep your database running smoothly. Date range selection as a first-class concept The biggest feature in our…

Continue reading

Full Text Search in Milliseconds with Rails and PostgreSQL

16 April, 2020

Imagine the following scenario: You have a database full of job titles and descriptions, and you’re trying to find the best match. Typically you’d start by using an ILIKE expression, but this requires the search phrase to be an exact match. Then you might use trigrams, allowing spelling mistakes and inexact matches based on word similarity, but this makes it difficult to search using multiple words. What you really want to use is Full Text Search, providing the benefits of ILIKE and trigrams…

Continue reading

Effectively Using Materialized Views in Ruby on Rails

16 January, 2020

It's every developer's nightmare: SQL queries that get large and unwieldy. This can happen fairly quickly with the addition of multiple joins, a subquery and some complicated filtering logic. I have personally seen queries grow to nearly one hundred lines long in both the financial services and health industries. Luckily Postgres provides two ways to encapsulate large queries: Views and Materialized Views. In this article, we will cover in detail how to utilize both views and materialized views…

Continue reading

Introducing Automated Postgres EXPLAIN Visualization & Insights

16 December, 2019

Today, we’re excited to introduce you to the next evolution of pganalyze. We updated our logo and overall brand, worked on our documentation to help you understand Postgres and its internals better and, most importantly, we’re proud to announce a new key feature on our platform: Automated EXPLAIN Visualization & Insights. Offering this functionality to you is a natural progression for us as we’re further refining our focus on providing you with even better, more detailed insights into how your…

Continue reading

Similarity in Postgres and Rails using Trigrams

19 November, 2019

You typed "postgras", did you mean "postgres"? Use the best tool for the job. It seems like solid advice, but there's something to say about keeping things simple. There is a training and maintenance cost that comes with supporting an ever growing number of tools. It may be better advice to use an existing tool that works well, although not perfect, until it hurts. It all depends on your specific case. Postgres is an amazing relational database, and it supports more features than you might…

Continue reading

Efficient GraphQL queries in Ruby on Rails & Postgres

24 September, 2019

GraphQL puts the user in control of their own destiny. Yes, they are confined to your schema, but beyond that they can access the data in any which way. Will they ask only for the "events", or also for the "category" of each event? We don't really know! In REST based APIs we know ahead of time what will be rendered, and can plan ahead by generating the required data efficiently, often by eager-loading the data we know we'll need. In this article, we will discuss what N+1 queries are, how they…

Continue reading

Postgres Connection Tracing, Wait Event Analysis & Vacuum Monitoring go into GA on pganalyze

14 April, 2019

We’re excited to announce the general availability of three new pganalyze features: Connection Tracing, Wait Event Analysis, as well as Vacuum Monitoring. These features have been developed based on the feedback of hundreds of customers monitoring their production Postgres databases using pganalyze. Thanks so much for consistently taking the time to provide us with valuable information on how you’d like to see pganalyze evolve! Postgres Connection Tracing & Wait Event Analysis One of the most…

Continue reading

New in Postgres 11: Monitoring JIT performance, Auto Prewarm & Stored Procedures

04 October, 2018

Everyone’s favorite database, PostgreSQL, has a new release coming out soon: Postgres 11 In this post we take a look at some of the new features that are part of the release, and in particular review the things you may need to monitor, or can utilize to increase your application and query performance. Just-In-Time compilation (JIT) in Postgres 11 Just-In-Time compilation (JIT) for query execution was added in Postgres 11. It's not going to be enabled for queries by default, similar to parallel…

Continue reading

Postgres Log Monitoring with pganalyze: Introducing Log Insights 2.0

24 July, 2018

TLDR: We recently released substantial improvements to our Log Insights feature, including up to 30 day history, support for Heroku Postgres, as well as support for monitoring the log files of PostgreSQL servers running on-premise. How pganalyze parses Postgres log files Its now been a bit over a year since we first released the log monitoring functionality in pganalyze, and we would like to share a major update with you today. Before diving in, a quick review how the pganalyze collector works…

Continue reading

Postgres Log Monitoring 101: Deadlocks, Checkpoint Tuning & Blocked Queries

12 February, 2018

Those of us who operate production PostgreSQL databases have many jobs to do - and often there isn't enough time to take a regular look at the Postgres log files. However, often times those logs contain critical details on how new application code is affecting the database due to locking issues, or how certain configuration parameters cause the database to produce I/O spikes. This post highlights three common performance problems you can find by looking at, and automatically filtering your…

Continue reading

Visualizing & Tuning Postgres Autovacuum

28 November, 2017

In this post we'll take a deep dive into one of the mysteries of PostgreSQL: VACUUM and autovacuum. The Postgres autovacuum logic can be tricky to understand and tune - it has many moving parts, and is hard to understand, in particular for application developers who don't spend all day looking at database documentation. But luckily there are recent improvements in Postgres, in particular the addition of pg_stat_progress_vacuum in Postgres 9.6, that make understanding autovacuum and VACUUM…

Continue reading

Whats New in Postgres 10: Monitoring Improvements

04 October, 2017

Postgres 10 has been stamped on Monday, and will most likely be released this week, so this seems like a good time to review what this new release brings in terms of Monitoring functionality built into the database. In this post you'll see a few things that we find exciting about the new release, as well as some tips on what to adjust, whether you use a hosted Postgres monitoring tool like pganalyze, or if you've written your own scripts. New "pg_monitor" Monitoring Role Most users of Postgres…

Continue reading

Introducing Log Insights: Realtime Analysis of Postgres Logs

07 June, 2017

After significant development effort, we're excited to introduce you to a new part of pganalyze that we believe every production Postgres database needs: pganalyze Log Insights UPDATE: We released pganalyze Log Insights 2.0 - read more about it in our article: Postgres Log Monitoring with pganalyze: Introducing Log Insights. In the past you used generic log management systems and setup your own filtering and altering rules, which required a lot of manual effort, as well as knowledge of all…

Continue reading

Monitoring PostgreSQL 9.5 & Improved Weekly Reports

06 July, 2015

Last week the first official alpha version of PostgreSQL 9.5 was released. Whilst the stable release is still 2-3 months away, now is a good time to review what is upcoming, and which changes and improvements we can expect. Here is an overview of the most important changes for monitoring tools: pg_stat_statements gets new columns min_time, max_time, mean_time & stddev_time - making it much easier to identify outliers in the query statistics New pg_stat_ssl view that shows active SSL connections…

Continue reading

Introducing pg_query: Parse PostgreSQL queries in Ruby

17 June, 2014

In this article we'll take a look at the new pg_query Ruby library. pg_query is a Ruby library I wrote to help you parse SQL queries and work with the PostgreSQL parse tree. We use this extension inside pganalyze to provide contextual information for each query and find columns which might need an index. At the end of this article you'll also find monitor.rb - a ready-to-use example that filters pg_stat_statements output and restricts it to only show a specific table. Existing Solutions to Parse…

Continue reading

Announcing The All-New Database Check-Up

20 March, 2014

We’ve just launched our new version of Database Check-Up - allowing you to see more quickly what could be relevant to look at in your database. In addition we’ve also revamped the detail pages of queries, tables, indices and config settings to match the new style: Improved Check-Up: Config Settings When working with other people's PostgreSQL databases, we’ve seen a lot of things, from fsync=off (which you really only want if you don’t care about your data or have no writes) to simple…

Continue reading