notes

Log | Files | Refs | README

postgresql_connection.md (1171B)


      1 # PostgreSQL Connection
      2 
      3 A PostgreSQL connection is the link between a client (like an app, script, or
      4 psql) and a PostgreSQL database server that lets them send queries and receive
      5 results.
      6 
      7 ## Memory and Processes
      8 
      9 A PostgreSQL connection uses memory because each client gets its own backend
     10 process with its own state (caches, buffers, variables, temp data, etc.), and
     11 that state must live somewhere in RAM. This is also why too many connections can
     12 exhaust memory and hurt performance.
     13 
     14 PostgreSQL is a process‑per‑connection model (on typical
     15 [Unix-like systems](/operating_systems/README.md) a new OS process is forked for
     16 each client connection).
     17 
     18 Each backend process has its own private address space for session-local state,
     19 which avoids accidental shared mutable state between connections.
     20 
     21 Backends share only explicit shared-memory regions and files (e.g., shared
     22 buffer cache, WAL, locks), with well-defined synchronization, so there's no
     23 "mysterious" shared state like in a multi-threaded process with global
     24 variables.
     25 
     26 So, you do get isolation of most state per connection, with only controlled,
     27 intentional shared memory for common data structures.