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
Related
I have followed the steps from here. I successfuly installed both postgres#12.8 in WSL2 and PGAdmin4 on Windows.
Once I start service in WSL and create a server connection in pgAdmin I am not able to see any databases create from the pgAdmin GUI or neither from psql client.
I tried to:
set env variable PGHOST to localhost
editing postgresql.conf to listen_addresses = 'localhost'
connecting pgAdmin server by localhost name and by IP 127.0.0.1
nothing works..
I just ran into the same issue.
If you try to access your DB installed with pgAdmin from WSL 2, make sure you didnt install postgreSQL from Windows, as sudo service postgresql start from WSL will also start the only postgresql service you need.
Basically, it means you need to install postgresql ( sudo apt-get install postgresql) and start it FROM WSL, and then just open pgAdmin from Windows. Do NOT install postgresql directly on Windows as then your pgAdmin might create your DBs into the postgresql service started in Windows and not from the one started from WSL.
Make also sure that pgAdmin is installed for the same user that your WSL 2 uses, if you use it from VSCode for example. Otherwise, for the same reason, your WSL may not be able to find the corresponding DB.
Note that you can list the DB existing on a specific port by running psql -p 5432 -l from WSL ( change 5432 by the port you want to use ).
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.
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.
I have this problem trying to connect to the local postrgres databases. Until now i succeeded to connect to the same databases using jdbc or working directly in PGAdmin, this error happens when i try to connect using pqxx library or from shell:
pqxx code:
#include <pqxx/connection.hxx>
int main(){
pqxx::connection conn("user=postgres port=5432 dbname=pqxx-test password=postgres");
return 0;
}
or from shell, as user postgres:
psql pqxx-test
both the cases raise this error:
could not connect to server: No such file or directory Is the server
running locally and accepting connections on Unix domain socket
"/var/run/postgresql/.s.PGSQL.5432"
Searching for the solution i think i understood i have to edit pq_hba.conf and postgresql.conf files in order to connect in these ways, but in pg_hba.conf is already set:
local all all md5
and in postgresql.conf
listen_addresses='*'
And by the way, i'm not even able to edit these files because of a problem with the viminfo, but maybe this is another problem..
Can anyone help me?
edit:
using PostgreSQL 9.6.2
on Ubuntu 14.04
edit:
as postgres user, if i ask for the postgre version using:
psql -V
the result is 9.6.2
but looking at the file system hierarchy, all conf file are inside this folder
/opt/PostreSQL/9.4/data/
can that be the problem?
You seem to have a mix of client-side postgresql 9.6 configured for the ubuntu FS layout and a postgresql server 9.4 presumably downloaded from EntrepriseDB (and installed under /opt/PostgreSQL) using its own layout.
Assuming that the postgresql is running, the simplest solution is to add host=localhost to your connection string, so that it will use a TCP connection instead of the Unix domain socket /var/run/postgresql/.s.PGSQL.5432 that does not exist because of the mismatch.
I am attempting to use a Zabbix server running on an Ubuntu virtual machine to monitor the Postgres database in our application running on the same host machine (not a VM). To be clear, I am trying to connect from a Linux Ubuntu virtual machine on my computer to Postgres also running not in a VM on the same computer. Zabbix makes use of ODBC, so a preliminary step in the process is to get the ODBC connection to Postgres working correctly. However, I am having a problem.
Steps I have taken:
installed unixODBC via sudo apt-get install unixodbc unixodbc-dev
installed unixODBC driver for Postgres via sudo apt-get install odbc-postgresql
configured odbc.ini to the following:
[test]
Description = test database
Driver = /usr/lib/x86_64-linux-gnu/odbc/psqlodbca.so
Setup = /usr/lib/x86_64-linux-gnu/odbc/libodbcpsqlS.so
Server = 192.168.240.1
User = postgres
Password =
Port = 5432
Database = mydb
Yet when I test the connection via:
isql test -v
I get the following error:
[08001][unixODBC]could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
More notes:
I can successfully connect to Postgres from the admin running on the local (non VM) machine
port 5432 has been completely opened from Windows Firewall on the local machine
telnet to 192.168.240.1 (the network IP of the local machine) on port 5432 succeeds
This all implies that the problem has to do with the ODBC configuration in the Ubuntu VM. I spent several hours searching and trying various things but to no avail. If I can get isql to work correctly, I should be in business, as Zabbix basically sits right on top of ODBC for its database monitoring functions.
Thanks in advance for your help.
I think your configuration options are a little off. Try this:
[test]
Driver = /usr/lib/x86_64-linux-gnu/odbc/psqlodbca.so
Setup = /usr/lib/x86_64-linux-gnu/odbc/libodbcpsqlS.so
Database = mydb
Servername = 192.168.240.1
UserName = postgres
Password =
Port = 5432
Protocol = 7.4
Using Servername instead of Server might be sufficient.
I'd recommend the following steps to getting ODBC and PostgreSQL to play together (ignoring the apt install steps, since you already did these):
sudo odbcinst -i -d -f /usr/share/psqlodbc/odbcinst.ini.template
sudo odbcinst -i -s -l -n test -f /usr/share/doc/odbc-postgresql/examples/odbc.ini.template
sudo nano /etc/odbc.ini
Here's what these do:
Sets up your odbcinst.ini file with the files in the right places.
Sets up your odbc.ini file (for the system).
Edits the system odbc.ini file you created in step 2, where you can replace options to match your needs.
If you do not want the odbc.ini file to be system-wide, you can also limit it to just the user if you call step #2 without the -l parameter. In that case, it'll create or modify a ~/.odbc.ini file, which you can edit for your needs.
The unixODBC folks seem to recommend using odbcinst for setting this stuff up, as it knows where to put the files. Unfortunately, to use it to great effect, you'd need to know where to find the drivers' template files for your driver. The paths I've provided here match the ones for the Ubuntu package.