I have PostgreSQL 12 installed and using Windows 10. My goal is to connect to postgre via php, because it didn't work I tried with plsql but it didn't work either, i always get (with both plsql and php using PDO):
FATAL: password authentication failed for user "postgres"
Connection via plsql in cmd
However, when trying via pgAdmin4, I can connect and access my databases. I first use my root password then sometime my postgres user one, so I'm sure my password works.
Here is my pg_hba.conf file:
pg_hba.conf file
I have a set password for postgres which was set vua pgAdmin4.
I don't understand why it would work one way and not the other, can anyone help me?
So after trying several things, I found that plsql and php error was due to the wrong port being adressed.
By default 5432 is used, but for some reason my configuration was using 5433.
You can find this information in pgAdmin4 by opening PostgreSQL 12 properties, and then checking in connection tab.
To change the used port in plsql I used:
psql -U postgres -p 5433
Change 5433 by your configured port if you have same issue, you also need to specify the port if using php's PDO.
Related
I have 2 versions of postgresql running on Suse SLES, 9.6 and 10.7. The 9.6 version is running on port 5432, and 10.7 is running on port 5433. All the executables for each version are in the directory for that version, including psql.
If I execute the default psql, I get psql for version 9.6.3:
psql (9.6.3)
However, when I try to execute psql for version 10.7:
/usr/pgsql-10/bin/psql
it opens the version for 10.7, but reading from postgresql 9.6.3:
psql (10.7, Server 9.6.3).
If I try to give it the port number for 10.7:
/usr/pgsql-10/bin/psql -p 5433
it demands a password, but rejects the password for the user postgres that I know works in other contexts.
I have spent considerable time searching for an answer to this question, and I am sorry I have not found anything helpful. Thanks for any suggestions!
There are two issues in play here.
1)
I su to postgres: su - postgres This requires a password, and the password that works here, does not work when psql wants/demands a password.
The OS postgres user is not the same as the database postgres user.
On a fresh install the database postgres user does not have a password. Generally speaking the auth method for the user is set to either trust, ident or peer. See here pg_hba.conf what they mean. The key to a solution is to modify the pg_hba.conf to allow the user to connect in order to be able to create a password. The easiest way is to set a connection method, best practice local(socket) to trust. Then you can connect without a password and create one.
I installed PostgreSQL 13.2 on Windows. The service is running, but when I use psql -Upostgres to connect it always fails password authentication even though I am entering the right password. I read that if you set the METHOD to trust in pg_hba.conf then it shouldn't even ask for passwords. I did that and then restarted the service--it still asks for the password and fails.
I've run out of ideas on what to try, so I thought I'd try here. Any thoughts?
The problem was that a docker container was running that was using port 5432 so postgres was using port 5433. I had thought that the docker container was stopped, so I had put it completely out of my mind. When I used psql without specifying a port, it was attempting to connect to the db running in the docker container, which had a different password for the user postgres. (This also explained why changing METHOD to trust in pg_hba.conf didn't work: it was the wrong instance of postgres that I was connecting to.)
How do I open a postgres database created using psql (i.e. in the terminal) in PgAdmin4 and vice versa?
I also noticed that the localhost port for psql is 5432 and for PgAdmin4 is 5433.
Is this correct?
Some background is in order. When you install Postgres you create an instance of a server that comes with three databases already created; template0, template1 and postgres. On a given machine you can create more then one Postgres server/instance and have them run simultaneously. In order for that to happen though each server needs to listen on a different port. The default port is the 5432 you mention above. It would seem you also have another server running on port 5433. I'm guessing what you want to know is about connecting to a given server rather then a database in that server. In that case it is important to know that Postgres works on the server/client model where it is the server and in your case psql and pgAdmin are the clients. What this means is that a Postgres server is not tied to a client, it exists on its own. It also means a client can connect to any Postgres server it can reach, assuming it is using the correct credentials. All of the previous means, yes you can connect psql and/or pgAdmin to either server. For psql specify the correct port using -p. For pgAdmin you will need to set up a server using the server dialog Dialog. Then use the appropriate port in the connection tab.
This is the first time I am setting up multiple Postgres postgres servers on Ubuntu 12.04LTS. (I know multiple versions is a bad idea, but need to sanity check new installation before I migrate and kill the old instance)
Original Postgres V9.1 is installed using bundled apt-get install. (Port : 5432)
New Postgres V10 is installed via EnterpriseDB package. (Port : 5433)
I am able to use standard utilities for the V9.1 like psql, pg_dump, etc. However, I am not able to access psql of V10. Instead I am getting this error message (note the incorrect port):
/opt/PostgreSQL/10/bin$ ./psqlpsql.bin: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
I would like to be able to manage both ideally by using psql.
I usually use Python to connect to databases and I am able to create an SQLAlchemy connection to new instance at port 5433. I can query pg_catalog and information_schema as well.
Thanks in advance!
The default port of postgres is 5432.
So If you want to access psql of V10, use the below commands:
export PATH=/opt/PostgreSQL/10/bin:$PATH
psql -p 5433
I am trying to connect Tableau to a postgres DB using a SSH tunnel. The steps I have taken are
Install postgres drivers (32 bit) on my desktop
Create the tunnel in putty (tunnel L5432 127.0.0.1:5432) and open up the terminal
From this session I can run Postgres from the command line psql -d mydb -U myuser
However, when trying to connect using Tableau I get the error message "Invalid username and Password"
If I try to connect to a DB that doesn't exists I get the same error message "Invalid username and Password"
I have also created a psql user with superuser privileges but no success. Note that the username for the ssh tunnel and the psql db are different.
I have seen a number of posts on the forum with no solution.
Can anyone help? Thanks.
Roger
I met with the same question, with slight difference, I didn't use PuTTY but instead using Cygwin Autossh.
The answer is that two tunnels need to be built, first an ssh tunnel from local host to server, and then from the server port to the database port. A possible solution is to set up ssh tunnel like this:
5432:localhost:5432 username#hostserverdomain
The first 5432 is the local port(Tableau or PGAdmin), the second localhost actually refers to the server(cuz once log in localhost means the server itself), the second 5432 is the database on the server. And in order to get access to the database, one has to log in the server.
The above is just the syntax to connect thru two tunnels using ssh.
At first I didn't understand what Roger means by two tunnels, and then I look into the underlying methodology and finally got all the setup work done. Thanks Roger!