Understanding PostgreSQL Architecture

PostgreSQL is a client/server relational database management system (RDMS). PostgreSQL also supports various extensions, such as the Citus extension in the Azure Database for PostgreSQL Hyperscale Citus option. Once the extension is loaded into the database, it will function just like any built-in functionality.

PostgreSQL also has its own query language called pgsql. In addition, PostgreSQL supports procedural languages ​​such as Ruby on Rails.

Client/Server Architecture

PostgreSQL is based on a client/server architecture. The server stores, manages, and returns data to client programs. Client programs request data using pgSQL or one of the procedural languages ​​supported by PostgreSQL (such as PL/pgSQL).

A PostgreSQL session consists of three parts:

  • Postmaster
  • client application
  • server

Postmaster

Postmaster is the supervisor daemon process that manages the PostgreSQL server. The Postmaster daemon manages communication between the various server processes, including initializing the server, shutting down the server, handling connection requests, and performing other background processes. In Azure Database for PostgreSQL, you don't have access to the file system or the Postmaster process.

client application

Clients run queries and interact with databases on Azure Database for PostgreSQL servers. To run queries, you need a client tool such as Azure Data Studio, DBeaver, pgAdmin, or psql. You'll learn about client tools in the next module.

server process

Cluster - A single PostgreSQL server can host multiple user databases. PostgreSQL refers to this collection of databases as a cluster. Each database is independent of the other, and users and applications interact with a single database. Users are created at the cluster or server level.

The data for these databases is stored in a cluster data directory named PGDATA. The PGDATA data directory includes a file containing the running PostgreSQL version, pg_tblspc containing links to tablespaces, and pg_xlog containing write-ahead log files.

Azure Databases for PostgreSQL is a service that manages storage and the underlying file system. As a user of this server, you do not have direct access to the PGDATA directory or any of its subdirectories.

In addition to the databases you create, there are three system databases:

  • postgres - the default database. After creating the server, connect to the postgres database.
  • azure_maintenance - database for managing service processes. You do not have direct access to this database.
  • azure_sys - Query Store database. The azure_sys database or its schema must not be modified. Changing anything in azure_sys will prevent Query Store and other performance features from working properly.

Schema − A schema is a named grouping of database objects. Large databases with many objects benefit from organizing objects into schemas. For example, creating a schema for sales related objects, a schema for client related objects will make finding the right object easier.

Server Parameters - PostgreSQL has several configuration files that determine how the database engine should behave. The main PostgreSQL configuration file is called postgresql.conf.

Tablespaces - With the native implementation of PostgreSQL, the pg_tblspc subdirectory can be used to create tablespaces that are linked to the main storage area called PGDATA. Azure Database for PostgreSQL does not support tablespaces: all tables are created in the main storage area.

System catalogs − PostgreSQL includes a number of system tables and views for storing information about database objects. For example, pg_database will return all databases on the server, and pg_class stores statistics about tables.

Azure Database for PostgreSQL allows access to some directories, but not all system directories.

Extension plugins - PostgreSQL supports a series of extension plugins that extend the core functionality of the database engine. These extensions are provided in a repository called PostgreSQL Extensions Network (PGXN).

To use the PostgreSQL extension, it must be installed in the database. To install an extension, run  the CREATE EXTENSION  command from the psql tool to load the extension into the database. For example:

SELECT create_extension('postgis');

To find out which extensions are supported by Azure Database for PostgreSQL, run the following query:

SELECT * FROM pg_available_extensions;

All Azure Database for PostgreSQL servers include  the pg_stat_statements extension . This extension is installed to track execution statistics for SQL statements. The server parameter pg_stat_statements.track defines the statements counted by this extension. Options include:

  • top - traces all statements issued directly by the client (default).
  • None - No statements are traced.
  • All - Traces all statements, including those of nested statements and function calls.

There is a performance overhead on the server of logging each SQL statement. Set this parameter to None if you are not actively using pg_stat_statements. Note also that some third-party monitoring services may depend on pg_stat_statements.

Query Optimizer - PostgreSQL uses a cost-based approach to query optimization. The parser checks the query syntax and breaks the query into different parts. The parser creates a parse tree and passes the query to the rewriter, which applies rules to the query. The planner figures out the best way to execute a query before actually executing it.

Backend Processes - PostgreSQL process-per-transaction model. When a new user connects, PostgreSQL authenticates the user and creates a backend server process to handle the connection. Clients only interact with the server process when submitting queries and receiving query results.

see:

Understanding PostgreSQL Architecture - Training | Microsoft Learn

Guess you like

Origin blog.csdn.net/figosoar/article/details/131790842