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
Related
I am trying to connect to a remote PostgreSQL database by using this command using my local terminal (Windows PowerShell):
psql -h 112.176.20.102 -p 5432 -d bookstore -U postgres -W
But it returns an error message as shown below:
psql: error: connection to server at "112.176.20.102", port 5432 failed: server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.
SSL SYSCALL error: Connection reset by peer (0x00002746/10054)
connection to server at "112.176.20.102", port 5432 failed: expected authentication request from server, but received S
1. I have set up the pg_hba.conf configuration as shown below:
# 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 md5
# 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 0.0.0.0/0 md5
2. I also have set up postgresql.conf as shown below:
# -----------------------------
# 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'; 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
...
My question is what causes this problem and how to handle it so that I can connect to my remote PostgreSQL database?
I created an EC2 instance and then installed postgresql (version 11) and timescaledb in it. My security group looks as follows:
As of now, I have enabled this instance for all the IP addresses.
My /etc/postgresql/11/main/pg_hba.conf looks like this:
# 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
# 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 0.0.0.0/0 md5 #ipv4 range
host all all ::0/0 md5 #ipv6 range
host all all all md5 #all ip
and the /etc/postgresql/11/main/postgresql.conf looks like this:
# - 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)
Then, I try to connect to the database via Pgadmin4 using the Public DNS(IPv4):ec2-xx-xxx-xxx-xxx.eu-central-1.compute.amazonaws.com
After I enter the username and password, it throws the following error:
Unable to connect to server:
could not connect to server: Connection refused
Is the server running on host "ec2-xx-xxx-xxx-xxx.eu-central-1.compute.amazonaws.com" (xx.xxx.xxx.xxx) and accepting
TCP/IP connections on port 5432?
I had a look at the following post and followed all the instructions, but to no avail:
connect-to-remote-postgresql-server-on-amazon-ec2
Can anyone please help me out with this?
Edit 1
When I do:
/etc/init.d/postgresql restart
I get:
[....] Restarting postgresql (via systemctl): postgresql.service==== AUTHENTICATING FOR org.freedesktop.systemd1.manage-units ===
Authentication is required to restart 'postgresql.service'.
Authenticating as: Ubuntu (ubuntu)
Password:
I don't know what password to enter here so that the postgresql can get restarted
As pointed out by #jjanes in the comments, I had to restart the postgresql inorder to access it.
Doing
/etc/init.d/postgresql restart
was throwing an error (as shown in the question) that's why I had to use
sudo /etc/init.d/postgresql restart
in order to grant the root access.
Once the db was restarted, I tried connecting to the ec2 instance again via pgadmin4, and this time it worked.
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.
I'm using the scripts from here: https://wiki.postgresql.org/wiki/Automated_Backup_on_Linux
I have changed the owner of the files to "postgres" and I tried running the backup script while being logged in as "postgres"
my pg_hba.conf contains the following
local all postgres peer
and the "postgres" user has no password set to it. However when I run the backup script, the script asks for the "postgres" password.
Why is it asking for a password if I'm already logged in as postgres and pg_hba is set to peer authentication?
If I do set a password for it, then how would this run automatically every night since there is no way to put the password in the config file.
EDIT
my full pg_hba.conf
# PostgreSQL Client Authentication Configuration File
# ===================================================
#
# Refer to the "Client Authentication" section in the PostgreSQL
# documentation for a complete description of this file. A short
# synopsis follows.
#
# 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]
#
# (The uppercase items must be replaced by actual values.)
#
# The first field is the connection type: "local" is a Unix-domain
# socket, "host" is either a plain or SSL-encrypted TCP/IP socket,
# "hostssl" is an SSL-encrypted TCP/IP socket, and "hostnossl" is a
# plain TCP/IP socket.
#
# DATABASE can be "all", "sameuser", "samerole", "replication", a
# database name, or a comma-separated list thereof. The "all"
# keyword does not match "replication". Access to replication
# must be enabled in a separate record (see example below).
#
# USER can be "all", a user name, a group name prefixed with "+", or a
# comma-separated list thereof. In both the DATABASE and USER fields
# you can also write a file name prefixed with "#" to include names
# from a separate file.
#
# ADDRESS specifies the set of hosts the record matches. It can be a
# host name, or it is made up of an IP address and a CIDR mask that is
# an integer (between 0 and 32 (IPv4) or 128 (IPv6) inclusive) that
# specifies the number of significant bits in the mask. A host name
# that starts with a dot (.) matches a suffix of the actual host name.
# Alternatively, you can write an IP address and netmask in separate
# columns to specify the set of hosts. Instead of a CIDR-address, you
# can write "samehost" to match any of the server's own IP addresses,
# or "samenet" to match any address in any subnet that the server is
# directly connected to.
#
# 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.
#
# OPTIONS are a set of options for the authentication in the format
# NAME=VALUE. The available options depend on the different
# authentication methods -- refer to the "Client Authentication"
# section in the documentation for a list of which options are
# available for which authentication methods.
#
# Database and user names containing spaces, commas, quotes and other
# special characters must be quoted. Quoting one of the keywords
# "all", "sameuser", "samerole" or "replication" makes the name lose
# its special character, and just match a database or username with
# that name.
#
# This file is read on server startup and when the postmaster receives
# a SIGHUP signal. If you edit the file on a running system, you have
# to SIGHUP the postmaster for the changes to take effect. You can
# use "pg_ctl reload" to do that.
# Put your actual configuration here
# ----------------------------------
#
# 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.
# 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 peer
host all postgres 127.0.0.0/32 trust
# 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
# IPv6 local connections:
host all all ::1/128 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
host all all 0.0.0.0/0 md5
this part:
if [ ! $HOSTNAME ]; then
HOSTNAME="localhost"
fi;
sets connection to localhost, and https://www.postgresql.org/docs/current/static/auth-pg-hba-conf.html
local This record matches connection attempts using Unix-domain
sockets. Without a record of this type, Unix-domain socket connections
are disallowed.
so either configure
host all postgres localhost/32 trust
or set HOSTNAME=unix_socket_directories to hit the peer auth on
local all postgres peer
line
I have pasted below the snippets of Kettle DB Connection Configuration and of PgAdmin PostgreSQL Dashboard.
Please advice what I am doing wrong.
Localhost and Password are right.
Kettle configuration:
Snippet of PGADMIN dashboard
The error message is:
Error connecting to database [Postgre_Ady] :org.pentaho.di.core.exception.KettleDatabaseException: Error occurred while trying to connect to the database Error connecting to database: (using class org.postgresql.Driver) Connection refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections. org.pentaho.di.core.exception.KettleDatabaseException: Error occurred while trying to connect to the database
Below pasted is pg_hba.conf file
# PostgreSQL Client Authentication Configuration File
# ===================================================
#
# Refer to the "Client Authentication" section in the PostgreSQL
# documentation for a complete description of this file. A short
# synopsis follows.
#
# 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]
#
# (The uppercase items must be replaced by actual values.)
#
# The first field is the connection type: "local" is a Unix-domain
# socket, "host" is either a plain or SSL-encrypted TCP/IP socket,
# "hostssl" is an SSL-encrypted TCP/IP socket, and "hostnossl" is a
# plain TCP/IP socket.
#
# DATABASE can be "all", "sameuser", "samerole", "replication", a
# database name, or a comma-separated list thereof. The "all"
# keyword does not match "replication". Access to replication
# must be enabled in a separate record (see example below).
#
# USER can be "all", a user name, a group name prefixed with "+", or a
# comma-separated list thereof. In both the DATABASE and USER fields
# you can also write a file name prefixed with "#" to include names
# from a separate file.
#
# ADDRESS specifies the set of hosts the record matches. It can be a
# host name, or it is made up of an IP address and a CIDR mask that is
# an integer (between 0 and 32 (IPv4) or 128 (IPv6) inclusive) that
# specifies the number of significant bits in the mask. A host name
# that starts with a dot (.) matches a suffix of the actual host name.
# Alternatively, you can write an IP address and netmask in separate
# columns to specify the set of hosts. Instead of a CIDR-address, you
# can write "samehost" to match any of the server's own IP addresses,
# or "samenet" to match any address in any subnet that the server is
# directly connected to.
#
# 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.
#
# OPTIONS are a set of options for the authentication in the format
# NAME=VALUE. The available options depend on the different
# authentication methods -- refer to the "Client Authentication"
# section in the documentation for a list of which options are
# available for which authentication methods.
#
# Database and user names containing spaces, commas, quotes and other
# special characters must be quoted. Quoting one of the keywords
# "all", "sameuser", "samerole" or "replication" makes the name lose
# its special character, and just match a database or username with
# that name.
#
# This file is read on server startup and when the postmaster receives
# a SIGHUP signal. If you edit the file on a running system, you have
# to SIGHUP the postmaster for the changes to take effect. You can
# use "pg_ctl reload" to do that.
# Put your actual configuration here
# ----------------------------------
#
# 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.
# TYPE DATABASE USER ADDRESS METHOD
# 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.
#host replication postgres 127.0.0.1/32 md5
#host replication postgres ::1/128 md5
This how to get server IP and Port (If u use pgadmin4 means it is recent version of postgres and those functions already available)
select inet_server_addr(), inet_server_port()
According to screenshot, value "10892" is pid (process id) not a port number.
Default port number as mention #jipipayo is 5432
as user #a_horse_with_no_name pointed , the postgresql server listening port is wrong.
change the port number to 5432 on your kettle config, this is the default listening port on postgresql servers