pgmemcache

pgmemcache

pgmemcache : memcached interface

Overview

IDExtensionPackageVersionCategoryLicenseLanguage
9410
pgmemcache
pgmemcache
2.3.0
SIM
MIT
C
AttributeHas BinaryHas LibraryNeed LoadHas DDLRelocatableTrusted
--s-d-r
No
Yes
No
Yes
yes
no
Relationships
See Also
redis_fdw
redis
spat
mongo_fdw
kafka_fdw
documentdb
documentdb_core
documentdb_distributed

missing pg12-14 on el.aarch64

Packages

TypeRepoVersionPG Major CompatibilityPackage PatternDependencies
EXT
PGDG
2.3.0
18
17
16
15
14
pgmemcache-
RPM
PGDG
2.3.0
18
17
16
15
14
pgmemcache_$v-
DEB
PGDG
2.3.0
18
17
16
15
14
postgresql-$v-pgmemcache-
Linux / PGPG18PG17PG16PG15PG14
el8.x86_64
PGDG 2.3.0
PGDG 2.3.0
PGDG 2.3.0
PGDG 2.3.0
PGDG 2.3.0
el8.aarch64
PGDG 2.3.0
PGDG 2.3.0
PGDG 2.3.0
MISS
MISS
el9.x86_64
PGDG 2.3.0
PGDG 2.3.0
PGDG 2.3.0
PGDG 2.3.0
MISS
el9.aarch64
PGDG 2.3.0
PGDG 2.3.0
PGDG 2.3.0
MISS
MISS
el10.x86_64
PGDG 2.3.0
PGDG 2.3.0
PGDG 2.3.0
PGDG 2.3.0
PGDG 2.3.0
el10.aarch64
PGDG 2.3.0
PGDG 2.3.0
PGDG 2.3.0
PGDG 2.3.0
PGDG 2.3.0
d12.x86_64
PGDG 2.3.0
PGDG 2.3.0
PGDG 2.3.0
PGDG 2.3.0
PGDG 2.3.0
d12.aarch64
PGDG 2.3.0
PGDG 2.3.0
PGDG 2.3.0
PGDG 2.3.0
PGDG 2.3.0
d13.x86_64
PGDG 2.3.0
PGDG 2.3.0
PGDG 2.3.0
PGDG 2.3.0
PGDG 2.3.0
d13.aarch64
PGDG 2.3.0
PGDG 2.3.0
PGDG 2.3.0
PGDG 2.3.0
PGDG 2.3.0
u22.x86_64
PGDG 2.3.0
PGDG 2.3.0
PGDG 2.3.0
PGDG 2.3.0
PGDG 2.3.0
u22.aarch64
PGDG 2.3.0
PGDG 2.3.0
PGDG 2.3.0
PGDG 2.3.0
PGDG 2.3.0
u24.x86_64
PGDG 2.3.0
PGDG 2.3.0
PGDG 2.3.0
PGDG 2.3.0
PGDG 2.3.0
u24.aarch64
PGDG 2.3.0
PGDG 2.3.0
PGDG 2.3.0
PGDG 2.3.0
PGDG 2.3.0
PackageVersionOSORGSIZEFile URL
pgmemcache_152.3.0el8.x86_64pgdg56.1 KiBpgmemcache_15-2.3.0-5.rhel8.x86_64.rpm
pgmemcache_152.3.0el9.x86_64pgdg57.3 KiBpgmemcache_15-2.3.0-5.rhel9.x86_64.rpm
pgmemcache_152.3.0el10.x86_64pgdg26.4 KiBpgmemcache_15-2.3.0-9PGDG.rhel10.x86_64.rpm
pgmemcache_152.3.0el10.aarch64pgdg26.2 KiBpgmemcache_15-2.3.0-9PGDG.rhel10.aarch64.rpm
postgresql-15-pgmemcache2.3.0d12.x86_64pgdg45.3 KiBpostgresql-15-pgmemcache_2.3.0-15.pgdg12+1_amd64.deb
postgresql-15-pgmemcache2.3.0d12.aarch64pgdg45.1 KiBpostgresql-15-pgmemcache_2.3.0-15.pgdg12+1_arm64.deb
postgresql-15-pgmemcache2.3.0d13.x86_64pgdg45.7 KiBpostgresql-15-pgmemcache_2.3.0-15.pgdg13+1_amd64.deb
postgresql-15-pgmemcache2.3.0d13.aarch64pgdg45.2 KiBpostgresql-15-pgmemcache_2.3.0-15.pgdg13+1_arm64.deb
postgresql-15-pgmemcache2.3.0u22.x86_64pgdg51.8 KiBpostgresql-15-pgmemcache_2.3.0-15.pgdg22.04+1_amd64.deb
postgresql-15-pgmemcache2.3.0u22.aarch64pgdg51.6 KiBpostgresql-15-pgmemcache_2.3.0-15.pgdg22.04+1_arm64.deb
postgresql-15-pgmemcache2.3.0u24.x86_64pgdg45.7 KiBpostgresql-15-pgmemcache_2.3.0-15.pgdg24.04+1_amd64.deb
postgresql-15-pgmemcache2.3.0u24.aarch64pgdg45.1 KiBpostgresql-15-pgmemcache_2.3.0-15.pgdg24.04+1_arm64.deb
PackageVersionOSORGSIZEFile URL
pgmemcache_142.3.0el8.x86_64pgdg56.6 KiBpgmemcache_14-2.3.0-5.rhel8.x86_64.rpm
pgmemcache_142.3.0el10.x86_64pgdg26.4 KiBpgmemcache_14-2.3.0-9PGDG.rhel10.x86_64.rpm
pgmemcache_142.3.0el10.aarch64pgdg26.2 KiBpgmemcache_14-2.3.0-9PGDG.rhel10.aarch64.rpm
postgresql-14-pgmemcache2.3.0d12.x86_64pgdg45.3 KiBpostgresql-14-pgmemcache_2.3.0-15.pgdg12+1_amd64.deb
postgresql-14-pgmemcache2.3.0d12.aarch64pgdg45.1 KiBpostgresql-14-pgmemcache_2.3.0-15.pgdg12+1_arm64.deb
postgresql-14-pgmemcache2.3.0d13.x86_64pgdg45.6 KiBpostgresql-14-pgmemcache_2.3.0-15.pgdg13+1_amd64.deb
postgresql-14-pgmemcache2.3.0d13.aarch64pgdg45.1 KiBpostgresql-14-pgmemcache_2.3.0-15.pgdg13+1_arm64.deb
postgresql-14-pgmemcache2.3.0u22.x86_64pgdg51.7 KiBpostgresql-14-pgmemcache_2.3.0-15.pgdg22.04+1_amd64.deb
postgresql-14-pgmemcache2.3.0u22.aarch64pgdg51.5 KiBpostgresql-14-pgmemcache_2.3.0-15.pgdg22.04+1_arm64.deb
postgresql-14-pgmemcache2.3.0u24.x86_64pgdg45.7 KiBpostgresql-14-pgmemcache_2.3.0-15.pgdg24.04+1_amd64.deb
postgresql-14-pgmemcache2.3.0u24.aarch64pgdg45.2 KiBpostgresql-14-pgmemcache_2.3.0-15.pgdg24.04+1_arm64.deb

Source

Install

Make sure PGDG repo available:

pig repo add pgdg -u    # add pgdg repo and update cache

Install this extension with pig:

pig install pgmemcache;		# install via package name, for the active PG version

pig install pgmemcache -v 18;   # install for PG 18
pig install pgmemcache -v 17;   # install for PG 17
pig install pgmemcache -v 16;   # install for PG 16
pig install pgmemcache -v 15;   # install for PG 15
pig install pgmemcache -v 14;   # install for PG 14

Create this extension with:

CREATE EXTENSION pgmemcache;

Usage

pgmemcache: memcached interface

Provides PostgreSQL user-defined functions for interacting with memcached servers.

Enabling

CREATE EXTENSION pgmemcache;

Configure default servers in postgresql.conf:

shared_preload_libraries = 'pgmemcache'
pgmemcache.default_servers = 'localhost:11211'
pgmemcache.default_behavior = 'DEAD_TIMEOUT:2'

Server Management

SELECT memcache_server_add('localhost:11211');
SELECT memcache_server_add('cache-host');  -- uses default port 11211

Setting and Getting Values

-- Set a key (overwrites if exists)
SELECT memcache_set('user:1:name', 'John Doe');
SELECT memcache_set('session:abc', 'data', now() + interval '1 hour');

-- Add a key (fails if exists)
SELECT memcache_add('user:2:name', 'Jane Doe');
SELECT memcache_add('temp_key', 'value', interval '5 minutes');

-- Replace (fails if key doesn't exist)
SELECT memcache_replace('user:1:name', 'John Smith');

-- Get a value
SELECT memcache_get('user:1:name');  -- returns text or NULL

-- Get multiple values
SELECT key, value FROM memcache_get_multi('{key1,key2,key3}'::text[]);

Atomic Counters

SELECT memcache_incr('counter');        -- increment by 1
SELECT memcache_incr('counter', 5);     -- increment by 5
SELECT memcache_decr('counter');        -- decrement by 1
SELECT memcache_decr('counter', 3);     -- decrement by 3

Deleting and Flushing

SELECT memcache_delete('user:1:name');
SELECT memcache_flush_all();  -- flush all servers

Statistics

SELECT memcache_stats();  -- returns stats from all servers

Trigger Example

Invalidate cache on table updates:

CREATE OR REPLACE FUNCTION auth_passwd_upd()
RETURNS TRIGGER LANGUAGE plpgsql AS $$
BEGIN
    IF OLD.passwd <> NEW.passwd THEN
        PERFORM memcache_delete('user_id_' || NEW.user_id || '_password');
    END IF;
    RETURN NEW;
END;
$$;

CREATE TRIGGER auth_passwd_upd_trg AFTER UPDATE ON passwd
    FOR EACH ROW EXECUTE PROCEDURE auth_passwd_upd();
Last updated on