How to open a postgres database created using psql in PgAdmin4? - postgresql

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.

Related

Can't connect to postgres via PSQL or php, only pgAdmin4

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.

Multiple installations of Postgres on Ubuntu

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

Querying hive schema with HAWQ and PXF

I know it's possible to query data managed by Hive with HAWQ, and HCatalog, I have installed Hortonworks ambari that installs all the tools needed. To query the hive i schema followed pivotal instructions where it says to enter PostgreSQL and do the command SET pxf_service_address TO "localhost:51200", but I always get the error unrecognized configuration parameter "pxf_service_address". Does anyone have this problem before?
Your version() output indicates you are connecting to a PostgreSQL instance and this is NOT HAWQ.
The default port for both PostgreSQL and HAWQ is 5432 so on a single node, one has to be changed. I think it is a bug that Hortonworks has decided to change the HAWQ port instead of the PostgreSQL port. So if you want to give some feedback to Hortonworks, tell them to change the PostreSQL port to something other than 5432.
Find hawq_master_address_port in your /usr/local/hawq/etc/hawq-site.xml file. The value will be something other than 5432. You should also look at the hawq_master_address_host value and make sure you are on the Master host. So ssh to your master host to connect via psql.
Now, armed with your HAWQ port and logged in as gpadmin on the Master host, edit your .bashrc file. Add:
export PGPORT=<hawq_master_address_port>
Substitute hawq_master_address_port with the value from hawq-site.xml.
Now source your .bashrc file and then run:
psql template1
I'm also guessing you don't have a gpadmin database so create it.
psql -d template1 -c "create database gpadmin;"
Now you can just run "psql" and connect to HAWQ.

SSH tunnel to postgres from Tableau desktop - invalid username and password

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!

How to connect to postgres with two terminals?

I have a terminal I can connect to postgres
psql testdb
but when I open a new tab or a new terminal and tried to connect to psql an error is returned
This error returns
psql: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/pgsql_socket/.s.PGSQL.5433"?
I tried creating another user and using another port
createuser testing_multiple
psql -p 5433
the same error occurs.
Your issue is probably that you're working within virtualenv. It isn't a chroot, but it sets a bunch of environment variables to fake the local environment, quite likely including the PATH and other settings.
Most likely the unix socket is at a different location to that compiled into the psql binary you're using. I'd say your PostgreSQL server socket is probably actually at /tmp/.s.PGSQL.5433, in which case export PGHOST=/tmp/ will work. Since you can connect from within the virtualenv terminal you can check though - within psql, run SHOW unix_socket_directories;. The location shown there is what you can give in PGHOST to connect to that PostgreSQL server.
The reason that export PGHOST=localhost works is that you are forcing psql (and other clients that use libpq) to connect over TCP/IP, instead of the default unix socket connection.