Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1k2dFs-0002U9-BM for pgsql-general@arkaria.postgresql.org; Mon, 03 Aug 2020 16:24:04 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1k2dFq-00028Y-7h for pgsql-general@arkaria.postgresql.org; Mon, 03 Aug 2020 16:24:02 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1k2dFp-00028Q-Ty for pgsql-general@lists.postgresql.org; Mon, 03 Aug 2020 16:24:01 +0000 Received: from mail-wr1-x433.google.com ([2a00:1450:4864:20::433]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1k2dFj-0003YC-Ef for pgsql-general@lists.postgresql.org; Mon, 03 Aug 2020 16:24:00 +0000 Received: by mail-wr1-x433.google.com with SMTP id l2so24237418wrc.7 for ; Mon, 03 Aug 2020 09:23:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:content-transfer-encoding:mime-version:subject:message-id:date :to; bh=jsWJT/W9PkNz+Rs6TLmAIXgjViDdvPcG4CQ8zwl5gUE=; b=CTf3cXaZ55WoHENyZLZ73Pb6klAzbEeH4bjhF7HcrY5jq2Atzhpg0BA5PTecDC4pW6 lawa+Mz7+MBJ3Jl1jujTs/xCIRFxe9AFmUta5BZTwcH+kHNtfjpi5VWIcdCW2StKS9J7 Gk2CeQtx941NRyxsTQ6Bg09+kcSwMHWpMWQqfNKMI57/CRvKFrbxKM8MsthQnn2HIIsr bsYBNbTRif2HrylwWpjqnSkW3SWUk1w4LG6gQkDXRXPp9zG0toFyhLs2iPhdYekh5pDH P3nwbG6JOHNVEyaxc+hShwaLP9bhK0glUw3nEWkY9YGln931VBoYTBkRXsWlj5VSkmMD kX5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:content-transfer-encoding:mime-version :subject:message-id:date:to; bh=jsWJT/W9PkNz+Rs6TLmAIXgjViDdvPcG4CQ8zwl5gUE=; b=D2brQL0lPuHOdFvmk2HkH1GYGy4GZCXjF61U8D2lOHgZnsD8emM0uQkF2qCjZbXN2e OOz/jUgyJUPuqVQABN3uhOkYgvEfWt8mrAqyaMcjp3X7ylUngSkO5zYR3NKo9IOhBSlR AOKs/KIU9utlHwPTsUl/aXX6UTPBbwQ5F8wDq62yGtvykl5WCXeqSmhY9XIcZJo+lSPG ccwgd6GKaEPn5dvFB89DkHSwW4WxQk4UkvRlYLTC5MAUlo2CJ5F5QMvQ4NwPE5K054P/ b2ROeZ0pOLt8pWmqQ1pJlYyRkuv5p2t8bFqBwy0AdnDoh6Rdbal5caLVHzC9jCUxMQ4X Im3g== X-Gm-Message-State: AOAM531TcxX+4JqpIY5L6YtAV5uMp0n2DH8yEJx9WtXGQpka0PN04W7l BTVN3qnlcaXSIgNMPAR37Ltqvb7NE0c= X-Google-Smtp-Source: ABdhPJzfXl3liMuShIXaD1RPT+Vonf9xFSBzmE4rL5+uzgGCOJT0b7/MbJL4olXyntjf8hkh6u0Cog== X-Received: by 2002:a5d:490c:: with SMTP id x12mr15100802wrq.238.1596471833177; Mon, 03 Aug 2020 09:23:53 -0700 (PDT) Received: from imac-user.ics.forth.gr ([139.91.190.53]) by smtp.gmail.com with ESMTPSA id h11sm27429136wrb.68.2020.08.03.09.23.51 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 03 Aug 2020 09:23:52 -0700 (PDT) From: Stelios Sfakianakis Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Mime-Version: 1.0 (Mac OS X Mail 11.5 \(3445.9.1\)) Subject: Keeping state in a foreign data wrapper Message-Id: Date: Mon, 3 Aug 2020 19:23:50 +0300 To: pgsql-general@lists.postgresql.org X-Mailer: Apple Mail (2.3445.9.1) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Hi, I am trying to implement a FDW in Postgres for accessing a web api and = I would like to keep information like for example the total number of = requests submiited. Ideally these data should be kept =E2=80=9Cper-user=E2= =80=9D and of course with the proper locking to eliminate race = conditions. So the question I have is how to design such a global (but = per user and database) state, using the C FDW API of Postgres. I have = gone through the API and for example I see various fdw_private fields in = the query planning structures and callbacks but these do not seem to be = relevant to my requirements. Another possiblity seems to be to use = shared memory = (https://www.postgresql.org/docs/12/xfunc-c.html#id-1.8.3.13.14) but it = is even less clear how to do it. So is there any simple way to do implement such shared thread/process = safe state? Thank you Stelios