Logstash(docker) unable to connect database.
Error => Unable to connect to database. Tried 1 times {:message=>Java::OrgPostgresqlUtil::PSQLException: Connection to localhost:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections., :exception=>Sequel::DatabaseConnectionError
logstash.conf file:
input{
jdbc {
jdbc_driver_library => '/usr/share/logstash/logstash-core/lib/jars/postgresql-42.5.0.jar'
jdbc_driver_class => "org.postgresql.Driver"
jdbc_connection_string => "jdbc:postgresql://localhost:2022/testdb"
jdbc_user => "postgres"
jdbc_password => "12345"
statement => "SELECT * FROM users"
schedule => "* * * * *"
}
}
output {
elasticsearch {
hosts => "elasticsearch:9200"
index => "%{indexName}"
}
}
logstash.yml file:
http.host: "0.0.0.0"
path.config: /usr/share/logstash/pipeline
xpack.monitoring.elasticsearch.hosts: ["localhost:9200"]
xpack.monitoring.enabled: true
How can i connect to database?
I fixed this problem as follows =>
1-)My postgreSQL port is "2022" so i changed IPV4 port=127.0.0.1/22 in pg_hba.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/22 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 trust
host replication all 127.0.0.1/22 trust
host replication all ::1/128 trust
host all all all md5
2-) Use computer ip address(ipconfig) instead of localhost=
old= jdbc:postgresql://localhost:2022/testdb
new= jdbc:postgresql://192.168.1.83:2022/testdb
Related
I have a microservices architecture with 6 containers. One of them is the back (a server in python with asyncio) that is running in the address 0.0.0.0:1234 -> the host is '0.0.0.0' to be public.
And I have another microservice in Node JS, it is a socket connector, it has to connect with the back in python that is running in 0.0.0.0:1234, but I can't connect.
Error:
errno: -111,
code: 'ECONNREFUSED',
Why I can't connect the two containers between each other if it supposed to have a network in common?
I connect the others microservices between each other with the public domain that provides railway, but in this case I need the host and the port to connect it through sockets.
const connectToPythonServer = () => {
client.connect({
port: 1234,
host: '0.0.0.0'
}, () => {
// client.connect(1234, '0.0.0.0', () => {
console.log('Connected al back de python, es decir al sv asincronico');
client.write('Hello, server! Love, Client.');
});
}
This is how connect my Node JS connector to the back. It is working locally, but when I took this to railway, it doesn't work. It doesn't connect. **
I just began to learn about scala and want to find a way to connect to PostgreSQL with scalalikejdbc. I set up PostgreSQL on machine1 and want to connect to one from machine2.
This is my PostgreSQL configurations:
postgresql.conf
listen_addresses = '*' # what IP address(es) to listen on;
# comma-separated list of addresses;
# defaults to 'localhost'; use '*' for all
pg_hba.conf
# "local" is for Unix domain socket connections only
local all all md5
# IPv4 local connections:
host all all 127.0.0.1/32 ident
# 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 ident
host replication all ::1/128 ident
host all postgres 192.168.1.1/24 md5
This is my piece of code to connect to PostgreSQL that written by scala
def main(args: Array[String]): Unit = {
val jdbcDriver = "org.postgresql.Driver"
val jdbcUser = "postgres"
val jdbcPassword = "******"
val jdbcUrl = "jdbc:postgresql://192.168.50.1:5432/jdbc"
Class.forName(jdbcDriver)
ConnectionPool.singleton(jdbcUrl, jdbcUser, jdbcPassword)
val data = DB.readOnly { implicit session =>
sql"""SELECT * FROM Users""".
map { resultSet =>
resultSet.int(1) -> resultSet.int(2)
}
.list.apply().toMap
}
I get an error that "Connection to 192.168.50.1:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections."
Anyone can explain to me. Thanks a lot
I'm trying to move my bot to an Ubuntu virtual server from Vultr but it's having a problem connecting to the postgres database. I've tried editing the config from md5 to true, and host to local, etc. But those only give me different errors and also make it stop working on my original machine too. It's working perfectly fine on my Windows machine. Here is the error I'm facing:
asyncpg.exceptions.InvalidAuthorizationSpecificationError: no pg_hba.conf entry for host "[local]", user "postgres", database "xxx", SSL off
So I've tried to change this line:
async def create_db_pool():
bot.pg_con = await asyncpg.create_pool(database='xxx', user='postgres', password='???')
to this:
async def create_db_pool():
bot.pg_con = await asyncpg.create_pool(database='xxx', user='postgres', password='???', ssl=True)
and that gives me this error:
asyncpg.exceptions._base.InterfaceError: `ssl` parameter can only be enabled for TCP addresses, got a UNIX socket path: '/run/postgresql/.s.PGSQL.5432'
So I don't know what else to try. I've been stuck on this for a while. If it's relevant, it connects at the bottom of the bot.py file like this:
bot.loop.run_until_complete(create_db_pool())
Whether ssl is True or not, the database seems to still function on my Windows machine. But I can't get it to work on my Ubuntu virtual server.
If I edit my config to this:
# TYPE DATABASE USER ADDRESS METHOD
# IPv4 local connections:
host all all 0.0.0.0/0 md5
# IPv6 local connections:
host all all ::/0 md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
host replication all 0.0.0.0/0 md5
host replication all ::/0 md5
Then I get a call error like this:
OSError: Multiple exceptions: [Errno 111] Connect call failed ('::1', 5432, 0, 0), [Errno 111] Connect call failed ('127.0.0.1', 5432)
This is really driving me crazy. I have no idea what to do. I bought this virtual server to host my bot on but I can't even get it to connect to the database.
When I simply type psql in the terminal, I get this error:
Error: Invalid data directory for cluster 12 main
Postgres is not working as intended in basically any way. I'm using Vultr.com to host the Ubuntu server, if that matters. And connecting with PuTTy.
Your pg_hba.conf has multiple syntax errors. The "localhost" connection type is not allowed at all, and the "local" connection type does not accept an IP address field. The server would refuse to start/restart with the file you show, and if you try to reload a running server it will just keep using the previous settings.
LOG: invalid connection type "localhost"
CONTEXT: line 4 of configuration file "/home/jjanes/pgsql/data/pg_hba.conf"
LOG: invalid authentication method "127.0.0.1/32"
CONTEXT: line 5 of configuration file "/home/jjanes/pgsql/data/pg_hba.conf"
LOG: invalid authentication method "::1/128"
CONTEXT: line 9 of configuration file "/home/jjanes/pgsql/data/pg_hba.conf"
LOG: invalid connection type "localhost"
CONTEXT: line 10 of configuration file "/home/jjanes/pgsql/data/pg_hba.conf"
LOG: invalid authentication method "127.0.0.1/32"
CONTEXT: line 102 of configuration file "/home/jjanes/pgsql/data/pg_hba.conf"
FATAL: could not load pg_hba.conf
LOG: database system is shut down
I am using an application in Yii and Postgres database. When I run the application on live server(not local system) I am getting this error
CDbConnection failed to open the DB connection: SQLSTATE[08006] [7] could not connect to server: No buffer space available (0x00002747/10055) Is the server running on host "localhost" and accepting TCP/IP connections on port 5432?"
When I contact with server support team they told to close the db connection after each transaction. I would like to know how to close database connection after each transaction in yii with PostgreSQL?
This is my database connection code in main.php
'db'=>array( 'class'=>'CDbConnection', 'connectionString' => 'pgsql:host=localhost;port=5432;dbname=crescent_6', 'emulatePrepare' => true, 'username' => 'postgres', 'password' => 'root', 'charset' => 'utf8', ), 'cache' => array ( 'class' => 'system.caching.CDbCache', ),
I experiencing some problems with PostgreSQL that i need to install to run a SIlverpeas project.
Normally, the postgres part is correctly configured, because i've sent a command to make the user silverpeas owner of the database silverpeas, and i can connect by ssh using "pgsql -U silverpeas silverpeas"
Now, i'm trying to make my phpPgAdmin work. He is on the same server Centos 6.7 than Postgresql (in version 9.5).
When i'm trying to connect, i have a connection failed message, and sometimes, when i'm trying to troubleshoot the problem, i have the "trying to hack your system" message.
When i'm looking for the pgsql log file, after a connection trial, i have this message :
< 2016-03-16 11:32:39.378 CET >LOG: could not connect to Ident server at address "::1", port 113: Connection refused
< 2016-03-16 11:32:39.378 CET >FATAL: Ident authentication failed for user "silverpeas"
< 2016-03-16 11:32:39.378 CET >DETAIL: Connection matched pg_hba.conf line 84: "host all all ::1/128 ident"
The problem is, my /var/lib/pgsql/9.5/data/pg_hba.conf is like this :
# 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
host all all 10.1.1.0/8 md5
And if i looked for the /var/lib/pgsql/9.5/data/postgresql.conf file :
listen_addresses = 'localhost'
And my phpPgAdmin configuration is :
// use 'localhost' for TCP/IP connection on this computer
$conf['servers'][0]['host'] = 'localhost';
// Database port on server (5432 is the PostgreSQL default)
$conf['servers'][0]['port'] = 5432;
// Database SSL mode
// Possible options: disable, allow, prefer, require
// To require SSL on older servers use option: legacy
// To ignore the SSL mode, use option: unspecified
$conf['servers'][0]['sslmode'] = 'allow';
// Change the default database only if you cannot connect to template1.
// For a PostgreSQL 8.1+ server, you can set this to 'postgres'.
$conf['servers'][0]['defaultdb'] = 'silverpeas';
Suggestions ?
The pg_hba.conf file doesn't match the log file.
You use md5 method (good) but the log file talks about ident method.
Have you change and reload your postgresql conf before ?