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 1k5QEN-0007mK-EX for pgsql-general@arkaria.postgresql.org; Tue, 11 Aug 2020 09:06:03 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1k5QEK-0003hs-59 for pgsql-general@arkaria.postgresql.org; Tue, 11 Aug 2020 09:06:00 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1k5QEJ-0003hk-T3 for pgsql-general@lists.postgresql.org; Tue, 11 Aug 2020 09:05:59 +0000 Received: from mail-ej1-x643.google.com ([2a00:1450:4864:20::643]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1k5QEG-0003dD-Hq for pgsql-general@lists.postgresql.org; Tue, 11 Aug 2020 09:05:59 +0000 Received: by mail-ej1-x643.google.com with SMTP id bo3so12247347ejb.11 for ; Tue, 11 Aug 2020 02:05:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec-at.20150623.gappssmtp.com; s=20150623; h=message-id:subject:from:to:date:in-reply-to:references:user-agent :mime-version:content-transfer-encoding; bh=zABsC5RN2aOHh8pRqYrc/KLuoqefMFC2kk9ZMosqet8=; b=WrIJcv8Rg5kj8pYCn8/4+i5pLQCkRMZVLmLdvQtxKc3VpS7EL2JCDY7yJKgMuGQ0AF dk8zbnotlR5+PRu8VAkDV+Xl080fxR+yNCBJsb+yEUAyt+ToAKBCXFS/W1EemITN4+Gf X0hOU82o8hMTtByZyNSPIQkbWGXX4D4nMaGEdl8YE7Gx0VANAVszDBbx4tYdvSpLp5/Q 36al4VbESs1b1G2ywj7BRSRKBV16SfzFXEBfZjQSg2KhbfDzVFE9+FyFo7uQ6jSX6qwA ijNjOVK1TMKWmaLAytY9NYgBMtEfd9YgzB9dzka2nMolZyG7oJFGGZLuxbPCJYd7ozDq OW4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:subject:from:to:date:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=zABsC5RN2aOHh8pRqYrc/KLuoqefMFC2kk9ZMosqet8=; b=FvDL0sWh4t+siqs2mvwt2EhyTT9tCvHJ5ada/91YSNDvd8RTPdfNkSpIV3ZqKnN7V2 vW1TcNeVkChVmUWwjannzZa3bl34k0Ns1U+HsmdDCUNGoiALQ99l89SuUyHiTQOF2TV3 2dFugFQ7fEvvjx0soLMM4yTw1qiXQwAMryM1nXXpkKsirGW17GwzXjQwAJb6Bj1fbu7T mMqPXm0R9tFnbbPAjypT2/X/GEfp3CePG3blBppRy3vJMhjptTXtA3Gv2WmMrSBEfw6e UAOgcwpGkk/vxHHwUD5ZK2wWVP/2CmFAOvOJW964DO3V1iNKD5RwtFGLN7P1OhU7l1x9 MPkg== X-Gm-Message-State: AOAM5308IRfDQhPdTSRORG7/7bh5Wso+PDnJV7cLSP2IAEFBwgPotjqU JjYWX4XhcFWJqZUcSqKubdCN6A== X-Google-Smtp-Source: ABdhPJyywpxdlf6CzoZ/2iM6u8Qgzxx11BqtJEMQ8ZZl0Co2MmztBVz7ckIltxM7dRUxmH4L5Gm2Vg== X-Received: by 2002:a17:906:c143:: with SMTP id dp3mr24899486ejc.504.1597136755574; Tue, 11 Aug 2020 02:05:55 -0700 (PDT) Received: from localhost.localdomain (217-149-170-169.nat.highway.telekom.at. [217.149.170.169]) by smtp.gmail.com with ESMTPSA id m24sm14399200eje.80.2020.08.11.02.05.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Aug 2020 02:05:55 -0700 (PDT) Message-ID: Subject: Re: Keeping state in a foreign data wrapper From: Laurenz Albe To: Stelios Sfakianakis , pgsql-general@lists.postgresql.org Date: Tue, 11 Aug 2020 11:05:54 +0200 In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.36.4 (3.36.4-1.fc32) MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Mon, 2020-08-03 at 19:23 +0300, Stelios Sfakianakis wrote: > 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 “per-user” 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? I would create a table as part of the extension and use SPI to store the data there. Yours, Laurenz Albe