Giter VIP home page Giter VIP logo

pgec's Introduction


Test Coverage Test Results edoc Erlang/OTP 25+ Apache-2.0

PostgreSQL Edge Cache (PGEC)

pgec replicates data from PostgreSQL accessed with a Redis, Memcached and REST API with persistent storage.

Features

High Level Architecture

The replication process creates a transaction checkpoint ensuring data integrity. Once the initial data has been collected, streaming replication starts, receiving changes that have been applied subsequent to the checkpoint, ensuring no loss of data. Streaming replication continues keeping pgec up to date in real-time.

main

Quick Start

demo

Clone this repository for the docker compose.yaml with sample PostgreSQL data installed.

git clone https://github.com/shortishly/pgec.git

Alternatively, with the Github CLI installed use:

gh repo clone shortishly/pgec

Change to the newly cloned directory:

cd pgec

Start up everything with:

docker compose up --detach --remove-orphans

Sample data is populated from the scripts in this directory, using this publication. The compose includes a small load generator using table randload. Grafana dashboards: http://localhost:3000/, more details of monitoring are here

The grades table is populated with data from:

"Last name","First name","SSN","Test1","Test2","Test3","Test4","Final","Grade"
"Alfalfa","Aloysius","123-45-6789",40.0,90.0,100.0,83.0,49.0,"D-"
"Alfred","University","123-12-1234",41.0,97.0,96.0,97.0,48.0,"D+"
"Gerty","Gramma","567-89-0123",41.0,80.0,60.0,40.0,44.0,"C"
"Android","Electric","087-65-4321",42.0,23.0,36.0,45.0,47.0,"B-"
"Bumpkin","Fred","456-78-9012",43.0,78.0,88.0,77.0,45.0,"A-"
"Rubble","Betty","234-56-7890",44.0,90.0,80.0,90.0,46.0,"C-"
"Noshow","Cecil","345-67-8901",45.0,11.0,-1.0,4.0,43.0,"F"
"Buff","Bif","632-79-9939",46.0,20.0,30.0,40.0,50.0,"B+"
"Airpump","Andrew","223-45-6789",49.0,1.0,90.0,100.0,83.0,"A"
"Backus","Jim","143-12-1234",48.0,1.0,97.0,96.0,97.0,"A+"
"Carnivore","Art","565-89-0123",44.0,1.0,80.0,60.0,40.0,"D+"
"Dandy","Jim","087-75-4321",47.0,1.0,23.0,36.0,45.0,"C+"
"Elephant","Ima","456-71-9012",45.0,1.0,78.0,88.0,77.0,"B-"
"Franklin","Benny","234-56-2890",50.0,1.0,90.0,80.0,90.0,"B-"
"George","Boy","345-67-3901",40.0,1.0,11.0,-1.0,4.0,"B"
"Heffalump","Harvey","632-79-9439",30.0,1.0,20.0,30.0,40.0,"C"

Betty Rubble's grades are http://localhost:8080/pub/grades/234-56-7890:

curl -s http://localhost:8080/pub/grades/234-56-7890 | jq
{
  "final": 46,
  "first": "Betty",
  "grade": "C-",
  "last": "Rubble",
  "ssn": "234-56-7890",
  "test1": 44,
  "test2": 90,
  "test3": 80,
  "test4": 90
}

A 'C-' seems harsh, lets give her a 'C' instead:

docker compose exec \
    --no-TTY \
    postgres \
    psql \
    --command="update grades set grade='C' where ssn='234-56-7890'"

Fetching the same row, with the redis API instead:

redis-cli HGETALL pub.grades.234-56-7890
 1) "test4"
 2) "90"
 3) "test3"
 4) "80"
 5) "test2"
 6) "90"
 7) "test1"
 8) "44"
 9) "ssn"
10) "234-56-7890"
11) "last"
12) "Rubble"
13) "grade"
14) "C"
15) "first"
16) "Betty"
17) "final"
18) "46"

Fetching the same row, but with the memcached API instead:

telnet localhost 11211
Trying ::1...
Connected to localhost.
Escape character is '^]'.
get pub.grades.234-56-7890
VALUE pub.grades.234-56-7890 0 120
{"final":46,"first":"Betty","grade":"C","last":"Rubble","ssn":"234-56-7890","test1":44,"test2":90,"test3":80,"test4":90}
END

Primary keys via REST API:

curl -s http://localhost:8080/pub/deniro/Casino | jq
{
  "score": 80,
  "title": "Casino",
  "year": 1995
}

The same via the Redis API:

redis-cli HGETALL pub.deniro.Casino

1) "year"
2) "1995"
3) "title"
4) "Casino"
5) "score"
6) "80"

Composite keys:

curl -s http://localhost:8080/pub/cities/Tulsa/OK | jq
{
  "city": "Tulsa",
  "ew": "W",
  "lat_d": 36,
  "lat_m": 9,
  "lat_s": 35,
  "lon_d": 95,
  "lon_m": 54,
  "lon_s": 36,
  "ns": "N",
  "state": "OK"
}

pgec's People

Contributors

shortishly avatar dependabot[bot] avatar

Stargazers

 avatar  avatar Daniel Kreuer avatar  avatar Yiorgos Michokostas avatar Alvaro R Martin avatar Javier Silva Ortiz avatar Michael Usachenko avatar Alejandro Baez avatar Minh Nguyen avatar Maxim Fominykh avatar Nicolás Illia avatar Pedro Raimundo avatar  avatar noctarius aka Christoph Engelbert avatar Michael Rayva avatar BunmJyo avatar Teodor avatar Emanuel Calvo avatar  avatar Niamtokik  avatar Jacob Reynolds avatar Stephen Corya avatar Entrapta Jones avatar Bart Stefanski avatar Simon Escobar Benitez avatar Adam Lindberg avatar Jeremiah Campbell avatar Jay avatar  avatar Benjamin Krenn avatar  avatar Sam Mingo avatar Roman Chukh avatar ranjanprj avatar Oleg Pykhalov avatar Jonah H. Harris avatar Eduards Gruberts avatar Lin_n avatar Bhautik avatar Julio Merisio avatar Paweł Henek avatar Robert Scott avatar Daniel Kröger avatar Jov avatar Neal Feierabend avatar Edijs Drezovs avatar Jacek Artymiak avatar tsingson avatar Padraic Renaghan avatar Karthik avatar Mahatma_Fatal_Error avatar a avatar  avatar Anton Bessonov avatar Bruno Lavoie avatar  avatar Vassilios Karakoidas avatar nemo avatar Gurpartap Singh avatar Tyrone Meijn avatar firas omrane avatar Eric Hayes avatar Matt Gowie avatar Oliver Rice avatar Joe Kong avatar Gowthaman Basuvaraj avatar Gonçalo Mendes Cabrita avatar KindlyFire avatar Edward Beech avatar Matthew Perry avatar  avatar George Erickson avatar  avatar Ted Behling avatar Evgeny Postnov avatar Matthew Pope avatar Jordan Arentsen avatar Alex Sherbakov avatar Milos Gajdos avatar Mathew Polzin avatar Bryan A. S. avatar Jérémie Zarca avatar Wojtek Zymonik avatar Juri Hahn avatar Nikita avatar Rija Ménagé avatar Florian Klein avatar  avatar John Beimler avatar  avatar Ali Sabil avatar Ömer Karabacak avatar Mustafa Paltun avatar Alejandro M. Ramallo avatar Harun Oral avatar David.Gao avatar Felipe Menegazzi avatar Serge Aleynikov avatar lemon avatar

Watchers

Gowthaman Basuvaraj avatar  avatar  avatar Michael Rayva avatar Kostas Georgiou avatar  avatar

pgec's Issues

JSONB Support

Hi Peter,

I encountered an issue when dealing with JSONB columns in a publication. When I add the test data like this:

CREATE TABLE public.json_sample (id serial PRIMARY KEY, keyval jsonb);
INSERT INTO public.json_sample (keyval) VALUES ('{"foo": "bar", "baz": 1}');

When I change the publication to this dataset, pgec seem to crash and the REST API is not available anymore:

=CRASH REPORT==== 3-Mar-2023::19:10:32.062821 === <0.6203.0> proc_lib:crash_report/4:539
  crasher:
    initial call: cowboy_stream_h:request_process/3
    pid: <0.6203.0>
    registered_name: []
    exception error: bad argument
      in function  ets:safe_fixtable/2
         called as ets:safe_fixtable(osm_rivers_sample,true)
         *** argument 1: the table identifier does not refer to an existing ETS table
      in call from ets:foldl/3 (ets.erl, line 632)
      in call from pgec_h:init/3 (src/pgec_h.erl, line 51)
      in call from cowboy_handler:execute/2 (src/cowboy_handler.erl, line 37)
      in call from cowboy_stream_h:execute/3 (src/cowboy_stream_h.erl, line 306)
      in call from cowboy_stream_h:request_process/3 (src/cowboy_stream_h.erl, line 295)
    ancestors: [<0.6201.0>,<0.217.0>,<0.216.0>,ranch_sup,<0.116.0>]
    message_queue_len: 0
    messages: []
    links: [<0.6201.0>]
    dictionary: []
    trap_exit: false
    status: running
    heap_size: 376
    stack_size: 28
    reductions: 323
  neighbours:

=ERROR REPORT==== 3-Mar-2023::19:10:32.064281 === <0.6201.0>
Ranch listener pgec, connection process <0.6201.0>, stream 1 had its request process <0.6203.0> exit with reason badarg and stacktrace [{ets,safe_fixtable,[osm_rivers_sample,true],[{error_info,#{cause => id,module => erl_stdlib_errors}}]},{ets,foldl,3,[{file,"ets.erl"},{line,632}]},{pgec_h,init,3,[{file,"src/pgec_h.erl"},{line,51}]},{cowboy_handler,execute,2,[{file,"src/cowboy_handler.erl"},{line,37}]},{cowboy_stream_h,execute,3,[{file,"src/cowboy_stream_h.erl"},{line,306}]},{cowboy_stream_h,request_process,3,[{file,"src/cowboy_stream_h.erl"},{line,295}]},{proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,240}]}]

Could look into this?

PostGIS support

Hi @shortishly,

I learned about this project from Scaling Postgres#254 - very interesting work!

I tried to replace the test data with my own data and encountered an issue. I'm using PostGIS (geometry and raster) data, which basically worked in the REST API, but unfortunately was encoded binary in the output:

image

Maybe this is how pgec handles all non-simple UDTs.

It would be great to add ST_AsBinary(), ST_AsText() or ST_AsGEOJSON() for the output PostGIS vector geometries of pgec (REST, Memcached and Redis API) and maybe ST_AsBinary() for PostGIS raster objects.

I'm happy to contribute if you point me to the code - although I don't have any knowledge in Erlang.

Best regards,
Johannes

Feature idea: PostgreSQL API

I am very impressed by the idea behind this product.

How realistic is the idea of implementing a PostgreSQL API?

The PostgreSQL API should behave like a real PostgreSQL Server.
Read operations are served from the in memory cache.
Write operations are proxyed to the PostgreSQL server.
Like the current REDIS API.

The biggest advantage of a PostgreSQL API would be the integration of PGEC without code changes for applications.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.