Thread: error on connecting port 5432
Hi, When I m creating a test db user using below command using root OS user sudo -u postgres createuser -p 5432 --pwprompt testuser I am getting the attached error of port. But my postgres services are running fine on port 5432, I am sharing the screenshot of that also. So please help me in letting me know why I am getting the above error when I am connected to the root OS user? Note - I am able to create a test db user when I am connected to postgres using psql command. Regards, Atul
Attachment
On 12/1/20 12:51 AM, Atul Kumar wrote: > Hi, > > When I m creating a test db user using below command using root OS user > sudo -u postgres createuser -p 5432 --pwprompt testuser > > I am getting the attached error of port. > > But my postgres services are running fine on port 5432, I am sharing > the screenshot of that also. In future please include this as text not images. > > So please help me in letting me know why I am getting the above error > when I am connected to the root OS user? You are not connecting as OS root you are connecting as the database user testuser. Does /var/run/postgresql/.s.PGSQL.5432 exits? Do you have more then one instance of Postgres on this machine? If so how where they installed and more importantly where they installed differently? As a test try running the command with addition of -h localhost. > > Note - I am able to create a test db user when I am connected to > postgres using psql command. > > > Regards, > Atul > -- Adrian Klaver adrian.klaver@aklaver.com
On 12/1/20 6:26 AM, Adrian Klaver wrote: > On 12/1/20 12:51 AM, Atul Kumar wrote: >> Hi, >> >> When I m creating a test db user using below command using root OS user >> sudo -u postgres createuser -p 5432 --pwprompt testuser >> >> I am getting the attached error of port. >> >> But my postgres services are running fine on port 5432, I am sharing >> the screenshot of that also. > > In future please include this as text not images. > >> >> So please help me in letting me know why I am getting the above error >> when I am connected to the root OS user? > > You are not connecting as OS root you are connecting as the database > user testuser. > > Does /var/run/postgresql/.s.PGSQL.5432 exits? Does /var/run/postgresql/.s.PGSQL.5432 exist? > > Do you have more then one instance of Postgres on this machine? > > If so how where they installed and more importantly where they installed > differently? > > As a test try running the command with addition of -h localhost. > >> >> Note - I am able to create a test db user when I am connected to >> postgres using psql command. >> >> >> Regards, >> Atul >> > > -- Adrian Klaver adrian.klaver@aklaver.com
Hi,
On Tuesday, December 1, 2020, Adrian Klaver <adrian.klaver@aklaver.com> wrote:
Just to clarify that I am at root OS user, trying to create a test user using postgres user(-u) with create user command.
Error screenshots are already shared with you.
Please re-check the same.
Regards
Atul
On Tuesday, December 1, 2020, Adrian Klaver <adrian.klaver@aklaver.com> wrote:
On 12/1/20 12:51 AM, Atul Kumar wrote:Hi,
When I m creating a test db user using below command using root OS user
sudo -u postgres createuser -p 5432 --pwprompt testuser
I am getting the attached error of port.
But my postgres services are running fine on port 5432, I am sharing
the screenshot of that also.
In future please include this as text not images.
So please help me in letting me know why I am getting the above error
when I am connected to the root OS user?
You are not connecting as OS root you are connecting as the database user testuser.
Does /var/run/postgresql/.s.PGSQL.5432 exits?
Do you have more then one instance of Postgres on this machine?
If so how where they installed and more importantly where they installed differently?
As a test try running the command with addition of -h localhost.
Note - I am able to create a test db user when I am connected to
postgres using psql command.
Regards,
Atul
--
Adrian Klaver
adrian.klaver@aklaver.com
Atul Kumar <akumar14871@gmail.com> writes: > Just to clarify that I am at root OS user, trying to create a test user > using postgres user(-u) with create user command. Given the reference to /var/run/postgresql, I'm suspecting that you are running a server that thinks it should put its socket in /tmp, but you have some copies of libpq on the machine that were built with default socket location /var/run/postgresql. When you are root, you are very likely using a different PATH that is finding a different createuser program linked to a different libpq.so than when you are not root. A possible workaround is to add "-h /tmp" to your command when running as root. Eventually you'd want to try to not have multiple postgres installations on the machine. regards, tom lane
On 12/1/20 8:10 AM, Atul Kumar wrote: > Hi, > > Just to clarify that I am at root OS user, trying to create a test user > using postgres user(-u) with create user command. No you are not at root for the OS you are at OS user postgres connecting as database user testuser. > > Error screenshots are already shared with you. What I was saying is that the error message as text is better. You can copy and paste from a terminal session. You have not answered the other questions about the status of your Postgres install(s). The suspicion is that you have a mixed install and are having PATH issues. See Tom's response also. > > Please re-check the same. > > > > > > Regards > Atul > > > > On Tuesday, December 1, 2020, Adrian Klaver <adrian.klaver@aklaver.com > <mailto:adrian.klaver@aklaver.com>> wrote: > > On 12/1/20 12:51 AM, Atul Kumar wrote: > > Hi, > > When I m creating a test db user using below command using root > OS user > sudo -u postgres createuser -p 5432 --pwprompt testuser > > I am getting the attached error of port. > > But my postgres services are running fine on port 5432, I am sharing > the screenshot of that also. > > > In future please include this as text not images. > > > So please help me in letting me know why I am getting the above > error > when I am connected to the root OS user? > > > You are not connecting as OS root you are connecting as the database > user testuser. > > Does /var/run/postgresql/.s.PGSQL.5432 exits? > > Do you have more then one instance of Postgres on this machine? > > If so how where they installed and more importantly where they > installed differently? > > As a test try running the command with addition of -h localhost. > > > Note - I am able to create a test db user when I am connected to > postgres using psql command. > > > Regards, > Atul > > > > -- > Adrian Klaver > adrian.klaver@aklaver.com <mailto:adrian.klaver@aklaver.com> > -- Adrian Klaver adrian.klaver@aklaver.com
hi, There is no directory of postgresql in /var/run. Please help me out. Regards, Atul On 12/1/20, Tom Lane <tgl@sss.pgh.pa.us> wrote: > Atul Kumar <akumar14871@gmail.com> writes: >> Just to clarify that I am at root OS user, trying to create a test user >> using postgres user(-u) with create user command. > > Given the reference to /var/run/postgresql, I'm suspecting that you > are running a server that thinks it should put its socket in /tmp, > but you have some copies of libpq on the machine that were built with > default socket location /var/run/postgresql. When you are root, you > are very likely using a different PATH that is finding a different > createuser program linked to a different libpq.so than when you are > not root. > > A possible workaround is to add "-h /tmp" to your command when > running as root. Eventually you'd want to try to not have > multiple postgres installations on the machine. > > regards, tom lane >
On Tuesday, December 1, 2020, Atul Kumar <akumar14871@gmail.com> wrote:
There is no directory of postgresql in /var/run.
Wasn’t expecting there to be, that’s what you get the error.
Please help me out.
Since “su - postgres” works for psql just do that for createuser.
Or do what Tom said and specify -h /tmp in your commands
It might be interesting to see what “which psql” shows in each case; or whether psql works in the sudo -u case.
David J.
Thanks a lot Tom, I appended the -h /tmp and it worked. I need just one more help from you. Could you tell me that why & how that socket file existed in /tmp directory. What is the practice to make sure that this file (.s.PGSQL.5432) should be inside /var/run directory ? so that it will not throw such error. Please help me. Regards, Atul On 12/1/20, Tom Lane <tgl@sss.pgh.pa.us> wrote: > Atul Kumar <akumar14871@gmail.com> writes: >> Just to clarify that I am at root OS user, trying to create a test user >> using postgres user(-u) with create user command. > > Given the reference to /var/run/postgresql, I'm suspecting that you > are running a server that thinks it should put its socket in /tmp, > but you have some copies of libpq on the machine that were built with > default socket location /var/run/postgresql. When you are root, you > are very likely using a different PATH that is finding a different > createuser program linked to a different libpq.so than when you are > not root. > > A possible workaround is to add "-h /tmp" to your command when > running as root. Eventually you'd want to try to not have > multiple postgres installations on the machine. > > regards, tom lane >
You might want to give https://www.postgresql.org/docs/13/runtime-config-connection.html a read regards Andreas Am 12/2/2020 um 8:02 AM schrieb Atul Kumar: > Thanks a lot Tom, I appended the -h /tmp and it worked. > > I need just one more help from you. > > Could you tell me that why & how that socket file existed in /tmp directory. > > What is the practice to make sure that this file (.s.PGSQL.5432) > should be inside /var/run directory ? so that it will not throw such > error. > > Please help me. > > > > > > > Regards, > Atul > > > > On 12/1/20, Tom Lane <tgl@sss.pgh.pa.us> wrote: >> Atul Kumar <akumar14871@gmail.com> writes: >>> Just to clarify that I am at root OS user, trying to create a test user >>> using postgres user(-u) with create user command. >> Given the reference to /var/run/postgresql, I'm suspecting that you >> are running a server that thinks it should put its socket in /tmp, >> but you have some copies of libpq on the machine that were built with >> default socket location /var/run/postgresql. When you are root, you >> are very likely using a different PATH that is finding a different >> createuser program linked to a different libpq.so than when you are >> not root. >> >> A possible workaround is to add "-h /tmp" to your command when >> running as root. Eventually you'd want to try to not have >> multiple postgres installations on the machine. >> >> regards, tom lane >> >
On Wednesday, December 2, 2020, Atul Kumar <akumar14871@gmail.com> wrote:
Thanks a lot Tom, I appended the -h /tmp and it worked.
I need just one more help from you.
Could you tell me that why & how that socket file existed in /tmp directory.
Because the server was configured that way:
See: unix_socket_directories
Thing is, the client code doesn’t read the postgresql.conf configuration file - it just knows its own compile-time default. For some reason, your client in one mode was compiled using a different default than the server on the same machine. From which we infer you have two client installs on your machine, each compiled using different defaults.
David J.
On 12/1/20 11:02 PM, Atul Kumar wrote: > Thanks a lot Tom, I appended the -h /tmp and it worked. > > I need just one more help from you. > > Could you tell me that why & how that socket file existed in /tmp directory. > > What is the practice to make sure that this file (.s.PGSQL.5432) > should be inside /var/run directory ? so that it will not throw such > error. > > Please help me. We have been trying, but you have not provided the information necessary to come up with a solution. So once again: What OS and version? Do you have more then one instance of Postgres on this machine? Where did you get your Postgres code/packages from? > > > > > > > Regards, > Atul > > Adrian Klaver adrian.klaver@aklaver.com