postgres not using postgres.conf file? - postgresql

I have a postgres setup on my ubuntu 18.04 server.
I have changed the listen_addresses property to '*' but it doesn't seem like the postgres server is following this.
currently the first part of the file:
# - Connection Settings -
listen_addresses = '*' # what IP address(es) to listen on;
# comma-separated list of addresses;
# defaults to 'localhost'; use '*' for all
# (change requires restart)
port = 5432 # (change requires restart)
max_connections = 100 # (change requires restart)
#superuser_reserved_connections = 3 # (change requires restart)
unix_socket_directories = '/var/run/postgresql' # comma-separated list of directories
# (change requires restart)
#unix_socket_group = '' # (change requires restart)
#unix_socket_permissions = 0777 # begin with 0 to use octal notation
# (change requires restart)
#bonjour = off # advertise server via Bonjour
# (change requires restart)
#bonjour_name = '' # defaults to the computer name
# (change requires restart)
As a test, I changed the port setting to a different port and restarted the postgres server and psql stopped being able to connect to the running server so it seems like the psql command is following the config file but the server itself isnt?
How can I debug this issue?
I have tried to use psql -U postgres -c 'SHOW config_file' but it just shows the config file that I have edited?
at the end of the file is:
include_dir = 'conf.d' # include files ending in '.conf' from
# a directory, e.g., 'conf.d'
but this conf.d folder is empty

There are two changes you need to make to enable PostgreSQL to accept remote connections:
First is exactly what you've done, modify listen_addresses in /etc/postgresql/<VERSION>/main/postgresql.conf to listen on all interfaces:
listen_addresses = '*'
Second, you need to modify /etc/postgresql/<VERSION>/main/pg_hba.conf to allow remote connections. If you look at a default pg_hba.conf you will have a line that looks like this:
host all all 127.0.0.1/32 md5
That 127.0.0.1/32 is keeping PostgreSQL from accepting remote connections, so let's change it:
host all all 0.0.0.0/0 md5
Restart the PostgreSQL database after making these two changes and you should be able to connect to it from a remote computer.
If you're still having issues connecting to the database remotely I'd check firewalls like iptables, etc.

Related

Not able to run postgres, even if `service postgresql status` says it's active

I have installed postgresql 13
with following conf
pg_hba.conf
# Database administrative login by Unix domain socket
local all postgres trust
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all trust
# IPv4 local connections:
host all all 0.0.0.0/0 trust
# IPv6 local connections:
host all all ::0/00 trust
postgresql.conf
#listen_addresses = '*' # what IP address(es) to listen on;
# comma-separated list of addresses;
# defaults to 'localhost'; use '*' for all
# (change requires restart)
port = 5432 # (change requires restart)
max_connections = 100 # (change requires restart)
#superuser_reserved_connections = 3 # (change requires restart)
unix_socket_directories = '/var/run/postgresql' # comma-separated list of directories
when I run service postgresql status, I get
when I do sudo su postgres and psql , I get

I am having trouble connecting my remote postgres service to pg_admin.Tried all possible way still failing

I want to connect my remote postgres service which is on a VM to my desktop pg_admin, but I am getting the same error again and again. I saw many people have the same issue and the solutions provided on stackoverflow is not helping me.
As of now these are the configurations I have made in postgres conf file and pg_hba.conf file.
pg_hba.conf :
# If you want to allow non-local connections, you need to add more
# "host" records. In that case you will also need to make PostgreSQL
# listen on a non-local interface via the listen_addresses
# configuration parameter, or via the -i or -h command line switches.
host replication replication master_ip/24 md5
host all all 0.0.0.0/0 md5
# DO NOT DISABLE!
# If you change this first entry you will need to make sure that the
# database superuser can access the database using some other method.
# Noninteractive access to all databases is required during automatic
# maintenance (custom daily cronjobs, replication, and similar tasks).
#
# Database administrative login by Unix domain socket
local all postgres trust
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all trust
# IPv4 local connections:
host all all my_ip/32 md5
host all all 127.0.0.1/32 md5
# IPv6 local connections:
host all all ::1/128 md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
local replication all peer
host replication all 127.0.0.1/32 md5
host replication all ::1/128 md5
host all all my_ip/32 md5
host all all ::/0 md5
host all all 0.0.0.0/0 md5
postgresql.conf :
#------------------------------------------------------------------------------
# CONNECTIONS AND AUTHENTICATION
#------------------------------------------------------------------------------
# - Connection Settings -
listen_addresses = '*' # what IP address(es) to listen on;
# comma-separated list of addresses;
# defaults to 'localhost'; use '*' for all
# (change requires restart)
port = 5432 # (change requires restart)
max_connections = 100 # (change requires restart)
#superuser_reserved_connections = 3 # (change requires restart)
unix_socket_directories = '/var/run/postgresql' # comma-separated list of directories
# (change requires restart)
#unix_socket_group = '' # (change requires restart)
#unix_socket_permissions = 0777 # begin with 0 to use octal notation
# (change requires restart)
#bonjour = off # advertise server via Bonjour
# (change requires restart)
#bonjour_name = '' # defaults to the computer name
# (change requires restart)
pg_admin connection window :
Error that I get while connecting :
let me know what can be the possible issue for this, I have tried adding entry on pg_hba.conf and listen_port is allowd "*".
If any other info is needed please comment. There are many similar questions but that didn't help that's why adding the question.

Trying to allow postgresql to be accessed remotely always timeout expired

i tried to "enable" my postgresql13 to be accessed remotely.
So i tried to connect via pgadmin4 and it always said :
Unable to connect to server:
timeout expired
The ip when i check with command
ip a
it gave me
192.168.xxx.xxx/24
have tried both using with "/24" and without it
this is my pg_hba.conf
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all peer
# IPv4 local connections:
host all all 127.0.0.1/32 scram-sha-256
# IPv6 local connections:
host all all ::1/128 scram-sha-256
# Allow replication connections from localhost, by a user with the
# replication privilege.
local replication all peer
host replication all 127.0.0.1/32 scram-sha-256
host replication all ::1/128 scram-sha-256
host all all all md5
this is my postgresql.conf
# - Connection Settings -
#listen_addresses = '*' # what IP address(es) to listen on;
# comma-separated list of addresses;
# defaults to 'localhost'; use '*' for all
# (change requires restart)
#port = 5435 # (change requires restart)
max_connections = 100 # (change requires restart)
#superuser_reserved_connections = 3 # (change requires restart)
#unix_socket_directories = '/var/run/postgresql, /tmp' # comma-separated list of directories
# (change requires restart)
#unix_socket_group = '' # (change requires restart)
#unix_socket_permissions = 0777 # begin with 0 to use octal notation
# (change requires restart)
#bonjour = off # advertise server via Bonjour
# (change requires restart)
#bonjour_name = '' # defaults to the computer name
# (change requires restart)
I've already read from multiple sources here and there, change the listen addresses to become '*', and if wanted to change port, change it in the postgresql.conf port=desiredport
Am i missing something?
this is what i enter in the pgadmin4

pgadmin4 unable to connect to server,FATAL: password authentication failed for user "postgres"

i tried to config postgresql to be able to connect to pgadmin4 "remotely"
So i installed postgresql version 13 in the server ,and i tried to access it via my laptop.
But why do i always get an error , i just changed the password and i enter the username and password in the pgadmin4 ,it still says password authentication.
image1
this is my pghba.conf file.
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all trust
# IPv4 local connections:
host all all 127.0.0.1/32 trust
host all all 0.0.0.0/0 trust
# IPv6 local connections:
host all all ::1/128 trust
# Allow replication connections from localhost, by a user with the
# replication privilege.
local replication all peer
host replication all 127.0.0.1/32 trust
host replication all ::1/128 trust
this is my postgesql.conf file
listen_addresses = '*'
# comma-separated list of addresses;
# defaults to 'localhost'; use '*' for all
# (change requires restart)
port = 5434 # (change requires restart)
max_connections = 100 # (change requires restart)
#superuser_reserved_connections = 3 # (change requires restart)
#unix_socket_directories = '/var/run/postgresql, /tmp' # comma-separated list of directories
# (change requires restart)
#unix_socket_group = '' # (change requires restart)
#unix_socket_permissions = 0777 # begin with 0 to use octal notation
# (change requires restart)
#bonjour = off # advertise server via Bonjour
# (change requires restart)
#bonjour_name = '' # defaults to the computer name
# (change requires restart)
# - TCP settings -
# see "man tcp" for details
#tcp_keepalives_idle = 0 # TCP_KEEPIDLE, in seconds;
# 0 selects the system default
#tcp_keepalives_interval = 0 # TCP_KEEPINTVL, in seconds;
# 0 selects the system default
#tcp_keepalives_count = 0 # TCP_KEEPCNT;
# 0 selects the system default
#tcp_user_timeout = 0 # TCP_USER_TIMEOUT, in milliseconds;
# 0 selects the system default
# - Authentication -
#authentication_timeout = 1min # 1s-600s
password_encryption = scram-sha-256 # md5 or scram-sha-256
#db_user_namespace = off
# GSSAPI using Kerberos
#krb_server_keyfile = 'FILE:${sysconfdir}/krb5.keytab'
#krb_caseins_users = off
and still i don't know why, maybe someone experienced the same ? or have any idea?
fyi : i open the pgadmin4 application and the url going to this :http://127.0.0.1:60888/browser/
this is my pgadmin4 in browser
On image1 you changed the password for Postgres linux user, not for Postgres database user. Try next:
sudo -u postgres psql postgres # connect to Postgres
\password postgres # change password postgres user
\q # quite from Postgres shell
Then try to connect to Postgres again.
Would be helpful: https://docs.boundlessgeo.com/suite/1.1.1/dataadmin/pgGettingStarted/firstconnect.html
I solved it after changing in the pg_hba.conf
from
local all all trust
to become
host all all trust
Now it works like a charm.. Thankyou everyone! :)

Connecting to a Postgresql database running on host OS

i am running a postgresql instance in my host machine (Mac OS). I am able to access this instance by JDBC using localhost property in my Spring Boot application
Now i have a guest Ubuntu Virtual Box OS installed. and i want to install the same instance from this OS.
So i just changed the data source url of the same application from localhost to the host ip and port .
But now when i deploy the application and try to run it, i get "connection refused" error.
Telnet to host os from guest OS (10.0.2.2 5432) is working fine.
Content from my pg_hba.conf file
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all md5
# IPv4 local connections:
host all all 127.0.0.1/32 md5
# IPv6 local connections:
host all all ::1/128 md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
#local replication postgres md5
#host replication postgres 127.0.0.1/32 md5
#host replication postgres ::1/128 md5
host all all 0.0.0.0/0 md5
host all all ::/0 md5
Connections and authentications content from my postgresql.conf
#------------------------------------------------------------------------------
# CONNECTIONS AND AUTHENTICATION
#------------------------------------------------------------------------------
# - Connection Settings -
listen_addresses = '*' # what IP address(es) to listen on;
# comma-separated list of addresses;
# defaults to 'localhost'; use '*' for all
# (change requires restart)
port = 5432 # (change requires restart)
max_connections = 100 # (change requires restart)
#superuser_reserved_connections = 3 # (change requires restart)
#unix_socket_directories = '/tmp' # comma-separated list of directories
# (change requires restart)
#unix_socket_group = '' # (change requires restart)
#unix_socket_permissions = 0777 # begin with 0 to use octal notation
# (change requires restart)
#bonjour = off # advertise server via Bonjour
# (change requires restart)
#bonjour_name = '' # defaults to the computer name
# (change requires restart)
So i have configured my postgrsql instance to accept connections from any IP.
i am behind a firewall.
Probably i am still missing somethings
Best Regards,
Saurav
This was a problem with my configuration of Spring Boot and Cloud Foundry..it was nowhere related to Postgresql.
Curious readers please head over to No unique service maching interface error in Spring Boot Cloud Foundry error for the solution