Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Connect to PostgreSQL-base by Unit-Socket

 
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
     
     I use TCP-connection to remote postgre-database by:


   And it working successfully.

   But I cant use UNIX-Socket connection:


    PostgreSQL-version 9.2

   
 
Saloon Keeper
Posts: 6448
158
Android Mac OS X Firefox Browser VI Editor Tomcat Server Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The connections would always use sockets, so I'm confused why you mention that fact so prominently.

The difference seems to be that you left out the host name in the second - but that's required. If you mean to connect locally, use 127.0.0.1 or localhost.
 
Andrey Dmitriev
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
  Tim Moores,
 I try "jdbc:postgresql://localhost/test_psql" and receive the same error
 
Tim Moores
Saloon Keeper
Posts: 6448
158
Android Mac OS X Firefox Browser VI Editor Tomcat Server Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which error is that?

Have you tried 127.0.0.1?
 
Andrey Dmitriev
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
  Yes, I tried.

  In stack:

rg.postgresql.util.PSQLException: Connection to 127.0.0.1:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
 
Andrey Dmitriev
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I add to pom dependencies:



And change url to this:



I receive in stack now:

 
Tim Moores
Saloon Keeper
Posts: 6448
158
Android Mac OS X Firefox Browser VI Editor Tomcat Server Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not sure what "org.newsclub.net.unix.NarSystem" but it seems to get in the way. Maybe start with fixing that.

Is Postgres running on your local machine on that port?

Can you log in using those credentials with the psql utility?
 
Andrey Dmitriev
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
  And Postgres is indeed running on your local machine on that port?
 
  Yes.  Application and database mounted on one and the same server with host: remotehost.com.
  TCP-connrction between them is posible, but will be not so fast as by unix-socket
 
Andrey Dmitriev
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim Moores

  I dont understand now how can I  access  to  database by unit-socket,  using psql.

 In a case of TCP-port  I  run the following  "psql -h remotehost.ru -p 5432 -d test_psql"
 
Saloon Keeper
Posts: 22122
151
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Andrey Dmitriev wrote:   And Postgres is indeed running on your local machine on that port?
 
  Yes.  Application and database mounted on one and the same server with host: remotehost.com.
  TCP-connrction between them is posible, but will be not so fast as by unix-socket



I think you are confused about how the network stack works. If you do not provide a hostname on the JDBC URL, then localhost is assumed. Localhost requests are tied (routed) to the loopback network device because that's how the network stack is implemented.

However, if you are going to access a PostgreSQL server on localhost, you need to make sure that there is in fact a PostgreSQL server running on the localhost, that it has been configured to listen on the proper ports (5432 by default), that there are no intervening firewall rules blocking you and that finally, that the user authentication mechanism that you are using to contact the database is valid for that set of credentials, that contact source and that database. PostgreSQL is quite paranoid.

Some of these restrictions do no apply when using Unix-domain sockets instead of TCP. However unless you are moving large amounts of data in a single transaction, Unix-domain sockets may not give as much of a boost as hoped for over TCP. And, of course, you do have to have the PostgreSQL server configured properly for Unix-domain sockets. And be running a relatively recent JDBC driver, since this wasn't even an option until PostgreSQL 9.4-1208.

Unix-domain sockets do have a performance advantage, but they also limit you. They only work on the local machine, and in today's virtualized and containerized world, that may not be good enough. It's not uncommon to have a completely separate physical host(s) for a high-performance database installation. And as far as I know, you cannot at this time do domain sockets between containers and containers are very popular as elastic services for webapp servers and other processes. The current mood is that it's better to throw more machines at a problem than to tune fewer ones because hardware is cheap but specialized labor isn't.
 
Arch enemy? I mean, I don't like you, but I don't think you qualify as "arch enemy". Here, try this tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic