Database Requirements for Analytical Use Cases
local graph
Chapter 9 — Database Requirements for Analytical Use Cases
Section titled “Chapter 9 — Database Requirements for Analytical Use Cases”Database Requirements for Analytical Use Cases
Section titled “Database Requirements for Analytical Use Cases”Modern businesses operate in an environment where data-driven decision-making is essential, not optional. Historically, databases were built to process and record transactions—capturing the operational heartbeat of an organization. However, as competition intensifies and market conditions shift more rapidly, relying solely on transactional systems without integrated analytical capabilities puts companies at a disadvantage because their business decisions are not data-driven. This makes them slow to react to changing market conditions. Agile companies must analyze their operational data in real time to remain nimble and competitive.
Decision cycles that once took weeks or months now shrink to days or even hours. This shift means analytics can no longer be a separate step done after the fact; instead, it must be integrated into the same systems that handle daily transactions. By combining analytics directly with transactional data, businesses can eliminate delays, streamline processes, and enable teams to respond immediately to emerging trends and opportunities.
Furthermore, the modern business environment rewards organizations that can transform raw data into real-time insights. Intuition and experience still matter, but they are now supported—and often confirmed—by data-driven evidence. Combining transactions and analytics provides decision-makers at all levels with a unified view of the business. This connection not only enhances operational efficiency but also fosters a culture of ongoing learning and informed decision-making, enabling businesses to navigate uncertainty with greater confidence.
Whereas the first part of the book focused on using PostgreSQL 18 for transactional applications, the subsequent chapters will demonstrate how PostgreSQL can be utilized to handle the analytics aspects of the modern business environment, before diving into using PostgreSQL with AI for even deeper insight and improved customer intimacy.
In this chapter, we will examine the analytics business requirements and how they differ from those of a transactional system. We will also explore the technical implications and how they can be met with PostgreSQL. This is the foundation for our deep dive into the analytics data models, data transformations, analytics queries, and text analysis using PostgreSQL’s innate capabilities.
This chapter covers the following topics:
- How analytics requirements differ from transactional systems
- Designing data models for analytics such as star schemas and data vaults
- Preparing and transforming data for analytical workloads
- Scaling PostgreSQL for read-heavy analytics
- Handling historical, multi-source, and multi-format data
- Managing security, access control, and the PostgreSQL ecosystem for analytics
Business requirements for analytics solutions
Section titled “Business requirements for analytics solutions”Analytics applications differ significantly from transactional use cases. Elaborating on the business requirements first will help you understand the difference in technical architectures:
- Different n ature: Analytical requests are different from transactions, even though both involve rows and columns. A typical analytics request might be ” Show me the growth of The Gap-branded articles in each state for the last three months and identify the top 3 products for each state.” In contrast, a transactional request could be, for example, ” Add 15 Boss Dress Shirts to inventory.” While transactions usually search for a small number of rows in multiple tables and then update a few of those rows, analytics requests tend to read many rows across numerous tables, then aggregate and analyze them, but rarely modify any data. Transactions are typically very short and execute within milliseconds, whereas analytical requests can take much longer—some may take hours. Transactions and analytics also tend to have different end users. While transactions typically occur within business applications, such as e-commerce or banking systems, analytics are often performed by humans with specific questions or scheduled tasks, such as generating a daily sales report, or by automated schedules that update predefined reports, for example, a quarterly customer profitability analysis.
- Single s ystem versus m ulti- s ystem: Transactions typically occur within a single system, such as an order management system. Analytics systems often integrate data from many sources. A data warehouse might combine data from loyalty systems, e-commerce systems, the order management system, and the receivables system to provide a comprehensive, 360-degree view of a customer. The data warehouse, which contains data on many enterprise subject areas, can, in turn, feed multiple subject-area-specific data marts, as seen in Figure 9.1.
Figure 9.1: Business systems feed data into data warehouses and data marts
This means that the data must be moved from the source systems into the analytics system, then integrated with data from other sources, before it is available for analytical requests.
- Current d ata versus h istorical d ata: While transactional systems work on “active” data—meaning the dataset that participates in current transactions—analytical systems include historical data to support long-term trend analysis. In practice, both systems also require data retention and purging policies for performance, cost, and regulatory compliance (for example, GDPR), often retaining only what is necessary and sometimes keeping older history in aggregated or anonymized form. The integration of data from multiple systems, along with the need to retain historical data, implies that analytical systems must handle significantly larger volumes of data.
- Differentiated a uditing and s ecurity: It also means that the security and audit requirements can be more complex. For example, when we want to give individual members of the field team access to reports, we want to ensure they can only see sales for their customers. Audit requirements also increase. In some applications, we may want to track all access to sensitive information.
- Near -r eal- t ime a nalytics: Historically, analytics occurred after business transactions were completed, often days later. This was mainly due to the time it took to move and integrate the data, as well as differences in the technical architectures required to meet analytics needs. However, modern business requirements have changed, and such latency is no longer acceptable. On the one hand, we have much tighter integration of analytics with the running business. For example, when we analyze the failure rate on a production line, we need real-time analytics—identifying today that Line A was about to fail yesterday has limited value. On the other hand, business decisions, such as pricing or restocking, must be driven by real-time data to be maximally effective. For example, we need to be able to ask whether today’s sales of a particular item in a specific store have exceeded forecast, so that we can accelerate resupply to avoid shortfalls. In practice, “near-real-time” typically means seconds to minutes, depending on the decision being made and the freshness the metric truly requires. Near-real-time analytics has become a key business requirement.
- Polymorphic d ata: Last, but not least, is the difference in data elements. Transactions traditionally focus on numbers and character strings. While that was the traditional scope of analytics, we have recently seen an increasing use of other data types, such as text, PDFs, and even images, in analytics applications. The advent of AI and the ability to extract meaning from non-standard data and represent it as rows and columns have substantially expanded the realm of analytics.
Next, we will see how the business requirements just outlined inform specific technical decisions, and how those can be met with PostgreSQL.
Technical implications and how to meet them in PostgreSQL
Section titled “Technical implications and how to meet them in PostgreSQL”While PostgreSQL excels at meeting analytical and transactional requirements, we use the database and its capabilities differently for these use cases. For analytics, the key differences lie in the following:
- Analytics-specific ways to organize the data
- The need to query and retrieve larger datasets
- Preparing and transforming data to support analytical workloads
- Integrating data from multiple source systems
- Handling historical data
- Handling a larger variety of data formats
Most of the lessons from earlier chapters dealing with data types, functions, and procedures remain valid; others, such as data normalization, are replaced by analytics-oriented techniques, such as Data Vault modeling and star schemas.
Organizing for read vs. write
Section titled “Organizing for read vs. write”Analytics focuses on finding, reading, aggregating, and analyzing large amounts of data. Whereas in transactional applications we normalize data (see Chapter 5, Transactions, ACID Compliance, and Data Normalization) to avoid update anomalies or redundancies, data normalization is not required for analytics.

Figure 9.2: Four-dimensional star schema
Instead, we optimize the data model for quick retrieval by using analytics-oriented modeling approaches such as data vaults (typically normalized hubs/links/satellites with downstream marts for consumption) or star schemas (often denormalized for fast querying) as shown in Figure 9.2. This includes decomposing data elements; for example, a date is broken down into year, quarter, month, week, and day, allowing for easy grouping of data in any of these dimensions.
Star schemas and data vaults will be the foundations for analytics-specific queries using GROUP BY, GROUPING SETS, CUBES, ROLLUPS, and so on, which allow us to easily express complex analytical requests—for example, ” How much more did we sell last month in Massachusetts than in Nevada for the top 10 products that were made in France?”
Finding and retrieving analytics data
Section titled “Finding and retrieving analytics data”Organizing data is one thing; finding and retrieving it quickly and at scale is another. Transactional requests rely primarily on equality comparisons to identify data that is to be changed—for example, ” Add inventory for the product with ID 17 ”. Analytical requests often combine equality-focused indexes, such as the B-Tree, with range-focused indexes, such as the Block Range Index (BRIN), to retrieve large amounts of data, for example, ” Retrieve all 2024 sales transactions from Nevada.” (For an overview of PostgreSQL index types and selection guidance, see Chapter 7*,* Designing for High - Transaction Volumes and Writing Efficient Transactional Code.)
Getting OLTP data ready for OLAP
Section titled “Getting OLTP data ready for OLAP”As we have seen, analytical data is modeled and indexed differently from transactional data. Also, analytics data is often aggregated from different systems into a data warehouse. Traditionally, data was moved from transactional systems to analytics systems using an Extract, Transform, and Load (ETL) process, like shown in Figure 9.3, which was either batch-oriented (e.g., reloading the warehouse over the weekend) or built using a Change Data Capture (CDC) process. The Transform step denormalizes the data and aligns it across the multiple data sources; the Load process adds the data to the data warehouse. Updating the data marts usually does not require further transformation. Many modern platforms favor an Extract, Load, Transform (ELT) approach, where raw data is loaded first, and transformations are performed in the target system using SQL. ETL remains valuable when transformations must happen before loading, for example, for data masking/tokenization, privacy filtering, or compliance-driven redaction of sensitive fields.

Figure 9.3: ETL process
With PostgreSQL, we can utilize an incremental process that leverages logical replication to transfer data from transactional systems to the data warehouse. Triggers can be used to maintain incremental transformations by updating denormalized summary tables as new data arrives, while materialized views can persist precomputed results for analytics queries.
PostgreSQL materialized views are generally refreshed as a whole (REFRESH MATERIALIZED VIEW); there is no native “incremental refresh,” so for truly incremental aggregates, summary tables maintained via triggers (or scheduled jobs) are often preferred.

Figure 9.4: Extract-load incremental transformation
It is often advantageous to precompute specific results. For example, we know that upper management frequently accesses weekly sales numbers by store. In that case, we precompute those aggregates instead of recalculating them each time by summarizing all sales transactions for that week and each store. Materialized views and triggers are the tools of choice in PostgreSQL.
Scalability: Horizontal scale-out
Section titled “Scalability: Horizontal scale-out”Databases tend to require a lot of memory and I/O. This resource pressure increases in analytics environments, where each request processes substantial amounts of data, driving up I/O and memory requirements, especially when many users run complex queries.
For these situations, we recommend using PostgreSQL’s physical (streaming) replication to create multiple read-only replicas of the analytics system and then distribute the analytics requests across the replicas. Physical replication is efficient and low-overhead, making it well-suited for scaling read-heavy workloads. Load balancing can be handled using tools such as HAProxy or Pgpool-II to route queries across replicas.
Logical replication can also be used for horizontal scale-out in some architectures, but it is generally chosen when replication needs to be selective, involves transformation, or supports cross-version/heterogeneous targets, rather than for pure read scaling, where physical (streaming) replication is usually the better fit.
Integrating multi-model data
Section titled “Integrating multi-model data”PostgreSQL is natively multi-model. Out of the box, it handles JSONB documents and text documents. Querying JSONB documents is described in Chapter 7*,* Designing for High - Transaction Volumes and Writing Efficient Transactional Code. As part of our dive into analytics techniques, we will teach the developer how to integrate full-text searching into an analytics solution using one of PostgreSQL’s native capabilities: LIKE-based pattern matching, regular expressions, trigrams, or tsvector-based full-text search. We will also show how to use AI-based semantic search for text and images.
Controlling and auditing data access
Section titled “Controlling and auditing data access”PostgreSQL provides robust R ole- B ased A ccess C ontrol (RBAC) and audit tools, as described in Chapter 4*,* Database Requirements for High-Volume Transactional Applications. Row-based access control or Row - Level Security (RLS) provides an additional tool for automatically restricting access to data within tables. Similar effects can be achieved through views that use the security of the invoker to filter the data. For example, a seller who is a member of the Massachusetts team can be limited to accessing data for their customers. All team members can use the same view of the data. Still, they will be automatically restricted to access their data through the row- or view-level security mechanism in the database—no need to modify the view or maintain multiple versions of the same view.
Leveraging PostgreSQL’s ecosystem
Section titled “Leveraging PostgreSQL’s ecosystem”PostgreSQL has seen enormous success. Fifteen years ago, a PostgreSQL database with 1 TB of data was considered remarkable; today, there are examples of PostgreSQL systems handling over 100 TB of data in mission-critical, high-volume environments. Nevertheless, there are still situations where core PostgreSQL should be used in conjunction with third-party solutions built on PostgreSQL or designed to integrate tightly with it.
For very large analytics warehousesthat need extensive M assive P arallel P rocessing (MPP) to run complex, long-duration queries, users can consider WarehousePG or Cloudberry, both open source forks of the Greenplum® data warehouse, a data warehousing solution initially based on PostgreSQL. WarehousePG or Cloudberry are proven solutions for petabyte-scale systems, providing high-speed concurrency performance through an MPP architecture built on PostgreSQL.
Many applications benefit from columnar database architectures, which optimize I/O through compression and vectorized execution. For example, Crunchy Data has demonstrated a PostgreSQL extension approach to add columnar capabilities (rather than requiring a fork). TimescaleDB from TigerData is also implemented as a PostgreSQL extension and has achieved significant success for time-series workloads and analytics patterns that benefit from compression and specialized access methods.
PostgreSQL supports various data models (tabular, JSONB, GIS, text, vectors, and key-value pairs), but it does not yet natively support open data formats such as Parquet or Iceberg. DuckDB and pg_lake are emerging as the preferred PostgreSQL-friendly solutions for integration with open data formats.
All the extensions and forks described previously have one thing in common: they speak PostgreSQL and behave essentially like standard PostgreSQL. Thus, even when application needs exceed the capabilities of core PostgreSQL, the same skill sets and architectural principles can be applied.
Summary
Section titled “Summary”This chapter provided a high-level overview of the business requirements for analytical solutions, their architectural implications, and how to meet them with PostgreSQL. We learned that analytics architectures optimize data for read-oriented, quick retrieval and analysis of large datasets, potentially resulting from multiple source systems. Also, they contain historical data to support trend analysis and often combine classical numbers-oriented data with text-based documents.
In the following chapters, we will dive into the denormalized analytics data model, exploring data vaults and star schemas, before looking at how PostgreSQL can be used to transform transactional, normalized data into denormalized, analytics-focused models.
The denormalized models provide the foundation for analytics queries. We will show you how to create groups, use aggregates, and compile data using cubes, roll-ups, window functions, and CTEs. Last, but not least, we will explore PostgreSQL’s text search capabilities.