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

  • Welcome to the site, Can you please ping localhost ? Are you getting that error from the psql? – Md Haidar Ali Khan Apr 21 '19 at 7:35
  • Yes, I can ping local host. The error comes from VSC. – Gabe Ruiz Apr 21 '19 at 19:59

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.
##   localhost broadcasthost
::1             localhost 

For further you ref here, here, here and here

  • The question is about Visual Studio Code, no? – mustaccio Apr 21 '19 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 '19 at 20:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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