codekingpro/portable-devtools
115k
1<?xml version="1.0" encoding="UTF-8" standalone="no"?>2<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>52.2. How Connections Are Established</title><link rel="stylesheet" type="text/css" href="stylesheet.css" /><link rev="made" href="pgsql-docs@lists.postgresql.org" /><meta name="generator" content="DocBook XSL Stylesheets Vsnapshot" /><link rel="prev" href="query-path.html" title="52.1. The Path of a Query" /><link rel="next" href="parser-stage.html" title="52.3. The Parser Stage" /></head><body id="docContent" class="container-fluid col-10"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="5" align="center">52.2. How Connections Are Established</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="query-path.html" title="52.1. The Path of a Query">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="overview.html" title="Chapter 52. Overview of PostgreSQL Internals">Up</a></td><th width="60%" align="center">Chapter 52. Overview of PostgreSQL Internals</th><td width="10%" align="right"><a accesskey="h" href="index.html" title="PostgreSQL 16.3 Documentation">Home</a></td><td width="10%" align="right"> <a accesskey="n" href="parser-stage.html" title="52.3. The Parser Stage">Next</a></td></tr></table><hr /></div><div class="sect1" id="CONNECT-ESTAB"><div class="titlepage"><div><div><h2 class="title" style="clear: both">52.2. How Connections Are Established <a href="#CONNECT-ESTAB" class="id_link">#</a></h2></div></div></div><p>3 <span class="productname">PostgreSQL</span> implements a4 <span class="quote">“<span class="quote">process per user</span>”</span> client/server model.5 In this model, every6 <a class="glossterm" href="glossary.html#GLOSSARY-CLIENT"><em class="glossterm"><a class="glossterm" href="glossary.html#GLOSSARY-CLIENT" title="Client (process)">client process</a></em></a>7 connects to exactly one8 <a class="glossterm" href="glossary.html#GLOSSARY-BACKEND"><em class="glossterm"><a class="glossterm" href="glossary.html#GLOSSARY-BACKEND" title="Backend (process)">backend process</a></em></a>.9 As we do not know ahead of time how many connections will be made,10 we have to use a <span class="quote">“<span class="quote">supervisor process</span>”</span> that spawns a new11 backend process every time a connection is requested. This supervisor12 process is called13 <a class="glossterm" href="glossary.html#GLOSSARY-POSTMASTER"><em class="glossterm"><a class="glossterm" href="glossary.html#GLOSSARY-POSTMASTER" title="Postmaster (process)">postmaster</a></em></a>14 and listens at a specified TCP/IP port for incoming connections.15 Whenever it detects a request for a connection, it spawns a new16 backend process. Those backend processes communicate with each17 other and with other processes of the18 <a class="glossterm" href="glossary.html#GLOSSARY-INSTANCE"><em class="glossterm"><a class="glossterm" href="glossary.html#GLOSSARY-INSTANCE" title="Instance">instance</a></em></a>19 using <em class="firstterm">semaphores</em> and20 <a class="glossterm" href="glossary.html#GLOSSARY-SHARED-MEMORY"><em class="glossterm"><a class="glossterm" href="glossary.html#GLOSSARY-SHARED-MEMORY" title="Shared memory">shared memory</a></em></a>21 to ensure data integrity throughout concurrent data access.22 </p><p>23 The client process can be any program that understands the24 <span class="productname">PostgreSQL</span> protocol described in25 <a class="xref" href="protocol.html" title="Chapter 55. Frontend/Backend Protocol">Chapter 55</a>. Many clients are based on the26 C-language library <span class="application">libpq</span>, but several independent27 implementations of the protocol exist, such as the Java28 <span class="application">JDBC</span> driver.29 </p><p>30 Once a connection is established, the client process can send a query31 to the backend process it's connected to. The query is transmitted using32 plain text, i.e., there is no parsing done in the client. The backend33 process parses the query, creates an <em class="firstterm">execution plan</em>,34 executes the plan, and returns the retrieved rows to the client35 by transmitting them over the established connection.36 </p></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="query-path.html" title="52.1. The Path of a Query">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="overview.html" title="Chapter 52. Overview of PostgreSQL Internals">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="parser-stage.html" title="52.3. The Parser Stage">Next</a></td></tr><tr><td width="40%" align="left" valign="top">52.1. The Path of a Query </td><td width="20%" align="center"><a accesskey="h" href="index.html" title="PostgreSQL 16.3 Documentation">Home</a></td><td width="40%" align="right" valign="top"> 52.3. The Parser Stage</td></tr></table></div></body></html>