Failed to connect to Postgres database Postgres requires connecting to a specific database, the following databases were tried: - hyperledger-fabric

I'm getting this error when i try to connect my fabric-ca to use postgres as a database.
Using postgres database, connecting to database...
2019/10/22 09:21:16 [DEBUG] Database Name: fabriccaserver
2019/10/22 09:21:16 [DEBUG] Connecting to PostgreSQL server, using connection string: host=127.0.0.1 port=5432 user=**** password=**** dbname=fabriccaserver sslmode=disable
2019/10/22 09:21:16 [WARNING] Failed to connect to database 'fabriccaserver'
2019/10/22 09:21:16 [DEBUG] Connecting to PostgreSQL server, using connection string: host=127.0.0.1 port=5432 user=**** password=**** dbname=postgres sslmode=disable
2019/10/22 09:21:16 [WARNING] Failed to connect to database 'postgres'
2019/10/22 09:21:16 [DEBUG] Connecting to PostgreSQL server, using connection string: host=127.0.0.1 port=5432 user=**** password=**** dbname=template1 sslmode=disable
2019/10/22 09:21:16 [WARNING] Failed to connect to database 'template1'
2019/10/22 09:21:16 [ERROR] Error occurred initializing database: Failed to connect to Postgres database. Postgres requires connecting to a specific database, the following databases were tried: [fabriccaserver postgres template1]. Please create one of these database before continuing

I solved this error by putting container_name in the host i,e.
db:
db:
type: postgres
datasource: host=db-postgres port=5432 user=postgres password=caDbPass12345 dbname=fabriccaserver sslmode=disable
tls:
enabled: false
certfiles:
client:
certfile:
keyfile:
Previously, i was entering localhost and also tried with 127.0.0.1 and after that i saw that in my docker-compose.yaml my postgres service was under different network and ica.org1.example.com was under different network which i fixed and also had to do docker network prune after killing and removing all the docker processes.

Related

Error starting vreplication engine: error in connecting to mysql db with connection <nil> Vitess on kubernetes

kubernetes version: v1.16.3
linux version: 7.3.1611
Starting Vitess cluster on kubernetes using default operator.yaml and 101_initial_cluster.yaml, one of example-vttablet-zone1-xxx pod is restarting forever.
using kubectl logs -f example-vttablet-zone1-2548885007-46a852d0 -c vttablet to see the logs, i got
W0706 07:42:02.200507 1 tm_init.go:531] Cannot get current mysql port, will keep retrying every 1s: net.Dial(/vt/socket/mysql.sock) to local server failed: dial unix /vt/socket/mysql.sock: connect: no such file or directory (errno 2002) (sqlstate HY000)
E0706 07:42:02.285406 1 engine.go:213] Error starting vreplication engine: error in connecting to mysql db with connection <nil>, err net.Dial(/vt/socket/mysql.sock) to local server failed: dial unix /vt/socket/mysql.sock: connect: no such file or directory (errno 2002) (sqlstate HY000), will keep retrying.
E0706 07:42:02.285504 1 state_manager.go:276] Error transitioning to the desired state: MASTER, Serving, will keep retrying: net.Dial(/vt/socket/mysql.sock) to local server failed: dial unix /vt/socket/mysql.sock: connect: no such file or directory (errno 2002) (sqlstate HY000)
I0706 07:42:02.285527 1 state_manager.go:661] State: exiting lameduck
E0706 07:42:02.285539 1 tm_state.go:258] Cannot start query service: net.Dial(/vt/socket/mysql.sock) to local server failed: dial unix /vt/socket/mysql.sock: connect: no such file or directory (errno 2002) (sqlstate HY000)
I0706 07:42:02.285553 1 tm_state.go:305] Publishing state: alias:<cell:"zone1" uid:2548885007 > hostname:"10.233.107.217" port_map:<key:"grpc" value:15999 > port_map:<key:"vt" value:15000 > keyspace:"commerce" shard:"-" key_range:<> type:MASTER db_name_override:"vt_commerce" mysql_hostname:"10.233.107.217" master_term_start_time:<seconds:1625527268 nanoseconds:196807555 >
I didn't change any yaml in operator directory, anyone know why is this?

DBeaver / PostgresSQL fails to connect to remote docker container

I'm trying to access a postgresql docker container through DBeaver, but I can't figure out how to make it work.
Running docker port db_1 returns:
5432/tcp -> 0.0.0.0:5432
So the port should be open to connections.
The postgresql.conf is set to
listen_addresses = '*'
Running docker inspect --format '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' db_1 returns
172.19.0.2
When trying to connect to the database to either localhost / 127.0.0.1 / 172.19.0.2 / db_1 the Dbeaver log returns this:
2019-03-18 17:22:03.000 - Connect with 'jdbc:postgresql://db_1:5432/test' (postgres-jdbc-169919c23d5-77ac021a71307fee)
....
2019-03-18 17:22:14.815 - SSH INFO: SSH_MSG_SERVICE_ACCEPT received
2019-03-18 17:22:14.824 - SSH INFO: Authentications that can continue: password,keyboard-interactive
2019-03-18 17:22:14.825 - SSH INFO: Next authentication method: password
2019-03-18 17:22:18.432 - SSH INFO: Authentication succeeded (password).
2019-03-18 17:22:18.458 - Connection failed (postgres-jdbc-169919c23d5-77ac021a71307fee)
2019-03-18 17:22:18.459 - SSH INFO: Disconnecting from domain.com port 22
2019-03-18 17:22:18.461 - SSH INFO: Caught an exception, leaving main loop due to Socket closed
2019-03-18 17:22:18.514 - org.jkiss.dbeaver.model.exec.DBCConnectException: The connection attempt failed.
org.jkiss.dbeaver.model.exec.DBCConnectException: The connection attempt failed.
at org.jkiss.dbeaver.model.impl.jdbc.JDBCDataSource.openConnection(JDBCDataSource.java:179)
at org.jkiss.dbeaver.ext.postgresql.model.PostgreDataSource.openConnection(PostgreDataSource.java:363)
at org.jkiss.dbeaver.ext.postgresql.model.PostgreDataSource.initializeRemoteInstance(PostgreDataSource.java:122)
at org.jkiss.dbeaver.model.impl.jdbc.JDBCDataSource.<init>(JDBCDataSource.java:100)
at org.jkiss.dbeaver.model.impl.jdbc.JDBCDataSource.<init>(JDBCDataSource.java:89)
at org.jkiss.dbeaver.ext.postgresql.model.PostgreDataSource.<init>(PostgreDataSource.java:80)
at org.jkiss.dbeaver.ext.postgresql.PostgreDataSourceProvider.openDataSource(PostgreDataSourceProvider.java:97)
at org.jkiss.dbeaver.registry.DataSourceDescriptor.connect(DataSourceDescriptor.java:770)
at org.jkiss.dbeaver.runtime.jobs.ConnectJob.run(ConnectJob.java:70)
at org.jkiss.dbeaver.ui.dialogs.connection.ConnectionWizard$ConnectionTester.run(ConnectionWizard.java:232)
at org.jkiss.dbeaver.model.runtime.AbstractJob.run(AbstractJob.java:101)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:63)
Caused by: org.postgresql.util.PSQLException: The connection attempt failed.
at org.postgresql.Driver$ConnectThread.getResult(Driver.java:405)
at org.postgresql.Driver.connect(Driver.java:263)
at org.jkiss.dbeaver.model.impl.jdbc.JDBCDataSource.lambda$0(JDBCDataSource.java:148)
at org.jkiss.dbeaver.model.impl.jdbc.JDBCDataSource.openConnection(JDBCDataSource.java:157)
... 11 more
Caused by: java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(SocketInputStream.java:210)
at java.net.SocketInputStream.read(SocketInputStream.java:141)
at org.postgresql.core.VisibleBufferedInputStream.readMore(VisibleBufferedInputStream.java:140)
at org.postgresql.core.VisibleBufferedInputStream.ensureBytes(VisibleBufferedInputStream.java:109)
at org.postgresql.core.VisibleBufferedInputStream.read(VisibleBufferedInputStream.java:67)
at org.postgresql.core.PGStream.receiveChar(PGStream.java:306)
at org.postgresql.core.v3.ConnectionFactoryImpl.enableSSL(ConnectionFactoryImpl.java:405)
at org.postgresql.core.v3.ConnectionFactoryImpl.tryConnect(ConnectionFactoryImpl.java:94)
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:192)
at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:49)
at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:195)
at org.postgresql.Driver.makeConnection(Driver.java:454)
at org.postgresql.Driver.access$100(Driver.java:57)
at org.postgresql.Driver$ConnectThread.run(Driver.java:364)
at java.lang.Thread.run(Thread.java:748)
Really clueless on how to make the connection work. The SSH tunnel obviously works, but the connection to the db fails. I have a spring boot application running in another container, and connecting that through the connection string jdbc:postgresql://db_1:5432/test works like a charm.
Any input on this? Could it be that 0.0.0.0 doesn't get mapped to the internal network somehow?
How are you exactly running your container, I suspect maybe you are missing to expose the ports? because I just tried running a postgres instance using the following command in PS:
docker run --name some-postgres -e POSTGRES_PASSWORD=mysecretpassword -d -p 5433:5432 postgres
Mapping the default postgres container port 5432 to my local 5433 port (because I have a postgres installation locally and didn't want to run into some kind of port-interferance problem) and later on created a database by accessing the docker and running some psql commands as described on this answer and then accesed the DB from DBeaver
and everything worked fine! Hope this helps.

Mongoose - remote database connect failed

I am trying to connect to my mongo database in my remote server:
$ mongo xxx.xxx.xxx.xx:27017
But I get this error:
MongoDB shell version: 2.6.10 connecting to: xxx.xxx.xxx.xx:27017/test
2016-11-07T05:18:39.140+0000 warning: Failed to connect to
xxx.xxx.xxx.xx:27017, reason: errno:111 Connection refused
2016-11-07T05:18:39.142+0000 Error: couldn't connect to server
xxx.xxx.xxx.xx:27017 (xxx.xxx.xxx.xx), connection attempt failed at
src/mongo/shell/mongo.js:148 exception: connect failed
Any ideas why?
I even have tried to connect it with an username and password but it still fails to connect...
Run this following command :
sudo service mongodb stop
sudo rm /var/lib/mongodb/mongod.lock
sudo service mongod restart
mongo

How to run mongodb again after executing db.shutdownServer(); in the admin db

I was just learning mongodb. I command I entered are :
use admin
db.shutdownServer();
This shutdown the database. After that whenever I'm writing mongo to start mongoDB it gives me :
MongoDB shell version: 3.0.12 connecting to: test
2016-10-09T18:24:27.661+0530 W NETWORK Failed to connect to
127.0.0.1:27017, reason: errno:111 Connection refused 2016-10-09T18:24:27.664+0530 E QUERY Error: couldn't connect to
server 127.0.0.1:27017 (127.0.0.1), connection attempt failed
at connect (src/mongo/shell/mongo.js:179:14)
at (connect):1:6 at src/mongo/shell/mongo.js:179 exception: connect failed
When I run this : sudo service mongodb start
I get :
Redirecting to /bin/systemctl start mongodb.service Failed to start
mongodb.service: Unit mongodb.service failed to load: No such file or
directory.
I tried other different commands (even I've re installed it again) but none of them restarted mongodb.
How to start mongodb?
shut down the node
:SECONDARY> db.shutdownServer()
up
:~$ mongod --config /db/mongod-repl-2.conf
:SECONDARY> rs.slaveOk()
:SECONDARY> show dbs
admin 0.000GB
config 0.000GB
local 0.000GB
testDatabase 0.000GB
You need to fork your service again,
Try
mongod --dbpath /var/lib/mongo/ --fork --logpath /var/log/mongodb/mongod.log

mongo db can't start ubuntu 15.10

sudo service mongodb start
Failed to start mongodb.service: Unit mongodb.service is masked.
What should I do? help me..
~$ mongo MongoDB shell version: 3.2.3 connecting to: test
2016-02-26T17:40:18.552+0200 W NETWORK [thread1] Failed to connect to
127.0.0.1:27017, reason: errno:111 Connection refused 2016-02-26T17:40:18.552+0200 E QUERY [thread1] Error: couldn't
connect to server 127.0.0.1:27017, connection attempt failed :
connect#src/mongo/shell/mongo.js:224:14 #(connect):1:6
exception: connect failed
I think it's sudo service mongod start - please note the lack of b in mongod
I find the solution;
sudo mongod --dbpath /var/lib/mongodb/ --journal
different terminal is opening and
mongo
command is starting with

Resources