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 1kcAiE-0007hw-H8 for pgsql-general@arkaria.postgresql.org; Mon, 09 Nov 2020 17:12:14 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kcAiD-00042Q-Fs for pgsql-general@arkaria.postgresql.org; Mon, 09 Nov 2020 17:12:13 +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 1kcAiD-00042I-7e for pgsql-general@lists.postgresql.org; Mon, 09 Nov 2020 17:12:13 +0000 Received: from mail-ej1-x641.google.com ([2a00:1450:4864:20::641]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kcAiA-0003nm-Kt for pgsql-general@lists.postgresql.org; Mon, 09 Nov 2020 17:12:12 +0000 Received: by mail-ej1-x641.google.com with SMTP id o21so13360469ejb.3 for ; Mon, 09 Nov 2020 09:12:10 -0800 (PST) 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=fFf4tEcZfKxGmO4RWGbVCKq5wwuwwnbVUkF8MT2Xz0c=; b=uVNfiwhYgX3ExSffrf4hc16PVnatMsH5G88LxBbjh0TVozADu3YMjE4FU2w3kVLqGl JzT3O7HyOLw/7bIWCBXe9Rj0YAMvfd0/0gxx9JAPGIzipma7hDOCpdDzMYdnKtTe+gA9 uIz+4bmnOqtWpuZMFM0tA+WPcDYK9i7DdCFx6/O0r3WI5sS3cXjNTTVagUD4TlEf/Pho fBP4whiHUjz39wpVr8Sd5qKCTydP5j0wwAkOn4D0SXmOVwxSebICc1s+sJcsdFddmnRI C3qz9euK8UJvEXcIMZTqCxd8u4TevXufMMO52+ewsHQxeDDWze3m/Q0ELhGn9OttsQmc 4Rrw== 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=fFf4tEcZfKxGmO4RWGbVCKq5wwuwwnbVUkF8MT2Xz0c=; b=uLd+OR3KhI2ZCf9zyixVl+H9DYhDRgKCAp2nPr+XKzbcMcEaOwp8XwFhf0AmGCGpib WZoMnJXmPM7quUczPa1RekyCrEiyKpqNf/5l+GaKLk3680ewv3YTrO2ViXwfD19b+qId emh3oXUo2JKQ4lF0eVESrgmOpcwQajG6QUQ8aOx8U9DoGUz2MJ+kaF7g5YQbayYNeHaW wfnuIzhVPmRn0yo710tlg4cCxO7BBDYas5aMPY+kREOyZNeh42Pj1ygGp6FOzA8rQRK7 sQ6BAAHKa5Lv1TeRKLexRCTGdEbbuPiQ1AIAxonjge74u5KfjgCfpanIG5vHusX65a8L d5YA== X-Gm-Message-State: AOAM533kdKmr2V/ZodSgz8pzaRn247ZpJdWD9a38SCT4dqlWiKHms45c TSCO/GUjUAz2WJj7mmPsRUSxhDPqBI2k/Q== X-Google-Smtp-Source: ABdhPJysLDES25HFeEX9CJZTeR9rP3li1+0pRNkji+6wjOz7DLzraMvTzvqOxgKNoUD0eYZD3fmTqw== X-Received: by 2002:a17:906:d8b3:: with SMTP id qc19mr15524455ejb.222.1604941929243; Mon, 09 Nov 2020 09:12:09 -0800 (PST) Received: from localhost.localdomain (217-149-175-94.nat.highway.telekom.at. [217.149.175.94]) by smtp.gmail.com with ESMTPSA id a10sm9193656edn.77.2020.11.09.09.12.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Nov 2020 09:12:08 -0800 (PST) Message-ID: Subject: Re: Foreign Data Wrapper Handler From: Laurenz Albe To: susan.hurst@brookhurstdata.com, pgsql-general@lists.postgresql.org Date: Mon, 09 Nov 2020 18:12:08 +0100 In-Reply-To: <935b28a237e31f840b24d5e090e09342@mail.brookhurstdata.net> References: <376c4b35-383d-33bf-d22c-0939e034b455@aklaver.com> <935b28a237e31f840b24d5e090e09342@mail.brookhurstdata.net> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.36.5 (3.36.5-1.fc32) MIME-Version: 1.0 Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Sun, 2020-11-08 at 13:09 -0600, Susan Hurst wrote: > The first pass thru https://www.postgresql.org/docs/12/fdwhandler.html > does not tell me what I think I need to know, but I will digest this > more thoroughly. Maybe I need to understand more of the lingo re: > foreign data wrappers. I do understand that all fdw names must be unique > within a database so if I want to connect to more than one foreign db, I > need a different name for each connection. I cannot name each fdw > postgres_fdw. I would like to name the fdws something like: > dbname_to_foreigndbname. > > For example, here are 2 possible fdws: > > create foreign data wrapper stp_to_geo; > create foreign data wrapper stp_to_metrics; > > That syntax creates the fdw and I can create user mappings but I cannot > import any foreign schemas into my database. The error message says that > there is no handler for the fdw. That's where I'm stuck. > > BTW, I did try using postgres_fdw as a handler... > > create foreign data wrapper stp_to_geo handler postgres_fdw; > > ...but then I got these errors: > ERROR: function postgres_fdw() does not exist > ERROR: foreign-data wrapper "stp_to_geo" does not exist > > Looks like I need to study a bit more. This is how you would create a new foreign data wrapper object for PostgreSQL: CREATE FOREIGN DATA WRAPPER myfdw HANDLER public.postgres_fdw_handler VALIDATOR public.postgres_fdw_validator; This assumes that you installed the extension "postgres_fdw" in schema "public". But you normally don't have to create a new foreign data wrapper: the one named "postgres_fdw" that is created by the extension is good enough. The only reason would be to have a foreign data wrapper with non-default options, but since there are no options for "postgres_fdw", that is moot. So don't do that. The hierarchy of objects is as follows: - The foreign data wrapper encapsulates the code required to access the foreign data source. You need only one per database; no need to create a new one. - The foreign server encapsulates the connection string to access a remote PostgreSQL database. Define one per remote database you want to access. - The user mapping encapsulates the credentials for a user to access a foreign server. Create one per user and foreign server (or a single one for PUBLIC = everybody). - The foreign table describes how a remote table is mapped locally. Define one per table that interests you. Yours, Laurenz Albe -- Cybertec | https://www.cybertec-postgresql.com