pgmemcache

pgmemcache

pgmemcache : memcached interface

Overview

ID Extension Package Version Category License Language
9410
pgmemcache
pgmemcache
2.3.0
SIM
MIT
C
Attribute Has Binary Has Library Need Load Has DDL Relocatable Trusted
--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

Type Repo Version PG Major Compatibility Package Pattern Dependencies
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 / PG PG18 PG17 PG16 PG15 PG14
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
Package Version OS ORG SIZE File URL
pgmemcache_18 2.3.0 el8.x86_64 pgdg 26.5 KiB pgmemcache_18-2.3.0-9PGDG.rhel8.x86_64.rpm
pgmemcache_18 2.3.0 el8.aarch64 pgdg 26.0 KiB pgmemcache_18-2.3.0-9PGDG.rhel8.aarch64.rpm
pgmemcache_18 2.3.0 el9.x86_64 pgdg 25.9 KiB pgmemcache_18-2.3.0-9PGDG.rhel9.x86_64.rpm
pgmemcache_18 2.3.0 el9.aarch64 pgdg 25.4 KiB pgmemcache_18-2.3.0-9PGDG.rhel9.aarch64.rpm
pgmemcache_18 2.3.0 el10.x86_64 pgdg 26.3 KiB pgmemcache_18-2.3.0-9PGDG.rhel10.x86_64.rpm
pgmemcache_18 2.3.0 el10.aarch64 pgdg 26.2 KiB pgmemcache_18-2.3.0-9PGDG.rhel10.aarch64.rpm
postgresql-18-pgmemcache 2.3.0 d12.x86_64 pgdg 45.4 KiB postgresql-18-pgmemcache_2.3.0-15.pgdg12+1_amd64.deb
postgresql-18-pgmemcache 2.3.0 d12.aarch64 pgdg 45.0 KiB postgresql-18-pgmemcache_2.3.0-15.pgdg12+1_arm64.deb
postgresql-18-pgmemcache 2.3.0 d13.x86_64 pgdg 45.6 KiB postgresql-18-pgmemcache_2.3.0-15.pgdg13+1_amd64.deb
postgresql-18-pgmemcache 2.3.0 d13.aarch64 pgdg 45.0 KiB postgresql-18-pgmemcache_2.3.0-15.pgdg13+1_arm64.deb
postgresql-18-pgmemcache 2.3.0 u22.x86_64 pgdg 46.5 KiB postgresql-18-pgmemcache_2.3.0-15.pgdg22.04+1_amd64.deb
postgresql-18-pgmemcache 2.3.0 u22.aarch64 pgdg 46.3 KiB postgresql-18-pgmemcache_2.3.0-15.pgdg22.04+1_arm64.deb
postgresql-18-pgmemcache 2.3.0 u24.x86_64 pgdg 45.7 KiB postgresql-18-pgmemcache_2.3.0-15.pgdg24.04+1_amd64.deb
postgresql-18-pgmemcache 2.3.0 u24.aarch64 pgdg 45.1 KiB postgresql-18-pgmemcache_2.3.0-15.pgdg24.04+1_arm64.deb
Package Version OS ORG SIZE File URL
pgmemcache_17 2.3.0 el8.x86_64 pgdg 26.4 KiB pgmemcache_17-2.3.0-8PGDG.rhel8.x86_64.rpm
pgmemcache_17 2.3.0 el8.aarch64 pgdg 25.9 KiB pgmemcache_17-2.3.0-8PGDG.rhel8.aarch64.rpm
pgmemcache_17 2.3.0 el9.x86_64 pgdg 26.0 KiB pgmemcache_17-2.3.0-8PGDG.rhel9.x86_64.rpm
pgmemcache_17 2.3.0 el9.aarch64 pgdg 25.6 KiB pgmemcache_17-2.3.0-8PGDG.rhel9.aarch64.rpm
pgmemcache_17 2.3.0 el10.x86_64 pgdg 26.3 KiB pgmemcache_17-2.3.0-9PGDG.rhel10.x86_64.rpm
pgmemcache_17 2.3.0 el10.aarch64 pgdg 26.2 KiB pgmemcache_17-2.3.0-9PGDG.rhel10.aarch64.rpm
postgresql-17-pgmemcache 2.3.0 d12.x86_64 pgdg 45.3 KiB postgresql-17-pgmemcache_2.3.0-15.pgdg12+1_amd64.deb
postgresql-17-pgmemcache 2.3.0 d12.aarch64 pgdg 45.0 KiB postgresql-17-pgmemcache_2.3.0-15.pgdg12+1_arm64.deb
postgresql-17-pgmemcache 2.3.0 d13.x86_64 pgdg 45.7 KiB postgresql-17-pgmemcache_2.3.0-15.pgdg13+1_amd64.deb
postgresql-17-pgmemcache 2.3.0 d13.aarch64 pgdg 45.1 KiB postgresql-17-pgmemcache_2.3.0-15.pgdg13+1_arm64.deb
postgresql-17-pgmemcache 2.3.0 u22.x86_64 pgdg 52.3 KiB postgresql-17-pgmemcache_2.3.0-15.pgdg22.04+1_amd64.deb
postgresql-17-pgmemcache 2.3.0 u22.aarch64 pgdg 51.9 KiB postgresql-17-pgmemcache_2.3.0-15.pgdg22.04+1_arm64.deb
postgresql-17-pgmemcache 2.3.0 u24.x86_64 pgdg 45.7 KiB postgresql-17-pgmemcache_2.3.0-15.pgdg24.04+1_amd64.deb
postgresql-17-pgmemcache 2.3.0 u24.aarch64 pgdg 45.2 KiB postgresql-17-pgmemcache_2.3.0-15.pgdg24.04+1_arm64.deb
Package Version OS ORG SIZE File URL
pgmemcache_16 2.3.0 el8.x86_64 pgdg 26.2 KiB pgmemcache_16-2.3.0-6.rhel8.1.x86_64.rpm
pgmemcache_16 2.3.0 el8.aarch64 pgdg 25.7 KiB pgmemcache_16-2.3.0-6.rhel8.1.aarch64.rpm
pgmemcache_16 2.3.0 el9.x86_64 pgdg 25.7 KiB pgmemcache_16-2.3.0-6.rhel9.1.x86_64.rpm
pgmemcache_16 2.3.0 el9.aarch64 pgdg 25.1 KiB pgmemcache_16-2.3.0-6.rhel9.1.aarch64.rpm
pgmemcache_16 2.3.0 el10.x86_64 pgdg 26.4 KiB pgmemcache_16-2.3.0-9PGDG.rhel10.x86_64.rpm
pgmemcache_16 2.3.0 el10.aarch64 pgdg 26.2 KiB pgmemcache_16-2.3.0-9PGDG.rhel10.aarch64.rpm
postgresql-16-pgmemcache 2.3.0 d12.x86_64 pgdg 45.4 KiB postgresql-16-pgmemcache_2.3.0-15.pgdg12+1_amd64.deb
postgresql-16-pgmemcache 2.3.0 d12.aarch64 pgdg 44.9 KiB postgresql-16-pgmemcache_2.3.0-15.pgdg12+1_arm64.deb
postgresql-16-pgmemcache 2.3.0 d13.x86_64 pgdg 45.6 KiB postgresql-16-pgmemcache_2.3.0-15.pgdg13+1_amd64.deb
postgresql-16-pgmemcache 2.3.0 d13.aarch64 pgdg 45.1 KiB postgresql-16-pgmemcache_2.3.0-15.pgdg13+1_arm64.deb
postgresql-16-pgmemcache 2.3.0 u22.x86_64 pgdg 51.7 KiB postgresql-16-pgmemcache_2.3.0-15.pgdg22.04+1_amd64.deb
postgresql-16-pgmemcache 2.3.0 u22.aarch64 pgdg 51.6 KiB postgresql-16-pgmemcache_2.3.0-15.pgdg22.04+1_arm64.deb
postgresql-16-pgmemcache 2.3.0 u24.x86_64 pgdg 45.7 KiB postgresql-16-pgmemcache_2.3.0-15.pgdg24.04+1_amd64.deb
postgresql-16-pgmemcache 2.3.0 u24.aarch64 pgdg 45.1 KiB postgresql-16-pgmemcache_2.3.0-15.pgdg24.04+1_arm64.deb
Package Version OS ORG SIZE File URL
pgmemcache_15 2.3.0 el8.x86_64 pgdg 56.1 KiB pgmemcache_15-2.3.0-5.rhel8.x86_64.rpm
pgmemcache_15 2.3.0 el9.x86_64 pgdg 57.3 KiB pgmemcache_15-2.3.0-5.rhel9.x86_64.rpm
pgmemcache_15 2.3.0 el10.x86_64 pgdg 26.4 KiB pgmemcache_15-2.3.0-9PGDG.rhel10.x86_64.rpm
pgmemcache_15 2.3.0 el10.aarch64 pgdg 26.2 KiB pgmemcache_15-2.3.0-9PGDG.rhel10.aarch64.rpm
postgresql-15-pgmemcache 2.3.0 d12.x86_64 pgdg 45.3 KiB postgresql-15-pgmemcache_2.3.0-15.pgdg12+1_amd64.deb
postgresql-15-pgmemcache 2.3.0 d12.aarch64 pgdg 45.1 KiB postgresql-15-pgmemcache_2.3.0-15.pgdg12+1_arm64.deb
postgresql-15-pgmemcache 2.3.0 d13.x86_64 pgdg 45.7 KiB postgresql-15-pgmemcache_2.3.0-15.pgdg13+1_amd64.deb
postgresql-15-pgmemcache 2.3.0 d13.aarch64 pgdg 45.2 KiB postgresql-15-pgmemcache_2.3.0-15.pgdg13+1_arm64.deb
postgresql-15-pgmemcache 2.3.0 u22.x86_64 pgdg 51.8 KiB postgresql-15-pgmemcache_2.3.0-15.pgdg22.04+1_amd64.deb
postgresql-15-pgmemcache 2.3.0 u22.aarch64 pgdg 51.6 KiB postgresql-15-pgmemcache_2.3.0-15.pgdg22.04+1_arm64.deb
postgresql-15-pgmemcache 2.3.0 u24.x86_64 pgdg 45.7 KiB postgresql-15-pgmemcache_2.3.0-15.pgdg24.04+1_amd64.deb
postgresql-15-pgmemcache 2.3.0 u24.aarch64 pgdg 45.1 KiB postgresql-15-pgmemcache_2.3.0-15.pgdg24.04+1_arm64.deb
Package Version OS ORG SIZE File URL
pgmemcache_14 2.3.0 el8.x86_64 pgdg 56.6 KiB pgmemcache_14-2.3.0-5.rhel8.x86_64.rpm
pgmemcache_14 2.3.0 el10.x86_64 pgdg 26.4 KiB pgmemcache_14-2.3.0-9PGDG.rhel10.x86_64.rpm
pgmemcache_14 2.3.0 el10.aarch64 pgdg 26.2 KiB pgmemcache_14-2.3.0-9PGDG.rhel10.aarch64.rpm
postgresql-14-pgmemcache 2.3.0 d12.x86_64 pgdg 45.3 KiB postgresql-14-pgmemcache_2.3.0-15.pgdg12+1_amd64.deb
postgresql-14-pgmemcache 2.3.0 d12.aarch64 pgdg 45.1 KiB postgresql-14-pgmemcache_2.3.0-15.pgdg12+1_arm64.deb
postgresql-14-pgmemcache 2.3.0 d13.x86_64 pgdg 45.6 KiB postgresql-14-pgmemcache_2.3.0-15.pgdg13+1_amd64.deb
postgresql-14-pgmemcache 2.3.0 d13.aarch64 pgdg 45.1 KiB postgresql-14-pgmemcache_2.3.0-15.pgdg13+1_arm64.deb
postgresql-14-pgmemcache 2.3.0 u22.x86_64 pgdg 51.7 KiB postgresql-14-pgmemcache_2.3.0-15.pgdg22.04+1_amd64.deb
postgresql-14-pgmemcache 2.3.0 u22.aarch64 pgdg 51.5 KiB postgresql-14-pgmemcache_2.3.0-15.pgdg22.04+1_arm64.deb
postgresql-14-pgmemcache 2.3.0 u24.x86_64 pgdg 45.7 KiB postgresql-14-pgmemcache_2.3.0-15.pgdg24.04+1_amd64.deb
postgresql-14-pgmemcache 2.3.0 u24.aarch64 pgdg 45.2 KiB postgresql-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