Unable to connect postgres DB remotely - postgresql

Every time, when I try to connect to remote Postgres DB, I receive error:
no pg_hba.conf entry for host "159.224.92.121", user "xpkzxqrkisdrjd", database "d92na0gp4bdq4", SSL off
I googled it and found that two config files should be updated.
Should append:
pg_hba.conf
host all all 0.0.0.0/0 md5
postgresql.conf
listen_addresses = '*'
I did it, but error still occurs, when I try to connect to remote DB.
Local DB work fine.
Any ideas?
UPDATE
Maybe it will be useful. I have installed postgres using homebrew.
For restarting postgres server I use:
brew services postgres restart

Two items to help you on the way:
pg_hba.conf is processed from top to bottom, so if the incoming connection matches an earlier line, that entry will be used.
Set log_connections = on in postgresql.conf and reload. Then, after a connection attempt has failed, look into the log file for the reason. Recent PostgreSQL versions will also tell you which pg_hba.conf line was used.

So, I continued to google this issue and finally found the answer. You should use SSL option.
Please, check this link:
https://intellij-support.jetbrains.com/hc/en-us/community/posts/205996299/comments/206373089

Related

Can't connect to postgresql "Role does not exist"

I'm trying to connect to postgresql from a docker container but I get following error:
2019-03-02 20:10:45.218 MSK [2777] spectrum_user#spectrum_db FATAL: password authentication failed for user "spectrum_user"
2019-03-02 20:10:45.218 MSK [2777] spectrum_user#spectrum_db DETAIL: Role "spectrum_user" does not exist.
Connection matched pg_hba.conf line 100: "host all all 172.17.0.0/16 md5"
Looks like it successfully connects but fails to authenticate. And I don't have idea why. I can connect to db with psql. This role definitely exists.
I'm using Ubuntu 18.04 LTS
Does anyone have suggestions?
UPDATE: It appeared that I had two versions of postgresql running simultaneously and I tried to connect to wrong postgresql instance.
It appeared that I had two versions of postgresql running simultaneously and I tried to connect to wrong postgresql instance.
You'll need to edit the pg_hba.conf.
On my install of Ubuntu 18.04 this is the path:
/etc/postgresql/10/main/pg_hba.conf
You can try:
sudo vim /etc/postgresql/10/main/pg_hba.conf
replace vim with your choice of text editor. If a file doesn't open with this command (a file that already has settings in it) then you'll need to explore around /etc/postgresql to find the pg_hba.conf file. Try:
find -name pg_hba.conf
Once you find and open the file, edit the following lines:
Under the comment # IPv4 local connections:
host all all 172.17.0.1/24 trust
Now you'll need to edit one more file:
sudo vim /etc/postgresql/10/main/postgresql.conf
Change any reference of listen_addresses to:
listen_addresses = '*'
After you've saved all the above changes, run this command:
sudo service postgresql restart
Note: this configuration isn't secure for a production environment, and you would need to configure your firewall and change some of these settings to make it secure. This is for development only.
Now, as long as you're pointing at your host OS's IP address for your postgres URL and the user exists on the system and the role exists in the database, you'll be able to connect to the host database from the docker container. I also always bind an HTTP port, so this may come into play. I'd need to see your docker file to give any information on that.
You also need to allow the port on your firewall:
sudo ufw allow from 172.17.0.1/24 to any port 5432
If you don't care about security and the above still doesn't work, just open port 5432. Be aware that opening a port can be unsafe.

Disable authentication in postgres entirely

I've installed postgres 10 under Ubuntu, and trying to perform an import from the command line like:
psql -f dump.sql -U postgres -d dbname
The operation fails with the message:
psql: FATAL: Peer authentication failed for user "postgres"
I read I should edit the pg_hba.conf file. The problem starts here, because I don't have any pg_hba.conf file on my system. The only similar file I have found is /usr/share/postgresql/10/pg_hba.conf.sample but it doesn't contain any code, just comments.
So what I did was create a pg_hba.conf in this same directory with the contents:
local all all trust
# IPv4 local connections:
host all all 127.0.0.1/32 trust
# IPv6 local connections:
host all all ::1/128 trust
I also put the same into pg_hba.conf.sample (although I don't think this file is used anyhow but anyways..)
Then, I restarted the server with:
sudo service postgresql restart
Nothing changed, I'm getting the same error.
Then, I tried all possible combinations in pg_hba.conf, from 'trust' to 'md5', 'localhost', 127.0.0.1, anything I could find on the internet. Even created new users and tried with those, also installed pgadmin to grant all access to all users to every database.... Restarted the OS, reinstalled postgres, tried everything again and again..
The problem still persist.
Anything else I could try? Is there a way to disable the authentication entirely?
It's meant to be a database for local testing purposes only, and I've been trying for three hours just to get it to work.

Openbravo - Connecting pgadmin with postgresql database in Ubuntu

I have installed Openbravo ERP 3.0 in Ubuntu 12.04(LTS). After completed the installation I tried to connect with postgresql database using pgadmin 9.1. I gave all the details as mentioned in this link: http://wiki.openbravo.com/wiki/Installation/Appliance/Openbravo.
Also I have changed the config file settings like listen_addresses="*". I got this error after I click "Ok" button
Could anyone give suggestion to fix this error? Thanks in advance.
Actually the problem comes because of not mentioning the local cluster or data area for PostgreSQL. To do this after installing Openbravo, need to give this command in terminal
psql -d openbravo -U tad -h localhost -p 5932
Finally give the PostgreSQL configuration details as mentioned in this link
It works fine now...
To be able to reach the server remotely you have to add the following line into the file: /var/lib/pgsql/data/postgresql.conf:
listen_addresses = '*'
PostgreSQL, by default, refuses all connections it receives from any remote address. You have to relax these rules by adding this line to /var/lib/pgsql/data/pg_hba.conf:
host all all 0.0.0.0/0 md5
This is an access control rule that lets anyone login from any address if a valid password is provided (the md5 keyword). You can use your network/mask instead of 0.0.0.0/0 to only allow access from certain IP addresses.
When you have applied these modifications to your configuration files, you will need to restart the PostgreSQL server.
/etc/init.d/postgresql start
Now, you will be able to login to your server remotely

Postgres and Atlassian Jira: driver issue

I am trying to setup a server with centOS 32 bit to install Atlassian Jira on it.
I followed the official Atlassian installation guide at https://confluence.atlassian.com/display/JIRA/Installing+JIRA
Now I am running the Setup Wizard and I need to configure a PostgreSQL database. On my centOS, I installed version 8.4.20 via yum.
However, I am having a hard time setting Jira. Postgres is running and I can login via Linux console, but when I test the connection to the database, I get the following error:
Error connecting to database
Connection refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
Connection refused
Also, this error appears when I type the full public IP address. If I insert localhost, I get this:
Error connecting to database
FATAL: Ident authentication failed for user "jiradbuser"
If I insert
http://<public ip>
I get the following:
Error connecting to database
No suitable driver found for jdbc:postgresql://http://<public ip>:5432/jiradb
However, I put my jdbc driver into /opt/atlassian/jira/lib and its name is postgresql-8.4-703.jdbc4.jar. Postgresql version is 8.4.20.
Where am I doing wrong?
Connection refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
By default, PostgreSQL listens only on the local loopback interface, so connecting to the public IP won't work. If you're connecting from localhost you don't need to anyway, just use localhost.
FATAL: Ident authentication failed for user "jiradbuser"
This is good, it shows that you're connecting to PostgreSQL successfully, then getting an authentication error when trying to log in.
Your PostgreSQL server install defaulted to ident authentication for TCP/IP connections, but the JIRA application isn't running under a unix user named "jiradbuser" so the connection is rejected. Change pg_hba.conf to use md5 instead of ident and set a password for the user. See the client authentication chapter in the docs, particularly, pg_hba.conf.
No suitable driver found for jdbc:postgresql://http://:5432/jiradb
I have no idea where you got the idea that that URL would work...
You want something like:
jdbc:postgresql://localhost:5432/jiradb
I had the same problem. I could solve it setting up the postgres driver .jar from maven repository to \target\jira\webapp\WEB-INF\lib\
Pretty late to the question here but thought I'd add a couple bits to help out the future, going backwards:
No suitable driver found for jdbc
A while ago Atlassian didn't distribute the PostGreSQL JDBC driver file with the JIRA releases. They have been doing this for a while now (I'd say since mid 2013) - regardless, the driver file belongs in the <jira-base>/lib directory unless you are doing a WAR install, in which case you shouldn't, and just put the driver file in the lib directory anyway
FATAL: Ident authentication failed for user "jiradbuser"
1. Listen on a socket if you need to - The best approach to this is to look at your JDBC driver URL - if it has an IP/hostname other than 127.x.x.x or 'localhost' you need to modify PostGreSQL to listen to a TCP port by modifying your postgresql.conf file to enable listening on ports. Just find the file, back it up, then open it and search for localhost, read the file comments and make the correct change. If you find yourself looking around in multiple locations in the file or changing more than a single word you are trying too hard - restore your backup and try again. Just remember to *stop* and *start* your postgres db cluster when you are done
2. enable the correct login METHOD in pg_hba.conf (same directory as the postgresql.conf file - on unix typically under /etc/postgresql/<version>/main/.) - this is difficult to writeup in brief but I'll try
1. backup the pg_hba.conf file - I ain't foolin, this is something you'll be happy with later - back the sucker up
2. edit the file
3. go to the bottom of the file - look for the last line like "# TYPE DATABASE USER ADDRESS METHOD"
4. comment out every line under this 'table heading' line
- the reason to do this is that the package maintainers often fall back to commenting here and so you'll have 2 commented out lines and then one line that isn't commented out - and you'll never notice it - it's easiest to just start off with commenting out the whole block of stuff so there isn't a single uncommented line in the file
- add a two lines for the postgres user to connect local and to a db socket unless your corporate security does not allow - something like this:
local all postgres 127.0.0.1/32 peer
host all postgres 127.0.0.1/32 trust
- add a line for your jiradbuser to connect to the newly created database via sockets with md5 encryption. md5 isn't the best - there are other options to google - if you use md5, it'd look something like this:
host jiraversiondb jiradbuser 127.0.0.1/32 md5
Then save the file, restart postgres cluster (with a stop and start, not with the 'restart' option), and test connecting from the command line.
How to test connections from the command line
If you are logged into a unix system with the postgres tools installed you should be able to mimic the connection attempt which the JIRA server will try to connect to the database. If you cannot connect to the new postgresql db from the command line it's a REAL GOOD chance that JIRA won't be able to either. Plus you'll get better error messages. So to do this just bring up a shell and enter (replacing variables where appropriate - things within the '<' and '>' characters) - all the values for these are in your head and the postgresql.conf file:
psql --port <port - default is 5434> --username=<db user name> --password --dbname=<database name>
Once you can connect from the command line it's a good bet JIRA will as well - no promises, but you'll be on sound footing.
...ahhh....now, that'll hopefully help someone...

PostgreSQL: Access to database denied

I'm using PostgreSQL 9.1 on an Ubuntu 12.04 server. The database instance seems to run fine in general and when I try and connect from pgAdmin III via localhost on the server machine itself, there is no problem.
Whenever I try to use the LAN address 192.168.1.16 from the server, I get the error "Access to database denied."
From what I gather, the common culprit in these sorts of situations seems to be the configuration described in the pg_hba.conf file, which currently contains the following:
host all all 192.168.0.1/32 md5
As far as I understand, the instance should accept all users. Is there anything I'm missing here?
Note that you are trying to connect from 192.168.1.16, however, your pg_hba.conf is allowing only 192.168.0.1 (that's what the /32 means).
Check https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing#IPv4_CIDR_blocks to learn more about CIDR notation.
If you want to allow 192.168.1.16 only you can add the following line at your pg_hba.conf:
host all all 192.168.0.16/32 md5
Then, run pg_ctl reload to apply the change made above.
This answer is assuming that you have verified the listen_address parameter in your postgresql.conf file and it's binding the correct IP values.