dblink does not resolve DNS, but works with IP

Started by Mike Christensenalmost 13 years ago6 messagesgeneral
Jump to latest
#1Mike Christensen
mike@kitchenpc.com

If I have this:

CREATE OR REPLACE VIEW Link.Foo AS
select * from dblink(
'hostaddr=123.123.123.123 dbname=KitchenPC user=Website
password=secret',
'select * from Foo') as ...

Then it works. However, if I do:

CREATE OR REPLACE VIEW Link.Foo AS
select * from dblink(
'hostaddr=db.domain.com dbname=KitchenPC user=Website password=secret',
'select * from Foo') as ...

Then I get:

ERROR: could not establish connection
DETAIL: could not translate host name "db.domain.com" to address: Unknown
host

However, from a command prompt I can ping db.domain.com and get
123.123.123.123.

Does dblink just not support DNS resolution? I really don't want to hard
code IP addresses in my scripts. Thanks!

#2Adrian Klaver
adrian.klaver@aklaver.com
In reply to: Mike Christensen (#1)
Re: dblink does not resolve DNS, but works with IP

On 05/14/2013 09:17 PM, Mike Christensen wrote:

If I have this:

CREATE OR REPLACE VIEW Link.Foo AS
select * from dblink(
'hostaddr=123.123.123.123 dbname=KitchenPC user=Website
password=secret',
'select * from Foo') as ...

Then it works. However, if I do:

CREATE OR REPLACE VIEW Link.Foo AS
select * from dblink(
'hostaddr=db.domain.com <http://db.domain.com&gt; dbname=KitchenPC
user=Website password=secret',
'select * from Foo') as ...

Then I get:

ERROR: could not establish connection
DETAIL: could not translate host name "db.domain.com
<http://db.domain.com&gt;&quot; to address: Unknown host

However, from a command prompt I can ping db.domain.com
<http://db.domain.com&gt; and get 123.123.123.123.

Does dblink just not support DNS resolution? I really don't want to
hard code IP addresses in my scripts. Thanks!

See below for explanation of hostaddr and host. Short version, you are
looking for host:

http://www.postgresql.org/docs/9.2/interactive/libpq-connect.html#LIBPQ-PARAMKEYWORDS

--
Adrian Klaver
adrian.klaver@gmail.com

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

#3Mike Christensen
mike@kitchenpc.com
In reply to: Adrian Klaver (#2)
Re: dblink does not resolve DNS, but works with IP

Excellent! Thanks so much.

On Tue, May 14, 2013 at 9:25 PM, Adrian Klaver <adrian.klaver@gmail.com>wrote:

Show quoted text

On 05/14/2013 09:17 PM, Mike Christensen wrote:

If I have this:

CREATE OR REPLACE VIEW Link.Foo AS
select * from dblink(
'hostaddr=123.123.123.123 dbname=KitchenPC user=Website
password=secret',
'select * from Foo') as ...

Then it works. However, if I do:

CREATE OR REPLACE VIEW Link.Foo AS
select * from dblink(
'hostaddr=db.domain.com <http://db.domain.com&gt; dbname=KitchenPC

user=Website password=secret',
'select * from Foo') as ...

Then I get:

ERROR: could not establish connection
DETAIL: could not translate host name "db.domain.com
<http://db.domain.com&gt;&quot; to address: Unknown host

However, from a command prompt I can ping db.domain.com
<http://db.domain.com&gt; and get 123.123.123.123.

Does dblink just not support DNS resolution? I really don't want to
hard code IP addresses in my scripts. Thanks!

See below for explanation of hostaddr and host. Short version, you are
looking for host:

http://www.postgresql.org/**docs/9.2/interactive/libpq-**
connect.html#LIBPQ-**PARAMKEYWORDS<http://www.postgresql.org/docs/9.2/interactive/libpq-connect.html#LIBPQ-PARAMKEYWORDS&gt;

--
Adrian Klaver
adrian.klaver@gmail.com

#4Mike Christensen
mike@kitchenpc.com
In reply to: Mike Christensen (#3)
Re: dblink does not resolve DNS, but works with IP

Though I'm a bit curious why there's a host and hostaddr. Why can't it
just resolve whatever you give it?

On Tue, May 14, 2013 at 9:31 PM, Mike Christensen <mike@kitchenpc.com>wrote:

Show quoted text

Excellent! Thanks so much.

On Tue, May 14, 2013 at 9:25 PM, Adrian Klaver <adrian.klaver@gmail.com>wrote:

On 05/14/2013 09:17 PM, Mike Christensen wrote:

If I have this:

CREATE OR REPLACE VIEW Link.Foo AS
select * from dblink(
'hostaddr=123.123.123.123 dbname=KitchenPC user=Website
password=secret',
'select * from Foo') as ...

Then it works. However, if I do:

CREATE OR REPLACE VIEW Link.Foo AS
select * from dblink(
'hostaddr=db.domain.com <http://db.domain.com&gt; dbname=KitchenPC

user=Website password=secret',
'select * from Foo') as ...

Then I get:

ERROR: could not establish connection
DETAIL: could not translate host name "db.domain.com
<http://db.domain.com&gt;&quot; to address: Unknown host

However, from a command prompt I can ping db.domain.com
<http://db.domain.com&gt; and get 123.123.123.123.

Does dblink just not support DNS resolution? I really don't want to
hard code IP addresses in my scripts. Thanks!

See below for explanation of hostaddr and host. Short version, you are
looking for host:

http://www.postgresql.org/**docs/9.2/interactive/libpq-**
connect.html#LIBPQ-**PARAMKEYWORDS<http://www.postgresql.org/docs/9.2/interactive/libpq-connect.html#LIBPQ-PARAMKEYWORDS&gt;

--
Adrian Klaver
adrian.klaver@gmail.com

#5Tom Lane
tgl@sss.pgh.pa.us
In reply to: Mike Christensen (#4)
Re: dblink does not resolve DNS, but works with IP

Mike Christensen <mike@kitchenpc.com> writes:

Though I'm a bit curious why there's a host and hostaddr. Why can't it
just resolve whatever you give it?

Well, it will ... if you use the "host" parameter. The whole point of
"hostaddr" is that for that parameter, it will not try a DNS lookup.
You'd only use that if you had issues with the speed or reliability
of your DNS service.

regards, tom lane

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

#6Mike Christensen
mike@kitchenpc.com
In reply to: Tom Lane (#5)
Re: dblink does not resolve DNS, but works with IP

Ah, gotcha! I guess whatever sample I was originally copying from used
hostaddr for some reason.. Thanks for the clarification, Tom!

On Wed, May 15, 2013 at 6:08 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:

Show quoted text

Mike Christensen <mike@kitchenpc.com> writes:

Though I'm a bit curious why there's a host and hostaddr. Why can't it
just resolve whatever you give it?

Well, it will ... if you use the "host" parameter. The whole point of
"hostaddr" is that for that parameter, it will not try a DNS lookup.
You'd only use that if you had issues with the speed or reliability
of your DNS service.

regards, tom lane