8000 minor #14364 [lock] Add documentation for Postgresql (jderusse) · symfony/symfony-docs@c3e26ca · GitHub
[go: up one dir, main page]

Skip to content

Commit c3e26ca

Browse files
committed
minor #14364 [lock] Add documentation for Postgresql (jderusse)
This PR was merged into the 5.x branch. Discussion ---------- [lock] Add documentation for Postgresql Fixes #14362 Commits ------- 496ea82 Add documentation for Postgresql
2 parents e8ff716 + 496ea82 commit c3e26ca

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

components/lock.rst

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,7 @@ Store Scope Blocking Expiring Sharing
319319
:ref:`MemcachedStore <lock-store-memcached>` remote no yes no
320320
:ref:`MongoDbStore <lock-store-mongodb>` remote no yes no
321321
:ref:`PdoStore <lock-store-pdo>` remote no yes no
322+
:ref:`PostgreSqlStore <lock-store-pgsql>` remote yes yes yes
322323
:ref:`RedisStore <lock-store-redis>` remote no yes yes
323324
:ref:`SemaphoreStore <lock-store-semaphore>` local yes no no
324325
:ref:`ZookeeperStore <lock-store-zookeeper>` remote no no no
@@ -452,6 +453,29 @@ You can also create this table explicitly by calling the
452453
:method:`Symfony\\Component\\Lock\\Store\\PdoStore::createTable` method in
453454
your code.
454455

456+
.. _lock-store-pgsql:
457+
458+
PostgreSqlStore
459+
~~~~~~~~~~~~~~~
460+
461+
The PostgreSqlStore uses `Advisory Locks`_ provided by PostgreSQL. It requires a
462+
`PDO`_ connection, a `Doctrine DBAL Connection`_, or a
463+
`Data Source Name (DSN)`_. it nativly supports blocking, as weel as sharing
464+
locks.
465+
466+
use Symfony\Component\Lock\Store\PostgreSqlStore;
467+
468+
// a PDO, a Doctrine DBAL connection or DSN for lazy connecting through PDO
469+
$databaseConnectionOrDSN = 'postgresql://myuser:mypassword@localhost:5634/lock';
470+
$store = new PostgreSqlStore($databaseConnectionOrDSN);
471+
472+
In opposite to the ``PdoStore``, the ``PostgreSqlStore`` does not need a table to
473+
stores locks and does not expires.
474+
475+
.. versionadded:: 5.2
476+
477+
PostgreSqlStore were introduced in Symfony 5.2.
478+
455479
.. _lock-store-redis:
456480

457481
RedisStore
@@ -551,6 +575,7 @@ Remote Stores
551575
Remote stores (:ref:`MemcachedStore <lock-store-memcached>`,
552576
:ref:`MongoDbStore <lock-store-mongodb>`,
553577
:ref:`PdoStore <lock-store-pdo>`,
578+
:ref:`PostgreSqlStore <lock-store-pgsql>`,
554579
:ref:`RedisStore <lock-store-redis>` and
555580
:ref:`ZookeeperStore <lock-store-zookeeper>`) use a unique token to recognize
556581
the true owner of the lock. This token is stored in the
@@ -760,6 +785,20 @@ have synchronized clocks.
760785
To ensure locks don't expire prematurely; the TTLs should be set with
761786
enough extra time to account for any clock drift between nodes.
762787

788+
PostgreSqlStore
789+
~~~~~~~~~~~~~~~
790+
791+
The PdoStore relies on the `Advisory Locks`_ properties of the PostgreSQL
792+
database. That means that by using :ref:`PostgreSqlStore <lock-store-pgsql>`
793+
the locks will be automatically released at the end of the session in case the
794+
client cannot unlock for any reason.
795+
796+
If the PostgreSQL service or the machine hosting it restarts, every lock would
797+
be lost without notifying the running processes.
798+
799+
If the TCP connection is lost, the PostgreSQL may release locks without
800+
notifying the application.
801+
763802
RedisStore
764803
~~~~~~~~~~
765804

@@ -864,6 +903,7 @@ are still running.
864903

865904
.. _`a maximum of 1024 bytes in length`: https://docs.mongodb.com/manual/reference/limits/#Index-Key-Limit
866905
.. _`ACID`: https://en.wikipedia.org/wiki/ACID
906+
.. _`Advisory Locks`: https://www.postgresql.org/docs/current/explicit-locking.html
867907
.. _`Data Source Name (DSN)`: https://en.wikipedia.org/wiki/Data_source_name
868908
.. _`Doctrine DBAL Connection`: https://github.com/doctrine/dbal/blob/master/src/Connection.php
869909
.. _`Expire Data from Collections by Setting TTL`: https://docs.mongodb.com/manual/tutorial/expire-data/

lock.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ this behavior by using the ``lock`` key like:
5858
lock: 'sqlite:///%kernel.project_dir%/var/lock.db'
5959
lock: 'mysql:host=127.0.0.1;dbname=app'
6060
lock: 'pgsql:host=127.0.0.1;dbname=app'
61+
lock: 'pgsql+advisory:host=127.0.0.1;dbname=lock'
6162
lock: 'sqlsrv:server=127.0.0.1;Database=app'
6263
lock: 'oci:host=127.0.0.1;dbname=app'
6364
lock: 'mongodb://127.0.0.1/app?collection=lock'
@@ -107,6 +108,8 @@ this behavior by using the ``lock`` key like:
107108
108109
<framework:resource>pgsql:host=127.0.0.1;dbname=app</framework:resource>
109110
111+
<framework:resource>pgsql+advisory:host=127.0.0.1;dbname=lock</framework:resource>
112+
110113
<framework:resource>sqlsrv:server=127.0.0.1;Database=app</framework:resource>
111114
112115
<framework:resource>oci:host=127.0.0.1;dbname=app</framework:resource>
@@ -140,6 +143,7 @@ this behavior by using the ``lock`` key like:
140143
'lock' => 'sqlite:///%kernel.project_dir%/var/lock.db',
141144
'lock' => 'mysql:host=127.0.0.1;dbname=app',
142145
'lock' => 'pgsql:host=127.0.0.1;dbname=app',
146+
'lock' => 'pgsql+advisory:host=127.0.0.1;dbname=lock',
143147
'lock' => 'sqlsrv:server=127.0.0.1;Database=app',
144148
'lock' => 'oci:host=127.0.0.1;dbname=app',
145149
'lock' => 'mongodb://127.0.0.1/app?collection=lock',

0 commit comments

Comments
 (0)
0