@@ -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
453454your 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\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+
455479.. _lock-store-redis :
456480
457481RedisStore
@@ -551,6 +575,7 @@ Remote Stores
551575Remote 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
556581the 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+
763802RedisStore
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/
0 commit comments