@@ -293,6 +293,7 @@ Store Scope Blocking Expiring Sharing
293
293
:ref: `MemcachedStore <lock-store-memcached >` remote no yes no
294
294
:ref: `MongoDbStore <lock-store-mongodb >` remote no yes no
295
295
:ref: `PdoStore <lock-store-pdo >` remote no yes no
296
+ :ref: `PostgreSqlStore <lock-store-pgsql >` remote yes yes yes
296
297
:ref: `RedisStore <lock-store-redis >` remote no yes yes
297
298
:ref: `SemaphoreStore <lock-store-semaphore >` local yes no no
298
299
:ref: `ZookeeperStore <lock-store-zookeeper >` remote no no no
@@ -340,8 +341,6 @@ support blocking, and expects a TTL to avoid stalled locks::
340
341
341
342
Memcached does not support TTL lower than 1 second.
342
343
343
- .. _lock-store-pdo :
344
-
345
344
.. _lock-store-mongodb :
346
345
347
346
MongoDbStore
@@ -403,6 +402,7 @@ MongoDB Connection String:
403
402
The ``collection `` querystring parameter is not part of the `MongoDB Connection String `_ definition.
404
403
It is used to allow constructing a ``MongoDbStore `` using a `Data Source Name (DSN) `_ without ``$options ``.
405
404
405
+ .. _lock-store-pdo :
406
406
407
407
PdoStore
408
408
~~~~~~~~
@@ -427,6 +427,29 @@ You can also create this table explicitly by calling the
427
427
:method: `Symfony\\ Component\\ Lock\\ Store\\ PdoStore::createTable ` method in
428
428
your code.
429
429
430
+ .. _lock-store-pgsql :
431
+
432
+ PostgreSqlStore
433
+ ~~~~~~~~~~~~~~~
434
+
435
+ The PostgreSqlStore uses `Advisory Locks `_ provided by PostgreSQL. It requires a
436
+ `PDO `_ connection, a `Doctrine DBAL Connection `_, or a
437
+ `Data Source Name (DSN) `_. it nativly supports blocking, as weel as sharing
438
+ locks.
439
+
440
+ use Symfony\C omponent\L ock\S tore\P ostgreSqlStore;
441
+
442
+ // a PDO, a Doctrine DBAL connection or DSN for lazy connecting through PDO
443
+ $databaseConnectionOrDSN = 'postgresql://myuser:mypassword@localhost:5634/lock';
444
+ $store = new PostgreSqlStore($databaseConnectionOrDSN);
445
+
446
+ In opposite to the ``PdoStore ``, the ``PostgreSqlStore `` does not need a table to
447
+ stores locks and does not expires.
448
+
449
+ .. versionadded :: 5.2
450
+
451
+ PostgreSqlStore were introduced in Symfony 5.2.
452
+
430
453
.. _lock-store-redis :
431
454
432
455
RedisStore
@@ -526,6 +549,7 @@ Remote Stores
526
549
Remote stores (:ref: `MemcachedStore <lock-store-memcached >`,
527
550
:ref: `MongoDbStore <lock-store-mongodb >`,
528
551
:ref: `PdoStore <lock-store-pdo >`,
552
+ :ref: `PostgreSqlStore <lock-store-pgsql >`,
529
553
:ref: `RedisStore <lock-store-redis >` and
530
554
:ref: `ZookeeperStore <lock-store-zookeeper >`) use a unique token to recognize
531
555
the true owner of the lock. This token is stored in the
@@ -735,6 +759,20 @@ have synchronized clocks.
735
759
To ensure locks don't expire prematurely; the TTLs should be set with
736
760
enough extra time to account for any clock drift between nodes.
737
761
762
+ PostgreSqlStore
763
+ ~~~~~~~~~~~~~~~
764
+
765
+ The PdoStore relies on the `Advisory Locks `_ properties of the PostgreSQL
766
+ database. That means that by using :ref: `PostgreSqlStore <lock-store-pgsql >`
767
+ the locks will be automatically released at the end of the session in case the
768
+ client cannot unlock for any reason.
769
+
770
+ If the PostgreSQL service or the machine hosting it restarts, every lock would
771
+ be lost without notifying the running processes.
772
+
773
+ If the TCP connection is lost, the PostgreSQL may release locks without
774
+ notifying the application.
775
+
738
776
RedisStore
739
777
~~~~~~~~~~
740
778
@@ -839,6 +877,7 @@ are still running.
839
877
840
878
.. _`a maximum of 1024 bytes in length` : https://docs.mongodb.com/manual/reference/limits/#Index-Key-Limit
841
879
.. _`ACID` : https://en.wikipedia.org/wiki/ACID
880
+ .. _`Advisory Locks` : https://www.postgresql.org/docs/current/explicit-locking.html
842
881
.. _`Data Source Name (DSN)` : https://en.wikipedia.org/wiki/Data_source_name
843
882
.. _`Doctrine DBAL Connection` : https://github.com/doctrine/dbal/blob/master/src/Connection.php
844
883
.. _`Expire Data from Collections by Setting TTL` : https://docs.mongodb.com/manual/tutorial/expire-data/
0 commit comments