Loss of access to the database after restarting vm - postgresql

I have this database in a VM, could restart the VM and it could access correctly
But now if I restart the VM when trying to access the DB by pgAdmin III I get the message below
Server doesn't listen
The server doesn't accept connections: the connection library reports
could not connect to server: Connection refused Is the server running on host "127.0.0.1" and accepting TCP/IP connections on port 5432?
If you encounter this message, please check if the server you're
trying to contact is actually running PostgreSQL on the given port.
Test if you have network connectivity from your client to the server
host using ping or equivalent tools. Is your network / VPN / SSH
tunnel / firewall configured correctly?
For security reasons, PostgreSQL does not listen on all available
IP addresses on the server machine initially. In order to access the
server over the network, you need to enable listening on the address
first. For PostgreSQL servers starting with version 8.0, this is
controlled using the "listen_addresses" parameter in the
postgresql.conf file. Here, you can enter a list of IP addresses the
server should listen on, or simply use '*' to listen on all available
IP addresses. For earlier servers (Version 7.3 or 7.4), you'll need to
set the "tcpip_socket" parameter to 'true'.
You can use the postgresql.conf editor that is built into pgAdmin III
to edit the postgresql.conf configuration file. After changing this
file, you need to restart the server process to make the setting
effective.
If you double-checked your configuration but still get this error
message, it's still unlikely that you encounter a fatal PostgreSQL
misbehaviour. You probably have some low level network connectivity
problems (e.g. firewall configuration). Please check this thoroughly
before reporting a bug to the PostgreSQL community.
I did some testing through VM snapshots and noticed that the behavior occurs after the command
sudo a2enmod rewrite
But I did not find anything that could indicate some link or how to solve, since I need to run sudo a2enmod rewrite
postgresql.conf connection settings:
# - 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)
I already tried to restart the postgres service, and it did not work

This is part of my general procedure for debugging access to any database.
Basic tests
Intended to determine whether or not the services are running properly.
Check if PostgreSQL is running:
pgrep -fl postgres
service postgresql status
(If status is available in your Linux then you should see something like this):
mortiz#florida:~/.mozilla/firefox/hlmpduzp.default$ sudo service postgresql status
● postgresql.service - PostgreSQL RDBMS
Loaded: loaded (/lib/systemd/system/postgresql.service; enabled; vendor preset: enabled)
Active: active (exited) since Mon 2018-06-11 14:05:04 -03; 3s ago
Process: 17522 ExecStart=/bin/true (code=exited, status=0/SUCCESS)
Main PID: 17522 (code=exited, status=0/SUCCESS)
Jun 11 14:05:04 florida systemd[1]: Starting PostgreSQL RDBMS...
Jun 11 14:05:04 florida systemd[1]: Started PostgreSQL RDBMS.
If the service is running, check the basic connectivity to the port:
telnet 127.0.0.1 5432
If you aren't able to connect try with localhost or the ip address (not the loopback):
telnet localhost 5432
telnet <your_ip_address> 5432
If the service isn't running try restoring a postgresql.conf backup.
If the service is running but you aren't able to connect to the port,
it could be a configuration problem, try restoring the configuration
from a backup.
If you were able to connect to the port using telnet, then the service is up and the port is open, anyway there could be configuration problems with the instance or your client.
If telnet didn't work with 127.0.0.1 but it did with localhost or -(your_ip_address / not loopback) then change that in your client settings.
If the service is running, check the basic connectivity to the port:
telnet 127.0.0.1 5432
If you aren't able to connect try with localhost or the ip address (not the loopback):
telnet localhost 5432
telnet <your_ip_address> 5432
If the service isn't running try restoring a postgresql.conf backup.
If the service is running but you aren't able to connect to the port,
it could be a configuration problem, try restoring the configuration
from a backup.
If you were able to connect to the port using telnet, then the service is up and the port is open, anyway there could be configuration problems with the instance or your client.
If the telnet didn't work with 127.0.0.1 but it did with localhost or then change that in your client settings.
Testing functionality
To check the expected behavior of the service. In Linux some services start even with errors and produce undesired behaviors.
Now it's time to see if the service is working properly, we'll use the CLI. Run this command:
psql -h localhost --username=postgres --list
And you should see the list of databases:
mortiz#florida:~/.mozilla/firefox/hlmpduzp.default$ psql -h localhost --username=postgres --list
Password for user postgres:
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+----------+-------------+-------------+-----------------------
postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
template0 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
(3 rows)
If this works then your problem may be in the client pgAdmin. Try installing another client or version and try connecting to the database.
Reviewing the configuration of the server
* Maybe someone changed the method of accessing the database.
Be careful, backup your file first. Check the PostgreSQL Client Authentication Configuration File hosts allowed to connect / methods and users -> /etc/postgresql/9.6/main/pg_hba.conf
# This file controls: which hosts are allowed to connect, how clients
# are authenticated, which PostgreSQL user names they can use, which
# databases they can access. Records take one of these forms:
#
# local DATABASE USER METHOD [OPTIONS]
# host DATABASE USER ADDRESS METHOD [OPTIONS]
# hostssl DATABASE USER ADDRESS METHOD [OPTIONS]
# hostnossl DATABASE USER ADDRESS METHOD [OPTIONS]
# METHOD can be "trust", "reject", "md5", "password", "gss", "sspi",
# "ident", "peer", "pam", "ldap", "radius" or "cert". Note that
# "password" sends passwords in clear text; "md5" is preferred since
# it sends encrypted passwords.
Tell me your results of each test if any problem.

Related

Manage PostgreSQL database remotely with Navicat

I installed PostgreSQL on my server today and quickly took notes. I hope that I have compiled the answers I found for my question beautifully for you.
UPDATE PG_HBA.CONF
If you are using an ubuntu distribution, the file path should be this way.
I use the 10 version and use the ubuntu distribution. This path may differ depending on your operating system. Find this file on your system. etc/postgressql/10/main/pg_hba.conf Using nano, you can open it directly with the command.
nano etc/postgresql/10/main/pg_hba.conf
here are two settings we need to make.
# "local" is for Unix domain socket connections only
local all all md5
# Remote connections for navicat
host samerole all 0.0.0.0/0 md5
don't touch the others, should look like this in its final form.
# Database administrative login by Unix domain socket
local all postgres peer
# 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 all peer
host replication all 127.0.0.1/32 md5
host replication all ::1/128 md5
# Remote connections for navicat
host samerole all 0.0.0.0/0 md5
UPDATE POSTGRESQL.CONF
Open this file with nano, find the line below and update it as follows.
nano etc/postgresql/10/main/postgresql.conf
listen_addresses = 'localhost'
change it
listen_adresses = '*'
The settings required for the translate remote connection to work are only related to these two settings. But if your system has a Firewall, we need to whitelist the ports for PostgreSQL like UFW. Let's do this when we say it.
$ sudo ufw status
When you check the firewall status, if it is active, you will see an output like this. If disabled, inactive appears.
To Action From
-- ------ ----
22/tcp ALLOW Anywhere
5432/tcp ALLOW Anywhere
22/tcp (v6) ALLOW Anywhere (v6)
5432/tcp (v6) ALLOW Anywhere (v6)
This place is very important! Make sure you have ssh permission when activating UFW. I will always let this habit. If you do not do this, you need to login to the system with root and interfere with ufw settings. you kind of lock yourself up :)
Let's continue with UFW permissions.
$ sudo ufw allow ssh
$ sudo ufw allow 5432/tcp
We also gave the necessary permissions. Let's do one more check. Let's make sure our PostgreSQL password is default postgres. Because it's a nonsense by the way. Let's secure our business. Time is cash.
CHECKING THE DEFAULT USERNAME AND PASSWORD (postgres, postgres, postgres)
$ sudo -u postgres psql
\password postgres
\q
just restart the postgres service.
$ sudo service postgresql restart
NOW WE START THE NAVICAT SETTINGS
Open your Navicat application and create a new connection that selects the PostreSQL connection from the new connection tab.
Two setting steps are waiting for you in the connection you created. General and SSH settings.
I enter my default PostgreSQL information in General settings. Just like in the picture.
Connection Name: Your Connection Name
Host: localhost
Port: 5432
Initial Database: postgres
User Name: postgres
Password: postgres
postgres is default database, username and password !
Let's set the SSH connection settings as follows.
Host: your droplet IP
Port: 22 is defeault SSH port
User Name: root (default root login)
Authentication Method: Public Key
Private Key: /Users/username/.ssh/id_rsa
Passphrase: your passhrase
If we have made our settings for Navicat, we can now test our connection. Click the Test Connection button and see if we connect.
Congratulations !!!

Cannot connect to PostgreSQL from client - Error timed out

After many days I am trying to connect to my PostgreSQL instance, I decided time has come to ask for help.
I am trying to connect to my PostgreSQL db from a Windows machine.
I am trying pgAdmin 4 and dBeaver but both fail to connect. Below is the screenshot of the error I receive when connecting using dBeaver.
The connection I am creating is like so:
My users are (\du):
List of roles
Role name | Attributes | Member of
-----------+------------------------------------------------------------+-----------
postgres | Superuser, Create role, Create DB, Replication, Bypass RLS | {}
umberto | Superuser, Create role, Create DB | {}
My databases (\l):
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+----------+---------+---------+-----------------------
postgres | postgres | UTF8 | C.UTF-8 | C.UTF-8 |
template0 | postgres | UTF8 | C.UTF-8 | C.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | C.UTF-8 | C.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
umberto | umberto | UTF8 | C.UTF-8 | C.UTF-8 |
wondermap | postgres | UTF8 | C.UTF-8 | C.UTF-8 |
Don't know exactly where to search for logs to dig into this problems on the server machine. The only thing I could find was the folder /var/log/postgresql where I see only two non gzipped files but the messages are referring to days previous to my attempts to connect.
Finally, my pg_hba.conf:
# Database administrative login by Unix domain socket
local all postgres peer
# 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 md5
host all all 0.0.0.0/0 md5
# IPv6 local connections:
host all all ::1/128 md5
host all all ::0/0 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 ::/0 md5
What could be the problem?
I wouldn't generally look at postgres logs for troubleshooting a connection timeout error, because if postgres is rejecting the connections, they'll get rejected right away rather than giving you a timeout, so if you're getting a timeout it typically means it never reached postgres, so there will be nothing relevant in the logs.
In my experience, a connection timeout error is typically due to a windows/networking issue, for example a firewall on (or in front of) the server doesn't allow access on port 5432, or nothing is actually listening on port 5432 (could be that postgres isn't actually running, or it's configured to listen on a different port, etc).
My favourite tool for troubleshooting these sorts of connectivity issues on Windows is portqry. Usage is portqry -n [hostname] -e [port number]. It will try to connect to [hostname] on port [port number] and give you the results:
Listening: portqry was able to connect to the host on the specified port, and an application was listening on that port. This is what you want.
Not listening: portqry was able to reach the host on the specified port, but nothing was listening on that port. In the case of postgres, this may be because the service isn't running, or is listening on a different port.
Filtered: portqry was unable to reach the host on the specified port. This means it was actually blocked from connecting, and this is generally caused by a firewall on the host or in between the client and host, which is preventing access to the host on that port.
In my case, I was trying to load a database from AWS RDS. After whitelisting my IP address, the error was resolved.
If you are hosting your pgadmin on the same server as your postgres database, try inserting "localhost" into the server / host connection field during the setup of your pgadmin connection to that database, also try "127.0.0.1". After ruling out all network issues this was what worked for me oddly enough.
I got this exact error. The issue was resolved after public accessibility was granted to the AWS database. It can be checked in the AWS console.
Just to add another solution here. Before this I want to clarify that I'm using Rocky Linux with Xfce for the host and Windows 10 for the client. So I was having this same issue and what I did was:
On the host, go to Network (taskbar) > right click > Edit connections
Double click on the connection your machine is in.
On the "General" tab, check the Firewall zone, and then change it to "trusted" then Save.
Now that solved my problem, hope it helps someone.

How to connect to windows postgres Database from WSL

I'm running Postgres 11 service on my Windows computer.
How can I connect to this database from WSL?
When I try su - postgres:
postgres#LAPTOP-NQ52TKOG:~$ psql
psql: 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"
It's trying to connect to a Postgres in WSL. I don't want to run Ubuntu Postgres using:
sudo /etc/init.d/postgresql start
WSL2 assigns IP address to the Windows host dynamically and the IP addresses can change without even rebooting Windows (see Notes below). So to reliably connect we'll need to:
Allow Windows and Postgres to accept connections from the WSL2 IP address range (not allowed by default)
From WSL2, determine the Windows/Postgresql host's IP address (which is dynamic) when connecting via psql. We'll make this convenient via .bashrc and alias.
Unfortunately I couldn't find the exact specification for the WSL2 IP address range. From several tests/reboots it appears that WSL2 is assigning IP addresses primarily in range of 172.*.*.* but I have occasionally been assigned 192.*.*.* so we'll use these when configuring the firewall and Postgres.
Add Windows Firewall Inbound Port Rule for WSL2 IP Addresses:
Open Windows Defender Firewall with Advanced Security
Click New Rule...
Select Port for rule type
Select TCP and for Specific local ports enter 5432
Select Allow the connection. Connecting from WSL2 won't be secure so don't select the secure option
Select at least Public. Can select Domain and Private as well. I could only connect if Public was selected
Name the rule e.g. Postgres - connect from WSL2 and create it
Right click newly created rule and select Properties then click on the Scope tab
Under Remote IP address, select These IP addresses then click Add... and enter range 172.0.0.1 to 172.254.254.254
Repeat step 9 for IP address range 192.0.0.1 to 192.254.254.254
Click Apply then OK
Make sure rule is enabled
Configure Postgres to Accept Connections from WSL2 IP Addresses
Assuming a default install/setup of Postgresql for Windows the following files are located under C:\Program Files\PostgresSQL\$VERSION\data
Verify that postgresql.conf has following set:
listen_addresses = '*'
This should already be set to '*' so nothing do here.
Update pg_hba.conf to allow connections from WSL2 range e.g. for Postgresl 12:
# TYPE DATABASE USER ADDRESS METHOD
# IPv4 local connections:
host all all 127.0.0.1/32 md5
host all all 172.0.0.0/8 md5
host all all 192.0.0.0/8 md5
For Postgresql 13+ you should use scram-sha-256 as the method.
Restart Postgres for changes to take effect. This can be done either from the Windows Services app or from cmd with Administrator privileges e.g. for Postgresql 12:
net stop postgresql-x64-12
net start postgresql-x64-12
WSL Shell Conveniences
In WSL, add following to your ~/.bashrc or similar:
# Add DNS entry for Windows host
if ! $(cat /etc/hosts | grep -q 'winhost'); then
echo 'Adding DNS entry for Windows host in /etc/hosts'
echo '\n# Windows host - added via ~/.bashhrc' | sudo tee -a /etc/hosts
echo -e "$(grep nameserver /etc/resolv.conf | awk '{print $2, " winhost"}')" | sudo tee -a /etc/hosts
fi
Then reload your .bashrc changes: source ~/.bashrc
Usage
psql -h winhost -p 5432 -U postgres
Notes:
The IP address assigned to the Windows host by WSL2 is not the same as the IP address assigned to your physical Windows machine on your network. WSL2 uses vEthernet connections.
You can inspect the vEthernet connections via Control Panel\Network and Internet\Network Connections
Note that when looking at the IPv4 properties that the IP addresses will appear as if they are statically set but they aren't! Try rebooting and inspecting IPv4 properties again
If one day you're unable to connect to Postgres, check that winhost is in the IP address range per firewall rules. Could be WSL has assigned an IP address that we weren't expecting!
In WSL2 you need to use host IP to connect
to get host IP
grep nameserver /etc/resolv.conf | awk '{print $2}'
then you need to allow TCP 5432 inbound Rules in 'Windows Defender Firewall with Advanced Security'
I made my self PS.you still need to allow TCP 5432 in Firewall
put this in ~/.bashrc
cat /etc/hosts | grep 172.; test $? -eq 0 && $1 || echo -e "$(grep nameserver /etc/resolv.conf | awk '{print $2, " host"}')\n$(cat /etc/hosts)" | sudo tee /etc/hosts
its append host IP to /etc/hosts if not exist before(usually happened when restart wsl or computer)
then
psql -h host -p 5432 -U postgres
Specify your host, port, and username explicitly
For example:
psql -h 127.0.0.1 -p 5432 -U postgres
For me what worked was to follow these steps:
Change pg_hba.conf to listen on all interfaces: host all all 0.0.0.0/0 trust
Open firewall for postgresql
Use one of the hostnames in /etc/hosts that pointed to the ip of my host. This hostname for me was: host.docker.internal
This issue can be fixed in two possible ways
Specify the host and user name explicitly
psql -h localhost -U postgres
Or
Navigate to the runpsql.sh file and run the query
/Library/PostgreSQL/14/scripts/runpsql.sh
Now run the psql query by entering password (if needed)

Postgres remote connection - Windows server

I have the following lines in pg_hba.conf. Postgres is installed on a Windows server.
# TYPE DATABASE USER ADDRESS METHOD
# IPv4 local connections:
host all all 127.0.0.1/32 md5
#host all all myip md5
# IPv6 local connections:
host all all ::1/128 md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
host replication all 127.0.0.1/32 md5
host replication all ::1/128 md5
I would like to allow connection only from one more public IP address. How can I achieve that? As soon as I enable the above line IP: Postgres doesn't start.
Looking for some guidance.
To open the port 5432 edit your /Program Files/PostgreSQL/10/data/postgresql.conf and change
# Connection Settings -
listen_addresses = '*' # what IP address(es) to listen on;
In /Program Files/PostgreSQL/10/data/pg_hba.conf
# IPv4 local connections:
host all all 0.0.0.0/0 md5
Now restate the Postgres server use cmd
pg_ctl -D "C:\Program Files\PostgreSQL\10\data" restart
I run postgres on several Windows servers (Windows Server 2012 R2, Windows Server 2016) as a part of a commercial framework running on an Apache tomcat webserver. The local connection worked fine. However, I want the same postgres server to be accessible for another framework (Cakephp) on another server (Red Hat Enterprise Linux) on the same server farm. This used to work until I upgraded to postgres 9. Now I had to upgrade to postgres 10. No matter what I tried, I failed.
Here is what I did to solve the problem:
Find your local postgres configuration files. They are usually in the same directory as the postgres tablespace, in my case:
d:\PG10Data\postgresql.conf.
This file has to contain the following lines:
# - Connection Settings:
listen_addresses = '*' # what IP addresses/interfaces to listen on
port = 5432
The next file to be modified is the pg_hba.conf (hba = host based access):
# TYPE DATABASE USER ADDRESS METHOD
# some sample entries:
# this will open UP ALL REMOTE IPv4 connections, do not open up permanently
host all all 0.0.0.0/0 md5
# only 1 database for 1 user from 1 IPv4 address:
host yourdatabasename yourusername 10.15.17.13/32 md5
# don not forget the "/32", otherwise the postgres server will not start up!
After editing these files, restart the postgres server.
You can run
netstat -a -n | findstr 5432
to see if the postgres listener is running.
You can also run the following to test connectivity from the Windows command prompt:
psql -Uyourusername -dyourdatabasename -p5432 -hlocalhost
This should work at any time. The next level will be to use your computer's local IPv4 address. This you can find out with
ipconfig
This will tell you your local IPv4 address. Use this in the following command:
psql -Uyourusername -dyourdatabasename -p5432 -hyourlocalip
My problem was, this command failed. Since I ran it directly on my server, it could not be the local Windows firewall.
The solution:
There is a 2nd configuration file:
d:\PG10Data\postgresql.auto.conf
The file starts ominously with the following 2 lines:
# Do not edit this file manually!
# It will be overwritten by the ALTER SYSTEM command
And it ends:
listen_addresses = 'localhost'
I tried the ALTER SYSTEM command when I was logged on locally as postgres via psql, but no success.
In the end I turned cheeky and changed the entry in d:\PG10Data\postgresql.auto.conf to;
listen_addresses = '*'
Bingo! After a postgres restart, remote access worked like a charm on both Windows servers.
N. B. Don't forget the Windows Firewall: Open port 5432 for remote access. Also check there are no firewalls in the network the block access to port 5432 from your remote client.
It would be nice if someone were able to tell me how I should have changed the parameter without editing the postgresql.auto.conf, but at least both of my framesworks - both on the local and the remote server - are working.
That is incorrect syntax: myip is not an IP address, and the /32 after it is missing.

Cannot connect to tryton (postgresql) via internet

I have a working local installation of tryton. But connecting from a remote client doesn't work.
tryton is build opon Postgre SQL, from documentation I assume the nature of the problem lies there.
Edit:
It turned out the problem was neither PostgreSQL nor the trytond.conf script alone, but rather that I needed to add an endpoint in the setup of the Virtual Machine on Windows Azure for Port 8000.
See http://xmodulo.com/2012/12/how-to-open-ports-on-windows-azure-vm.html.
However, the answer below regarding the trytond.conf file is correct as well.
In /etc/trytond.conf I've entered the IP address of the tryton server:
#This file is part of Tryton. The COPYRIGHT file at the top level of
#this repository contains the full copyright notices and license terms.
[options]
# This is the hostname used when generating tryton URI
#hostname =
# Activate the json-rpc protocol
jsonrpc = 23.97.165.118:8000
#ssl_jsonrpc = False
(This is an example IP)
Running the checks from the FAQ:
trytond is running correctly:
Listening ports:
However, no connect from the client via internet.
I'd like every client from anywhere on the internet to be able to connect (not best for security, but user's IPs change, so no way to avoid this).
What do I have to enter into /etc/postgresql/9.1/main/pg_hba.conf?
And what needs to go into postgresql.conf?
And in which one? Searching with "whereis postgresql.conf" finds several versions:
root#Tryton:~# whereis postgresql.conf
postgresql: /etc/postgresql /usr/lib/postgresql /usr/share/postgresql
Thank you very much for your help in advance.
Edit: Here are the configuration files. Runs ok locally on server, but cannot connect tryton client via internet.
Config Files (changes)
trytond.conf
#This file is part of Tryton. The COPYRIGHT file at the top level of
#this repository contains the full copyright notices and license terms.
[options]
# This is the hostname used when generating tryton URI
#hostname =
# Activate the json-rpc protocol
jsonrpc = *:8000
#ssl_jsonrpc = False
# Configure the path of json-rpc data
#jsondata_path = /var/www/localhost/tryton
# Activate the xml-rpc protocol
#xmlrpc = *:8069
#ssl_xmlrpc = False
# Activate the webdav protocol
#webdav = *:8080
#ssl_webdav = False
# Configure the database type
# allowed values are postgresql, sqlite, mysql
#db_type = postgresql
# Configure the database connection
## Note: Only databases owned by db_user will be displayed in the connection dialog
## of the Tryton client. db_user must have create permission for new databases
## to be able to use automatic database creation with the Tryton client.
#db_host = False
#db_port = False
db_user = tryton
db_password = tryton_password
#db_minconn = 1
#db_maxconn = 64
# Configure the postgresql path for the executable
#pg_path = None
# Configure the Tryton server password
#admin_passwd = admin
pg_hba.conf
# PostgreSQL Client Authentication Configuration File
# ===================================================
# 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 md5
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all peer
# IPv4 local connections:
# Original:
#host all all 127.0.0.1/32 md5
# Neu:
# Option 1: host all all 0.0.0.0/0 md5
host all all 127.0.0.1/32 md5
# IPv6 local connections:
# Original:
#host all all ::1/128 md5
# Neu:
host all all ::/0 md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
#local replication postgres peer
#host replication postgres 127.0.0.1/32 md5
#host replication postgres ::1/128 md5
postgresql.conf
# -----------------------------
# PostgreSQL configuration file
# -----------------------------
#
#------------------------------------------------------------------------------
# CONNECTIONS AND AUTHENTICATION
#------------------------------------------------------------------------------
# - Connection Settings -
listen_addresses = '*' # what IP address(es) to listen on;
# comma-separated list of addresses;
# defaults to 'localhost', '*' = all
# (change requires restart)
port = 5432 # (change requires restart)
max_connections = 100 # (change requires restart)
There is no issue related to postgresql as the postgresql connection is done from the server, so the problem is the config file, and exactly the jsonrpc option.
Basically this setting is for saying on which local interface/ip will tryton listen for conections:
So if you use:
jsonrpc = 23.97.165.118:8000
The server will listen on 23.97.165.118 and will only accept connections with destination 23.97.165.118, so you won't be able to access it throw localhost as localhost maps to 127.0.0.1
Having said that I will recomend using the following setting:
jsonrpc = *:8000
Which will listen to all the interfaces of the server (localhost and any external connections that you have).
Note: You must restart your tryton server in order to apply the changes in the configuration file.
I had the same issue, and advice in the accepted answer was actually the cause of my troubles. The correct syntax (at least for recent versions, 3.4 to 3.8) is the following :
[jsonrpc]
listen = *:8000