dblink module printing unnamed connection (with commit acaf7ccb94)

Started by Rushabh Lathiaover 9 years ago2 messageshackers
Beta feature

Hackorum builds and tests every patch posted to the lists, not only commitfest submissions. This is Hackorum's own CI rather than the PostgreSQL project's, and it is still under testing - please report anything that looks wrong.

won't retrytests failedCI history

You can run a PostgreSQL built from this patch straight from Docker, with no checkout and no build:

docker run --rm -p 5432:5432 ghcr.io/hackorum-dev/postgres-patch:t36308
psql -h localhost -U postgres

Built from patchset v1 (message #1), July 28, 2026 at 07:45 AM.

Every patchset is also pushed to a branch of our PostgreSQL fork, so you can check out the same tree CI built. Without a PostgreSQL checkout:

git clone --branch t36308_1 https://github.com/hackorum-dev/postgres.git

In a checkout you already have, add the fork once:

git remote add hackorum https://github.com/hackorum-dev/postgres.git

then, for this patchset and every later one:

git fetch hackorum t36308_1 && git checkout t36308_1

Patchset v1 (message #1) is on t36308_1

Jump to latest
#1Rushabh Lathia
rushabh.lathia@gmail.com

Hi All,

DBLINK contrib module started showing :"unnamed" connection name.

Consider the below test:

postgres=# CREATE ROLE alice NOSUPERUSER NOCREATEDB NOCREATEROLE LOGIN
PASSWORD 'wonderland';
CREATE ROLE
postgres=# GRANT EXECUTE ON FUNCTION dblink_connect_u(text,text) to alice;
GRANT
postgres=# \c postgres alice
You are now connected to database "postgres" as user "alice".
postgres=> SELECT dblink_connect_u('sm_conn_30','dbname=postgres user=alice
password=wonderland');
dblink_connect_u
------------------
OK
(1 row)

postgres=> SELECT * FROM dblink_send_query('sm_conn_30','SELECT
pg_stat_reset()') as dgr;
dgr
-----
1
(1 row)

postgres=> SELECT * FROM dblink_get_result('sm_conn_30') AS dgr(curr_user
boolean);
ERROR: permission denied for function pg_stat_reset
CONTEXT: Error occurred on dblink connection named "*unnamed*": could not
execute query.

This started with below commit:

commit acaf7ccb94a3916ea83712671a3563f0eb595558
Author: Peter Eisentraut <peter_e@gmx.net>
Date: Sun Dec 25 12:00:00 2016 -0500

dblink: Replace some macros by static functions

Also remove some unused code and the no longer useful dblink.h file.

Reviewed-by: Tsunakawa, Takayuki <tsunakawa.takay@jp.fujitsu.com>

Before this, macro used to assign the conname local variable; I quickly
worked
on the fix and attached patch do fix the issues. Patch assign the conname
local variable, so that error context show the correct connection name.

Regards,
Rushabh Lathia
www.EnterpriseDB.com

Attachments:

t36308_1
dblink_error_context.patchtext/x-patch; charset=US-ASCII; name=dblink_error_context.patchDownload+9-7
#2Peter Eisentraut
peter_e@gmx.net
In reply to: Rushabh Lathia (#1)
Re: dblink module printing unnamed connection (with commit acaf7ccb94)

On 3/23/17 01:38, Rushabh Lathia wrote:

DBLINK contrib module started showing :"unnamed" connection name.

Before this, macro used to assign the conname local variable; I quickly
worked
on the fix and attached patch do fix the issues. Patch assign the conname
local variable, so that error context show the correct connection name.

Committed, thanks.

In dblink_record_internal(), I moved the conname =
text_to_cstring(PG_GETARG_TEXT_PP(0)) call a little bit, because it does
not apply in all code paths, so it could be a problem if you try to read
a text argument that the function is not actually passing in.

--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers