@@ -319,6 +319,7 @@ Store Scope Blocking Expiring Sharing
319
319
:ref: `MemcachedStore <lock-store-memcached >` remote no yes no
320
320
:ref: `MongoDbStore <lock-store-mongodb >` remote no yes no
321
321
:ref: `PdoStore <lock-store-pdo >` remote no yes no
322
+ :ref: `PostgreSqlStore <lock-store-pgsql >` remote yes yes yes
322
323
:ref: `RedisStore <lock-store-redis >` remote no yes yes
323
324
:ref: `SemaphoreStore <lock-store-semaphore >` local yes no no
324
325
:ref: `ZookeeperStore <lock-store-zookeeper >` remote no no no
@@ -452,6 +453,29 @@ You can also create this table explicitly by calling the
452
453
:method: `Symfony\\ Component\\ Lock\\ Store\\ PdoStore::createTable ` method in
453
454
your code.
454
455
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\C omponent\L ock\S tore\P ostgreSqlStore;
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
+
455
479
.. _lock-store-redis :
456
480
457
481
RedisStore
@@ -551,6 +575,7 @@ Remote Stores
551
575
Remote stores (:ref: `MemcachedStore <lock-store-memcached >`,
552
576
:ref: `MongoDbStore <lock-store-mongodb >`,
553
577
:ref: `PdoStore <lock-store-pdo >`,
578
+ :ref: `PostgreSqlStore <lock-store-pgsql >`,
554
579
:ref: `RedisStore <lock-store-redis >` and
555
580
:ref: `ZookeeperStore <lock-store-zookeeper >`) use a unique token to recognize
556
581
the true owner of the lock. This token is stored in the
@@ -760,6 +785,20 @@ have synchronized clocks.
760
785
To ensure locks don't expire prematurely; the TTLs should be set with
761
786
enough extra time to account for any clock drift between nodes.
762
787
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
+
763
802
RedisStore
764
803
~~~~~~~~~~
765
804
@@ -864,6 +903,7 @@ are still running.
864
903
865
904
.. _`a maximum of 1024 bytes in length` : https://docs.mongodb.com/manual/reference/limits/#Index-Key-Limit
866
905
.. _`ACID` : https://en.wikipedia.org/wiki/ACID
906
+ .. _`Advisory Locks` : https://www.postgresql.org/docs/current/explicit-locking.html
867
907
.. _`Data Source Name (DSN)` : https://en.wikipedia.org/wiki/Data_source_name
868
908
.. _`Doctrine DBAL Connection` : https://github.com/doctrine/dbal/blob/master/src/Connection.php
869
909
.. _`Expire Data from Collections by Setting TTL` : https://docs.mongodb.com/manual/tutorial/expire-data/
0 commit comments