2

I would like to use Visual Studio Code to preform my PostgreSQL queries, and general DB maintenance as an alternative to pgAdmin4. I have read the documentation included with the appropriate extention (PostgreSQL by MS). When I try to Create A New Profile I get the following prompt:

Server Name Prompt

I am working from an Apple Mac so I attempted localhost at first. That did not work. I tried the ip address of the local computer with the same result. I attempted just giving the name of the DB, but that did not work either. Any suggestions as to what I can try next. I am terrible at spelling and rembering names so I would like some form of IDE support when I am working.

This is the error I get: PostgreSQL: Failed to connect: could not translate host name "localhost\Local" to address: nodename nor servname provided, or not known

1
  • Yes, I can ping local host. The error comes from VSC.
    – Gabe Ruiz
    Apr 21, 2019 at 19:59

2 Answers 2

0

As per documentation here Npgsql has a Visual Studio extension (VSIX) which integrates PostgreSQL access into Visual Studio. It allows connecting to PostgreSQL from within Visual Studio's Server Explorer, create an Entity Framework 6 model from an existing database, etc. The extension can be installed directly from the Visual Studio Marketplace page.

The VSIX doesn't automatically add Npgsql to your GAC, App.config, machines.config or any other project or system-wide resource. It only allows accessing PostgreSQL from Visual Studio itself.

As here you van find out, How to Connect Visual Studio LightSwitch to PostgreSQL with dotConnect for PostgreSQL Data Provider.

As per postgresql documentation here Could not translate host name localhost, service 5432 to address: nodename nor servname provided, or not known.

Usually this error is caused by broken /etc/hosts file. The problem could be a missing localhost entry, syntax errors or incorrect whitespace.

For reference, here is what this file should look like by default on macOS:

##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##
127.0.0.1   localhost
255.255.255.255 broadcasthost
::1             localhost 

For further you ref here, here, here and here

2
  • The question is about Visual Studio Code, no?
    – mustaccio
    Apr 21, 2019 at 13:05
  • Yes I had read through that documentation and have a hosts file in /etc. I have added a line called postgres as another user documentation suggested without success.
    – Gabe Ruiz
    Apr 21, 2019 at 20:00
0

The notation hostname\instance is a typical Microsoft SQL Server notation. PostgreSQL doesn't have the concept of instances like MSSQL does. However, PostgreSQL is run in an instance, it just doesn't have a name.

Maybe a simple localhost:5432 might work.

Then you might have to add or uncomment a line similar to the following in the pg_hba.conf file of the PostgreSQL instance:

# TYPE  DATABASE        USER            ADDRESS                 METHOD
local   all             all                                     trust
1
  • @a_horse_with_no_name I think this answer may be slightly better. No idea where I was with my thoughts when I wrote the initial answer.
    – John K. N.
    Feb 18, 2022 at 10:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.