Latest posts from Paul Ramsey

  • Postgres Insider Terminology

    Paul Ramsey

    Last week Craig Kerstiens published a great introduction to Postgres terminology , covering some of the basics you might run into when just getting started. The funny thing about jargon is how quickly we get used to it, and forget we are even using it. It becomes part of the secret handshake, the way we signal to other members of our tribe that we're part of the group. When I first started going to Postgres conferences and listening to talks by Postgres core developers I suddenly found myself...

    Read More
  • 5 min read

    Moving Objects and Geofencing with Postgres & PostGIS

    Paul Ramsey

    In a recent post , we introduced pg_eventserv and the real-time web notifications from database actions. In this post, we will dive into a practical use case: displaying state, calculating events, and tracking historical location for a set of moving objects . This demonstration uses pg_eventserv for eventing, and pg_featureserv for external web API, and OpenLayers as the map API, to build a small example application that shows off the common features of moving objects systems. Try it...

    Read More
  • Be Ready! Public schema changes in Postgres 15

    Paul Ramsey

    The end is nigh! PostgreSQL has substantially tightened restrictions on the use of the "public" schema. Here, a standard login user (not superuser) tries to make a table, as one does: NoooO! Why can I not write a table into public? For developers and experimenters, one of the long-time joys of PostgreSQL has been the free-and-easy security policy that PostgreSQL has shipped with for the "public" schema. • "public" is in the default , so you can always find things in it; and, • any user can cr...

    Read More
  • Real-time Database Events with pg_eventserv

    Paul Ramsey

    By combining triggers, the PostgreSQL system, and the pg_eventserv service, you can build a real-time application that keeps your web application state perfectly in sync with your database state. pg_eventserv converts events from the PostgreSQL event bus to standard WebSockets messages that any web client can handle. For multi-user real-time applications (like a fleet tracker, or auction system, for example), this setup can be a boon! The database is the central source-of-truth, and all ap...

    Read More
  • Generate Unlimited Crypto Using Postgres!

    Paul Ramsey

    Ha ha, made you look! This post is not a crazy scam (you be the judge) but just a practical description of using cryptographical algorithms to encrypt and decrypt data inside PostgreSQL. There's already a lot of encryption in Crunchy Bridge ! First, your data are "encrypted at rest". That means that the "volumes" (what in an earlier era would be called the disk drives) your data is saved to are encrypted. Also all the backup files generated by your server are encrypted. In practice, this means...

    Read More
  • Rise of the Anti-Join

    Paul Ramsey

    Find me all the things in set "A" that are not in set "B". This is a pretty common query pattern, and it occurs in both non-spatial and spatial situations. As usual, there are multiple ways to express this query in SQL, but only a couple queries will result in the best possible performance. The non-spatial setup starts with two tables with the numbers 1 to 1,000,000 in them, then deletes two records from one of the tables. The spatial setup is a 2M record table of geographic names, and a 3K rec...

    Read More
  • Postgres Indexing: When Does BRIN Win?

    Paul Ramsey

    The PostgreSQL BRIN index is a specialized index for (as the documentation says) "handling very large tables in which certain columns have some natural correlation with their physical location within the table". For data of that sort, BRIN indexes offer extremely low insert costs (good for high velocity data) and extremely small index sizes (good for high volume data). But what data has this "natural correlation"? Most frequently, data with a timestamp that is continuously adding new rows. • A l...

    Read More
  • Choosing a PostgreSQL Number Format

    Paul Ramsey

    It should be the easiest thing in the world: you are modeling your data and you need a column for some numbers, what type do you use? PostgreSQL offers a lot of different number types, and they all have advantages and limitations. You want the number type that is going to: • Store your data using the smallest amount of space • Represent your data with the smallest amount of error • Manipulate your data using the correct logic Store your data using the smallest amount of space Represent your da...

    Read More
  • 6 min read

    Postgres' Clever Query Planning System

    Paul Ramsey

    The sheer cleverness of relational databases is often discounted because we so frequently use them for very simple data management tasks. Serialize an object into a row, store with unique key. yawwwn Search for unique key, deserialize row into an object. yawwwwwwn The real power of relational databases is juggling "relations" (aka tables) in large numbers and figuring out on-the-fly the most effective way to filter out rows and find an answer. PostgreSQL has an undeniably clever query plannin...

    Read More
  • 5 min read

    Instant Heatmap with pg_featureserv

    Paul Ramsey

    The pg_featureserv micro-service is a thin middleware that binds tables and functions in a PostgreSQL database to a JSON collections API, accessible over HTTP. Using the Crunchy Bridge container apps , I'm going to give a quick overview of how to set up a web based spatial heatmap from Postgres. The application uses PostgreSQL to store and search 2.2M geographic names in the USA. Type in the search box and the auto-fill form will find candidate words. Select a word, and the database will pe...

    Read More