@@ -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,25 @@ 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 stores
447
+ locks and does not expires.
448
+
430
449
.. _lock-store-redis :
431
450
432
451
RedisStore
@@ -526,6 +545,7 @@ Remote Stores
526
545
Remote stores (:ref: `MemcachedStore <lock-store-memcached >`,
527
546
:ref: `MongoDbStore <lock-store-mongodb >`,
528
547
:ref: `PdoStore <lock-store-pdo >`,
548
+ :ref: `PostgreSqlStore <lock-store-pgsql >`,
529
549
:ref: `RedisStore <lock-store-redis >` and
530
550
:ref: `ZookeeperStore <lock-store-zookeeper >`) use a unique token to recognize
531
551
the true owner of the lock. This token is stored in the
@@ -735,6 +755,20 @@ have synchronized clocks.
735
755
To ensure locks don't expire prematurely; the TTLs should be set with
736
756
enough extra time to account for any clock drift between nodes.
737
757
758
+ PostgreSqlStore
759
+ ~~~~~~~~~~~~~~~
760
+
761
+ The PdoStore relies on the `Advisory Locks `_ properties of the Postgresql
762
+ database. That means that by using :ref: `PostgreSqlStore <lock-store-pgsql >`
763
+ the locks will be automatically released at the end of the session in case the
764
+ client cannot unlock for any reason.
765
+
766
+ If the Postgresql service or the machine hosting it restarts, every lock would
767
+ be lost without notifying the running processes.
768
+
769
+ If the tcp connection is lost, the Postgresql may release locks without
770
+ notifying the application.
771
+
738
772
RedisStore
739
773
~~~~~~~~~~
740
774
@@ -839,6 +873,7 @@ are still running.
839
873
840
874
.. _`a maximum of 1024 bytes in length` : https://docs.mongodb.com/manual/reference/limits/#Index-Key-Limit
841
875
.. _`ACID` : https://en.wikipedia.org/wiki/ACID
876
+ .. _`Advisory Locks` : https://www.postgresql.org/docs/current/explicit-locking.html
842
877
.. _`Data Source Name (DSN)` : https://en.wikipedia.org/wiki/Data_source_name
843
878
.. _`Doctrine DBAL Connection` : https://github.com/doctrine/dbal/blob/master/src/Connection.php
844
879
.. _`Expire Data from Collections by Setting TTL` : https://docs.mongodb.com/manual/tutorial/expire-data/
0 commit comments